在corda中实现可调度状态

在corda中实现可调度状态,corda,Corda,我们如何在corda中实现可调度状态?在我的情况下,我需要发布月度报表,那么schedulablestate可以用于此吗?您需要做很多事情 首先,状态对象需要实现SchedulableState接口。它添加了一个附加方法: interface SchedulableState : ContractState { /** * Indicate whether there is some activity to be performed at some future point i

我们如何在corda中实现可调度状态?在我的情况下,我需要发布月度报表,那么schedulablestate可以用于此吗?

您需要做很多事情

首先,状态对象需要实现
SchedulableState
接口。它添加了一个附加方法:

interface SchedulableState : ContractState {
    /**
     * Indicate whether there is some activity to be performed at some future point in time with respect to this
     * [ContractState], what that activity is and at what point in time it should be initiated.
     * This can be used to implement deadlines for payment or processing of financial instruments according to a schedule.
     *
     * The state has no reference to it's own StateRef, so supply that for use as input to any FlowLogic constructed.
     *
     * @return null if there is no activity to schedule.
     */
    fun nextScheduledActivity(thisStateRef: StateRef, flowLogicRefFactory: FlowLogicRefFactory): ScheduledActivity?
}
此接口需要实现名为
nextScheduledActivity
的方法,该方法返回可选的
ScheduledActivity
实例
ScheduledActivity
捕获每个节点将运行的
FlowLogic
实例,以执行该活动,其运行时间由
java.time.Instant
描述。一旦您的状态实现了此接口并被vault跟踪,则在提交到vault时,可能会查询到下一个活动。例如:

class ExampleState(val initiator: Party,
                   val requestTime: Instant,
                   val delay: Long) : SchedulableState {
     override val contract: Contract get() = DUMMY_PROGRAM_ID
     override val participants: List<AbstractParty> get() = listOf(initiator)
     override fun nextScheduledActivity(thisStateRef: StateRef, flowLogicRefFactory: FlowLogicRefFactory): ScheduledActivity? {
         val responseTime = requestTime.plusSeconds(delay)
         val flowRef = flowLogicRefFactory.create(FlowToStart::class.java)
         return ScheduledActivity(flowRef, responseTime)
     }
 }
现在,当
ExampleState
存储在vault中时,
FlowToStart
将被安排在
ExampleState
中指定的偏移时间开始


就这样

这是一个有趣的问题,我正在研究一个类似的用例,但我还不在实际实现中,然而,是的,schedulableState是您所需要的。在我的例子中,我需要基于父状态中的本金金额创建月度报表。因此,我的父状态将是schedulablestate,它每月安排一个流来创建月度报表(子状态)。我说得对吗?完全正确。您实现可调度状态,并将时间延迟一个月。然后,当计时器触发时,将执行发出语句的流。Cheersschedulable状态是2个节点之间的tx的一部分,此状态驻留在双方的节点中。在这种情况下,将在两个节点中触发调度程序流。但我希望它只在一个节点中触发。有可能吗?我们是否需要在正常实现中为网络启动处理程序添加逻辑,在正常实现中,必须在两侧执行相同的流逻辑?
@InitiatingFlow
@SchedulableFlow
class FlowToStart : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        // Do stuff.
    }
}