How do I define multiple responder flows, each in a different CorDapp?

扶醉桌前 提交于 2019-12-04 15:32:44

Well, the question comes that,

Why owner of CorDapp1 shares their business Flow logic to other? What if the business wants to keep flow implementation codebase private to them?

I think the following would be the project structure and implementation:

Ex. I have three parties PartyA, PartyB, PartyC and each has their own version of CorDapp's.

  1. cordapp-contract-states - this CorDapp contains shared contract, states, and abstract initiating flows will be used by counter-parties to implement their responder flow logic. This CorDapp shared with all required counterparties.

    @InitiatingFlow abstract class CreateTradeBaseFlow : FlowLogic {

    }

  2. cordapp-partyA - this CorDapp contains FlowLogic implementation for create trade.

    @StartableByRPC class CreateTradeFlow : CreateTradeBaseFlow { //Actual implementation of initiator flow goes here... }

  3. cordapp-partyB - this CorDapp contain responder flow for CreateTradeFlow and other business specific flowlogic implementation.

    @InitiatedBy(CreateTradeBaseFlow::class) class ResponderPartyB(private val otherSideSession: FlowSession) : FlowLogic<SignedTransaction>() { //implementation of responder flow goes here... }

  4. cordapp-partyC - this CorDapp contain responder flow for CreateTradeFlow and other business specific flowlogic implementation.

    @InitiatedBy(CreateTradeBaseFlow::class) class ResponderPartyC(private val otherSideSession: FlowSession) : FlowLogic<SignedTransaction>() { //implementation of responder flow goes here... }

What's your thought?

You need to define the CorDapp containing the initiating flow first, then set this CorDapp as a dependency for each CorDapp containing a responder flow. See https://docs.corda.net/cordapp-build-systems.html#dependencies-on-other-cordapps for details.

For example, suppose CorDapp 1 defines the following initiating flow:

@InitiatingFlow
@StartableByRPC
class Initiator : FlowLogic<Unit>() {
    ...
}

Then you have CorDapp 2A which defines the following responder flow:

@InitiatedBy(Initiator::class)
@StartableByRPC
class ResponderA : FlowLogic<Unit>() {
    ...
}

And CorDapp 2B which defines the following responder flow:

@InitiatedBy(Initiator::class)
@StartableByRPC
class ResponderB : FlowLogic<Unit>() {
    ...
}

CorDapp 2A and CorDapp 2B would then need a dependency in their build.gradle files making these CorDapps depend on CorDapp 1, where the initiating flow is defined.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!