首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Corda:在预定活动中使用StateRef

Corda:在预定活动中使用StateRef
EN

Stack Overflow用户
提问于 2018-11-03 20:00:03
回答 1查看 106关注 0票数 0

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

ForwardState:

代码语言:javascript
复制
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)
}

ForwardFlow:

代码语言:javascript
复制
@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:

代码语言:javascript
复制
@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到达ForwardSettleFlowResponder后响应。这个流在类构造函数中接受thisStateRef。测试表明,忽略这一点对错误输出没有任何影响。这一过程有两个流程和两个相应的响应程序。

甲方的空壳在FINALISING_TRANSACTION期间在ForwardFlow期间结冰。

代码语言:javascript
复制
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]

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-05 17:09:47

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

代码语言:javascript
复制
override fun create(flowClass: Class<out FlowLogic<*>>, vararg args: Any?): FlowLogicRef {

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

代码语言:javascript
复制
flowLogicRefFactory.create("com.template.ForwardSettleFlow")

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

代码语言:javascript
复制
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()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53135018

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档