Joel
Joel

Reputation: 23140

Can a Corda node initiate a flow session with itself?

In a Corda flow, you can initiate a FlowSession with a counterparty to send and receive data.

Can a node initiate a FlowSession with themselves?

Upvotes: 0

Views: 323

Answers (2)

Anton Germashev
Anton Germashev

Reputation: 21

Since Corda 4 this will throw an exception with message:

Do not provide flow sessions for the local node. FinalityFlow will record the notarised transaction locally.

Upvotes: 2

Joel
Joel

Reputation: 23140

Yes, this is completely fine. For example, the following would work:

@InitiatingFlow
@StartableByRPC
class Initiator : FlowLogic<Unit>() {
    override val progressTracker = ProgressTracker()

    @Suspendable
    override fun call() {
        val selfSession = initiateFlow(ourIdentity)
        selfSession.send("It's me!")
    }
}

@InitiatedBy(Initiator::class)
class Responder(val counterpartySession: FlowSession) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        logger.info(counterpartySession.receive<String>().unwrap { it })
    }
}

Upvotes: 2

Related Questions