0
votes

1.) I am making a project in Corda using the accounts library and I need to send a state to two accounts on different nodes in a single transaction. Is that possible in Corda and If yes then how? A flow code sample will be really helpful.

2.) How to create flow sessions for a list of parties in Corda flow or how to initiate flow for multiple participants?

3.) How to collect signatures from multiple parties in the flow?

2

2 Answers

1
votes

1 - Yes, you can. As described here you can use:

  • sendAll(payload: Any, sessions: Set<FlowSession>): it sends the payload object to all the provided FlowSession. It would be associated with receiveAll(receiveType: Class<R>, sessions: List<FlowSession>): List<UntrustworthyData<R>>
  • sendAllMap(payloadsPerSession: Map<FlowSession, Any>): it sends a potentially different payload to each FlowSession, as specified by the provided payloadsPerSession. It would be associated with receiveAllMap(sessions: Map<FlowSession, Class<out Any>>): Map<FlowSession, UntrustworthyData<Any>>

2 - Flows have to be created for each party:

FlowSession session1 = initiateFlow(counterparty1);
FlowSession session2 = initiateFlow(counterparty2);

but then you can pass all of them to the same

sendAll(payload, listOf(session1, session2))

3 - You have to use CollectSignaturesFlow(initiallySignedTx, listOf(sessions)), which receives in input a list of sessions. You can take a look to its implementation here and its unit tests here, or an example of usage here.

1
votes
  • In addition to Alessandro's reply, the Accounts library has a flow that is called ShareStateWithAccountFlow; which achieves your requirement.
  • Please make sure that you carefully read what the flow does and how to use it with accountQueryCriteria (see here).