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

天大地大妈咪最大 提交于 2019-12-09 22:34:21

问题


In Corda, I want to create several different versions of a responder flow, each to be used by a different node.

To do so, I understand that I need to define each responder flow in a separate CorDapp. However, they also all need to depend on the initiating flow class via the InitiatedBy annotation.

How can I structure the CorDapps containing the different implementations of the responder flow so that they all depend on this common initiating flow, without including all the responder flows in the same CorDapp where I defined the initiating flow?


回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/48624039/how-do-i-define-multiple-responder-flows-each-in-a-different-cordapp

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