Joel
Joel

Reputation: 23140

In Corda, how to define an InitiatedBy flow without defining the Initiating flow?

I would like to create an InitiatedBy flow that is initiated by a flow class defined in another CorDapp. I do not have the source files of the other CorDapp, which is written and maintained by another company.

How can I write the IntiatedBy flow in my CorDapp such that it can be initiated by an initiating flow defined in a different CorDapp?

Upvotes: 1

Views: 235

Answers (1)

Joel
Joel

Reputation: 23140

In Corda 4, you can specify which responder flow to use via the node configuration. See https://docs.corda.net/head/flow-overriding.html#overriding-a-flow-via-node-configuration.

In Corda 3 and earlier, you need to create an abstract class that has the same fully-qualfiied name as the flow that will initiate your InitiatedBy flow:

@InitiatingFlow
@StartableByRPC
abstract class Initiator : FlowLogic<Unit>()

Then use this class in the InitiatedBy annotation of your flow:

@InitiatedBy(Initiator::class)
class Responder(val counterpartySession: FlowSession) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        // TODO: Flow response logic.
    }
}

The Responder flow will now respond to any initiating flows with the name Initiator, regardless of the actual class being run on the other side.

Upvotes: 1

Related Questions