Joel
Joel

Reputation: 23140

In Corda, how can a responder flow pass a message back to the initiator flow if they reject a transaction?

Suppose I have the following flow pair:

If the node running the Responder flow refuses to sign, how can he pass the reason for his refusal back to the node running the Initiator flow?

Upvotes: 1

Views: 226

Answers (1)

Joel
Joel

Reputation: 23140

The node running the Responder flow needs to throw a FlowException. A FlowException is a special exception type that should be thrown in flows when you want the exception's message to be visible to the counterparty.

So in Responder, you might write:

val signTransactionFlow = object : SignTransactionFlow(otherPartyFlow) {
    override fun checkTransaction(stx: SignedTransaction) {
        val counterparty = otherPartyFlow.counterparty
        throw FlowException("I refuse to trade with $counterparty")
    }
}

return subFlow(signTransactionFlow)

And in the Initiator, you could choose to handle the exception:

try {
    val fullySignedTx = subFlow(CollectSignaturesFlow(partSignedTx, setOf(otherPartyFlow), GATHERING_SIGS.childProgressTracker()))
} catch (e: FlowException) {
    logger.error(e.message)
    TODO("Handle error.")
}

Upvotes: 0

Related Questions