制作东西 public

Making things public

有没有办法设计一个允许新节点加入网络的合约来发现一些 UTXO 及其历史?

可以在合约中添加状态转换,将新方添加到对话中,但这需要每次加入都进行交易。

您可以通过编写一个流对来实现这一点,该流对允许加入节点从网络上已有的其他节点请求特定的现有交易。

这是一个虚拟实现示例:

@InitiatingFlow
@StartableByRPC
class Initiator(val txIdToRequest: SecureHash, val partyToRequestFrom: Party) : FlowLogic<SignedTransaction>() {
    @Suspendable
    override fun call(): SignedTransaction {
        val sessionWithPartyToRequestFrom = initiateFlow(partyToRequestFrom)
        val untrustworthyData = sessionWithPartyToRequestFrom.sendAndReceive<SignedTransaction>(txIdToRequest)
        val requestedTx = untrustworthyData.unwrap { tx -> tx }
        return requestedTx
    }
}

@InitiatedBy(Initiator::class)
class Responder(val counterpartySession: FlowSession) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        val untrustworthyData = counterpartySession.receive<SecureHash>()
        val requestedTxId = untrustworthyData.unwrap { id -> id }
        val requestedTx = serviceHub.validatedTransactions.getTransaction(requestedTxId)!!
        counterpartySession.send(requestedTx)
    }
}