首页 > 解决方案 > 如何在 Corda 的新状态创建流程中设置启动器?

问题描述

我正在使用 Corda 中的事件调度功能。我在一个州添加了相同的内容。现在我想在现有状态被接受时自动创建另一个状态。接受功能与一方有关,而触发创建另一个状态的动作必须与另一方本身有关。当我尝试这样做时,两个启动器都是相同的。创建新状态流时如何设置对方为发起者?

PS:我们正在遵循一个项目结构,该结构具有用于合同状态和流程的单独模块。

标签: corda

解决方案


实现这一目标的一种方法是:

  1. 定义一个流,而不是执行任何逻辑,而是简单地交给响应者流
  2. 定义执行逻辑的响应程序流

这是一个例子:

@InitiatingFlow
@SchedulableFlow
class InitiatorFlow(val counterparty: Party) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        // We send a flag message to the counterparty, causing them to start their responder flow.
        val session = initiateFlow(counterparty)
        session.send(true)
    }
}

@InitiatedBy(InitiatorFlow::class)
class InitiatedFlow(val counterpartySession: FlowSession) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        // We process and discard the flag message.
        counterpartySession.receive<Boolean>()

        // TODO: Create the new state based on the acceptance.
    }
}

推荐阅读