如何从 corda 流中的多个状态参与者收集签名?

How to collect signatures from multiple state participants in a corda flow?

我正在处理一个涉及三方的用例,比方说 PartyA、PartyB 和 PartyC。

在这种情况下,

  1. PartyA发出一个dealState(A是唯一参与者),

  2. A方卖给B方(A、B为参与者),

  3. 现在PartyB想把这个状态卖给PartyC,但是我们需要A和B的签名,加上C接受出售过程的签名。

如何在第三种情况下从原始发行方甲方收集签名以使流程正常运行?

流程里的代码是这一个(我卖的是PartyB)

val newOwnerFlow = initiateFlow(PartyC)

progressTracker.currentStep = GATHERING_SIGS

println("Finished gathering signatures stage 9")

// Send the state to the counterparty, and receive it back with their signature.
val fullySignedTx = subFlow(CollectSignaturesFlow(partSignedTx, setOf(newOwnerFlow), GATHERING_SIGS.childProgressTracker()))

// Stage 10.
progressTracker.currentStep = FINALISING_TRANSACTION

println("Finalizing transaction")

// Notarise and record the transaction in both parties' vaults.

return subFlow(FinalityFlow(fullySignedTx, FINALISING_TRANSACTION.childProgressTracker()))

如何让甲方签署交易?

经过一些试验,我发现问题如下:

您必须创建一个 setOf(flowSessions) 将每个参与者映射到它必须传递给 CollectSignaturesFlow() 的对应的 initiateFlow(),语法如下所示:

 val participantsParties = dealState.participants.map { serviceHub.identityService.wellKnownPartyFromAnonymous(it)!! }

 val flowSessions = (participantsParties - myIdentity).map { initiateFlow(it) }.toSet()

 progressTracker.currentStep = GATHERING_SIGS

 println("Finished gathering signatures stage 9")

 // Send the state to the counterparty, and receive it back with their signature.

 val fullySignedTx = subFlow(CollectSignaturesFlow(partSignedTx, flowSessions, GATHERING_SIGS.childProgressTracker()))