Corda是否拥有如何将新节点的数据共享到网络中的最佳做法?例如,节点A有事务,我们有新的一个节点B.节点A必须与节点B共享过去3个月的事务。
你能分享一些如何做的例子吗?
感谢。
答案 0 :(得分:1)
您可以轻松为此编写流程对。
第一方调用以下流程将所有存储的交易发送给交易对手:
@InitiatingFlow
@StartableByRPC
class Sender(val counterparty: Party) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val (existingTransactions, _) = serviceHub.validatedTransactions.track()
val counterpartySession = initiateFlow(counterparty)
counterpartySession.send(existingTransactions)
}
}
交易对手通过调用以下流程来响应以接收和记录所有交易:
@InitiatedBy(Sender::class)
class Receiver(val counterpartySession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val existingTransactions = counterpartySession.receive<List<SignedTransaction>>().unwrap { it }
serviceHub.recordTransactions(existingTransactions)
}
}