问题
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.
cordapp-contract-states - this CorDapp contains shared
contract
,states
, andabstract initiating flows
will be used bycounter-parties
to implement theirresponder flow logic
. This CorDapp shared with all required counterparties.@InitiatingFlow abstract class CreateTradeBaseFlow : FlowLogic {
}
cordapp-partyA - this CorDapp contains
FlowLogic
implementation for create trade.@StartableByRPC class CreateTradeFlow : CreateTradeBaseFlow { //Actual implementation of initiator flow goes here... }
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... }
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