如何将状态发送到 corda 中的多个帐户?

How to send a state to multiple accounts in corda?

1.) 我正在使用帐户库在 Corda 中创建一个项目,我需要在单个事务中将状态发送到不同节点上的两个帐户。这在 Corda 中有可能吗?如果可以,那又如何呢?流代码示例将非常有用。

2.) 如何在 Corda 流程中为参与方列表创建流程会话或如何为多个参与者启动流程?

3.) 如何收集流程中的多方签名?

1 - 可以。如所述 here 您可以使用:

  • sendAll(payload: Any, sessions: Set<FlowSession>):它将有效负载对象发送到所有提供的 FlowSession。它将与 receiveAll(receiveType: Class<R>, sessions: List<FlowSession>): List<UntrustworthyData<R>>
  • 关联
  • sendAllMap(payloadsPerSession: Map<FlowSession, Any>):它向每个 FlowSession 发送可能不同的有效载荷,如提供的 payloadsPerSession 所指定。它将与 receiveAllMap(sessions: Map<FlowSession, Class<out Any>>): Map<FlowSession, UntrustworthyData<Any>>
  • 关联

2 - 必须为每一方创建流程:

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

但是你可以将它们全部传递给同一个

sendAll(payload, listOf(session1, session2))

3 - 您必须使用 CollectSignaturesFlow(initiallySignedTx, listOf(sessions)),它在输入中接收会话列表。你可以看看它的实现 here and its unit tests here, or an example of usage here.

  • 除了 Alessandro 的回复之外,Accounts 库还有一个名为 ShareStateWithAccountFlow 的流程;达到你的要求。
  • 请确保您仔细阅读了流程的作用以及如何将其与 accountQueryCriteria 一起使用(参见 here)。