【问题标题】:Corda: StateRef usage in a scheduled activityCorda:预定活动中的 StateRef 使用情况
【发布时间】:2018-11-06 01:09:47
【问题描述】:

在哪里提供构造函数输入作为错误消息状态?在安排活动时,我不确定 StateRef 的正确用法。我成功运行 Heartbeat CorDapp 以测试基本用法。

前进状态:

data class ForwardState(val initiator: Party, val acceptor: Party, val asset: String, val deliveryPrice: BigDecimal, val startDate: Instant, val settlementDate: Instant, val buySell: String) : SchedulableState {
    override val participants get() = listOf(initiator, acceptor)

    override fun nextScheduledActivity(thisStateRef: StateRef, flowLogicRefFactory: FlowLogicRefFactory): ScheduledActivity? {
        return ScheduledActivity(flowLogicRefFactory.create("com.template.ForwardSettleFlow"), settlementDate)
}

转发流:

@InitiatingFlow
@StartableByRPC
class ForwardFlow(val initiator: Party, val acceptor: Party, val asset: String, val deliveryPrice: BigDecimal,
              val startDate: Instant, val settlementDate: Instant, val buySell: String) : FlowLogic<Unit>() {

companion object {
    object GENERATING_TRANSACTION : ProgressTracker.Step("Generating transaction")
    object SIGNING_TRANSACTION : ProgressTracker.Step("Signing transaction with our private key")
    object FINALISING_TRANSACTION : ProgressTracker.Step("Recording transaction") {
        override fun childProgressTracker() = FinalityFlow.tracker()
    }

    fun tracker() = ProgressTracker(
            GENERATING_TRANSACTION,
            SIGNING_TRANSACTION,
            FINALISING_TRANSACTION
    )
}

override val progressTracker = tracker()

@Suspendable
override fun call() { 
    // Adapted from hello world pt 1/2
}
}

ForwardSettleFlow:

@InitiatingFlow
@SchedulableFlow
@StartableByRPC
class ForwardSettleFlow(val initiator: Party, val acceptor: Party, val asset: String, val deliveryPrice: BigDecimal,
                    val startDate: Instant, val settlementDate: Instant, val buySell: String,
                    val thisStateRef: StateRef) : FlowLogic<Unit>() {

// progress tracker redacted

@Suspendable
override fun call() {
    progressTracker.currentStep = GENERATING_TRANSACTION
    val input = serviceHub.toStateAndRef<ForwardState>(thisStateRef)
    val output = ForwardState(initiator, acceptor, asset, deliveryPrice, startDate, settlementDate, buySell)
    val beatCmd = Command(ForwardContract.Commands.Settle(), ourIdentity.owningKey)
    val txBuilder = TransactionBuilder(serviceHub.networkMapCache.notaryIdentities.first())
            .addInputState(input)
            .addOutputState(output, FORWARD_CONTRACT_ID)
            .addCommand(beatCmd)

    progressTracker.currentStep = SIGNING_TRANSACTION
    val signedTx = serviceHub.signInitialTransaction(txBuilder)

    progressTracker.currentStep = FINALISING_TRANSACTION
    subFlow(FinalityFlow(signedTx))
}
}
  1. ForwardFlow 发起并有一个Responder 供双方签署。
  2. 一旦通过ForwardSettleFlowResponder 达到结算日期,计划的活动设置就会响应。此流程在类构造函数中接受 thisStateRef。测试表明,忽略这一点对错误输出没有影响。这个过程有两个流程和两个各自的响应者。

A 方的崩溃外壳在ForwardFlow 期间的 FINALISING_TRANSACTION 时间附近冻结。

rx.exceptions.OnErrorNotImplementedException: A FlowLogicRef cannot be 
constructed for FlowLogic of type com.template.ForwardSettleFlow: due 
to missing constructor for arguments: [class 
net.corda.core.contracts.StateRef]

我相信这会阻止活动发生,包括在没有要求的测试期间合同为空白时。

【问题讨论】:

    标签: corda


    【解决方案1】:

    FlowLogicRefFactory.create() 具有以下构造函数:

    override fun create(flowClass: Class<out FlowLogic<*>>, vararg args: Any?): FlowLogicRef {
    

    当您在ForwardState.nextScheduledActivity() 中调用FlowLogicRefFactory.create() 时,您根本不传递任何参数:

    flowLogicRefFactory.create("com.template.ForwardSettleFlow")
    

    但是没有采用零参数的ForwardSettleFlow 构造函数:

    class ForwardSettleFlow(val initiator: Party, val acceptor: Party, val asset: String, 
        val deliveryPrice: BigDecimal, val startDate: Instant, val settlementDate: Instant, 
        val buySell: String, val thisStateRef: StateRef) : FlowLogic<Unit>() {
    

    因此你得到一个“缺少构造函数”异常。要么你需要更新 ForwardSettleFlow 以拥有一个零参数的构造函数,要么你需要将一些参数传递给 FlowLogicRefFactory.create()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 2012-09-06
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      • 2014-05-23
      相关资源
      最近更新 更多