我們如何在corda中實現可調度狀態?在我的情況下,我需要發佈每月的聲明,所以可以使用schedulablestate來做到這一點?在corda中實現可調度狀態
1
A
回答
4
有很多事情你需要做。
首先,您的狀態對象需要實現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?
}
該接口需要被實現,它返回一個可選ScheduledActivity
實例名爲nextScheduledActivity
的方法。 ScheduledActivity
捕獲每個節點將運行的實例,執行該活動,以及何時將運行由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)
}
}
其次,這是schedulted開始(在這種情況下FlowToStart
)的FlowLogic
類也必須標註了@SchedulableFlow.
例如
@InitiatingFlow
@SchedulableFlow
class FlowToStart : FlowLogic<Unit>() {
@Suspendable
override fun call() {
// Do stuff.
}
}
現在,當ExampleState
存儲在庫中,FlowToStart
將schedulted在ExampleState
指定的偏移時間啓動。
就是這樣!
相關問題
- 1. 如何更新corda中的狀態
- 2. 動態調度實現
- 3. 狀態機實現
- 4. C++實現狀態
- 5. Corda:在單個事務中添加多個輸出狀態
- 6. 在VHDL狀態機中實現延遲
- 7. std :: put_time在GCC中的實現狀態?
- 8. 在MVC中實現多狀態模型
- 9. 在WPF中實現狀態機模式
- 10. 在Labview中實現分層狀態機
- 11. 如何在Erlang中實現狀態?
- 12. 當在linux中調用bg時應該實現什麼狀態
- 13. 是否可以在Android應用程序中實現Flex狀態
- 14. 在Java中實現無狀態對象的可能方法
- 15. 可可狀態欄中的進度微調器
- 16. 鎖實現基於狀態
- 17. 容錯MPI實現:狀態
- 18. POSIX實現的狀態
- 19. 實現訂閱狀態
- 20. 實現狀態模式
- 21. 有限狀態機實現
- 22. Quartz調度程序可以實現嗎?
- 23. EJB無狀態bean調度
- 24. 如何在加載時實現角度可編輯編輯狀態禁用
- 25. 如何在apache上實現角度推送狀態
- 26. 是否有可能在Corda網絡中實時註冊節點
- 27. 在Windows中實現調度程序類
- 28. 在免費RTos中實現調度器
- 29. 處理工廠實現中的狀態
- 30. Erlang中分層狀態機的實現
這是一個有趣的問題,我正在研究一個類似的用例,但我還沒有在實際的實施,但是,schedulableState是你需要的 –