在Corda中,一个非';参与者是否在其vault中存储状态?

在Corda中,一个非';参与者是否在其vault中存储状态?,corda,Corda,在Corda中,节点仅存储其为参与者之一的状态(除非状态为OwnableState,在这种情况下,节点仅存储其为所有者的状态) 如何覆盖此行为并使节点存储其不是参与者的状态?节点可以选择记录其收到的事务中的每个状态,而不是选择仅记录其是参与者之一的状态。我在下面写了一个例子。您还可以查看实现此模式的可观察状态 发送交易 首先,拥有包含相关状态的交易的节点需要将交易发送给想要记录该交易但不是参与者的交易对手。下面是我们如何定义一个BrodcastTransactionFlow来实现这一点: @In

在Corda中,节点仅存储其为
参与者之一的状态(除非状态为
OwnableState
,在这种情况下,节点仅存储其为
所有者的状态)


如何覆盖此行为并使节点存储其不是参与者的状态?

节点可以选择记录其收到的事务中的每个状态,而不是选择仅记录其是
参与者之一的状态。我在下面写了一个例子。您还可以查看实现此模式的可观察状态

发送交易

首先,拥有包含相关状态的交易的节点需要将交易发送给想要记录该交易但不是
参与者的交易对手。下面是我们如何定义一个
BrodcastTransactionFlow
来实现这一点:

@InitiatingFlow
class BroadcastTransaction(
    val stx: SignedTransaction, 
    val counterparty: Party) : FlowLogic<Unit>() {

    @Suspendable
    override fun call() {
        val session = initiateFlow(counterparty)
        subFlow(SendTransactionFlow(session, stx))
    }
}
@InitiatedBy(BroadcastTransaction::class)
class RecordTransactionAsObserver(val otherSession: FlowSession) : FlowLogic<Unit>() {

    @Suspendable
    override fun call() {
        val flow = ReceiveTransactionFlow(
                otherSideSession = otherSession,
                checkSufficientSignatures = true,
                // We are recording all the states, 
                // and not just the ones where we are participants.
                statesToRecord = StatesToRecord.ALL_VISIBLE
        )

        subFlow(flow)
    }
}

节点可以选择记录它们收到的事务中的每个状态,而不是只记录它们是
参与者之一的状态。我在下面写了一个例子。您还可以查看实现此模式的可观察状态

发送交易

首先,拥有包含相关状态的交易的节点需要将交易发送给想要记录该交易但不是
参与者的交易对手。下面是我们如何定义一个
BrodcastTransactionFlow
来实现这一点:

@InitiatingFlow
class BroadcastTransaction(
    val stx: SignedTransaction, 
    val counterparty: Party) : FlowLogic<Unit>() {

    @Suspendable
    override fun call() {
        val session = initiateFlow(counterparty)
        subFlow(SendTransactionFlow(session, stx))
    }
}
@InitiatedBy(BroadcastTransaction::class)
class RecordTransactionAsObserver(val otherSession: FlowSession) : FlowLogic<Unit>() {

    @Suspendable
    override fun call() {
        val flow = ReceiveTransactionFlow(
                otherSideSession = otherSession,
                checkSufficientSignatures = true,
                // We are recording all the states, 
                // and not just the ones where we are participants.
                statesToRecord = StatesToRecord.ALL_VISIBLE
        )

        subFlow(flow)
    }
}