【发布时间】:2020-04-03 21:16:59
【问题描述】:
我正在尝试在 Corda Flow 中添加 FlowException。
我在我的代码中添加了以下部分。这总是正确的。我只想显示消息“Trade id already available”
val a : Int = 10
val b : Int = 10
if (a == b){
throw FlowException("Trade id already available")
}
当我运行代码时,由于 Flows 由于异常而提前结束,它应该显示 Flow 异常错误。但它唯一要做的就是结束流程而不显示消息
我的完整代码是:
object ExampleFlow {
@InitiatingFlow
@StartableByRPC
class Initiator(val iouValue: Int,
val otherParty: Party) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
// Obtain a reference to the notary we want to use.
val notary = serviceHub.networkMapCache.notaryIdentities[0]
val a : Int = 10
val b : Int = 10
if (a == b){
throw FlowException("Trade id already available")
}
val iouState = IOUState(iouValue, serviceHub.myInfo.legalIdentities.first(), otherParty)
val txCommand = Command(IOUContract.Commands.Create(), iouState.participants.map { it.owningKey })
val txBuilder = TransactionBuilder(notary)
.addOutputState(iouState, IOUContract.ID)
.addCommand(txCommand)
txBuilder.verify(serviceHub)
val partSignedTx = serviceHub.signInitialTransaction(txBuilder)
val otherPartySession = initiateFlow(otherParty)
val fullySignedTx = subFlow(CollectSignaturesFlow(partSignedTx, setOf(otherPartySession), GATHERING_SIGS.childProgressTracker()))
return subFlow(FinalityFlow(fullySignedTx, setOf(otherPartySession), FINALISING_TRANSACTION.childProgressTracker()))
}
}
@InitiatedBy(Initiator::class)
class Acceptor(val otherPartySession: FlowSession) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val signTransactionFlow = object : SignTransactionFlow(otherPartySession) {
override fun checkTransaction(stx: SignedTransaction) = requireThat {
val output = stx.tx.outputs.single().data
"This must be an IOU transaction." using (output is IOUState)
val iou = output as IOUState
"I won't accept IOUs with a value over 100." using (iou.value <= 100)
}
}
val txId = subFlow(signTransactionFlow).id
return subFlow(ReceiveFinalityFlow(otherPartySession, expectedTxId = txId))
}
}
}
【问题讨论】:
标签: corda