【发布时间】: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))
}
}
-
ForwardFlow发起并有一个Responder供双方签署。 - 一旦通过
ForwardSettleFlow和Responder达到结算日期,计划的活动设置就会响应。此流程在类构造函数中接受 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