我一直在关注如何从here和here实现观察者节点的官方教程。我尝试测试流程以将事务广播到观察者节点,但是,我不确定我是否正确实现了流程。运行流后,观察者节点的保险库中没有出现任何状态。当我运行RPC保险库查询时,没有状态(对应于广播的事务)出现,当我访问观察者节点的H2数据库时也没有显示。调试显示调用了流代码。也没有例外。
流程是否正常工作?另外,我如何将广播的事务视为观察者节点 - 它是否作为消费状态存储在其保险库中?
流程代码:
object BroadcastTransaction {
@InitiatingFlow
class BroadcastTransactionToObservers(private val stx: SignedTransaction, private val observers: List<Party>) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val sessions = observers.map { initiateFlow(it) }
sessions.forEach { subFlow(SendTransactionFlow(it, stx)) }
}
}
@InitiatedBy(BroadcastTransactionToObservers::class)
class RecordTransactionAsObserver(private val otherSession: FlowSession) :FlowLogic<Unit>() {
@Suspendable
override fun call() {
subFlow( ReceiveTransactionFlow(
otherSideSession = otherSession,
checkSufficientSignatures = true,
statesToRecord = StatesToRecord.ALL_VISIBLE
)
)
}
}
}
我如何称呼流程:
subFlow(BroadcastTransaction.BroadcastTransactionToObservers(fullySignedTx, listOf(observer)))
先前启动流程:
@InitiatingFlow
@StartableByRPC
class Initiator (val id: String,
val transferParty : Party,
val observer : Party) : BaseFlow() {
@Suspendable
override fun call() : SignedTransaction {
progressTracker.currentStep = ID_OTHER_NODES
val notary = serviceHub.networkMapCache.notaryIdentities[0]
progressTracker.currentStep = EXTRACTING_VAULT_STATES
val stateAndRef = getItemStateByItemId(id)
val inputState = stateAndRef.state.data
progressTracker.currentStep = TX_BUILDING
val txBuilder = TransactionBuilder(notary = notary)
val outputState = createOutput(inputState)
val signerKeys = listOf(ourIdentity.owningKey, transferParty.owningKey)
val cmd = Command(outputState.command, signerKeys)
txBuilder.addInputState(stateAndRef)
.addOutputState(outputState.ownableState, CONTRACT_ID)
.addCommand(cmd)
progressTracker.currentStep = TX_VERIFICATION
txBuilder.verify(serviceHub)
progressTracker.currentStep = TX_SIGNING
val signedTx = serviceHub.signInitialTransaction(txBuilder)
progressTracker.currentStep = SENDING_AND_RECEIVING_DATA
val sessions = setOf(initiateFlow(transferParty))
progressTracker.currentStep = SIGS_GATHERING
val fullySignedTx: SignedTransaction = subFlow(CollectSignaturesFlow(signedTx, sessions, SIGS_GATHERING.childProgressTracker()))
subFlow(BroadcastTransaction.BroadcastTransactionToObservers(fullySignedTx, listOf(observer)))
progressTracker.currentStep = FINALISATION
return subFlow(FinalityFlow(fullySignedTx, setOf(ourIdentity),FINALISATION.childProgressTracker()))
}
答案 0 :(得分:0)
您正在向观察员广播该交易,然后才将其作为FinalityFlow
的一部分从公证人那里收到签名。节点不会在其保险库中记录交易的状态,除非它具有所有必需的签名,包括公证人。
尝试将呼叫转移到FinalityFlow
的呼叫之上的BroadcastTransaction.BroadcastTransactionToObservers
。