是否可以在 corda 中添加审核员同行?
Is it possible to add an auditor peer in corda?
我想在 corda 中添加某种审核员同行。我的用例是否可行?:
当前网络有两个节点:partyA 和 partyB。涉及双方的交易大约有 100 笔。假设稍后 C 方(审计员)加入网络:是否可以让 C 方访问分类帐中涉及 A 方和 B 方的所有那些已经发布(和未来)的交易?
您应该使用观察者节点功能。请参阅教程 here and the Observable States sample here。
在您的情况下,您需要 partyA
或 partyB
的以下流程,以便在审计员首次加入网络时将所有过去的交易发送给审计员:
@InitiatingFlow
@StartableByRPC
class SendAllPastTransactionsToAuditor : FlowLogic<Unit>() {
@Suspendable
override fun call() {
// We extract all existing transactions from the vault.
val transactionFeed = serviceHub.validatedTransactions.track()
transactionFeed.updates.notUsed()
val transactions = transactionFeed.snapshot
// We send all the existing transactions to the auditor.
val auditor = serviceHub.identityService.partiesFromName("Auditor", true).single()
val session = initiateFlow(auditor)
transactions.forEach { transaction ->
subFlow(SendToAuditorFlow(session, transaction))
}
}
}
@InitiatingFlow
class SendToAuditorFlow(val session: FlowSession, val transaction: SignedTransaction) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
subFlow(SendTransactionFlow(session, transaction))
}
}
@InitiatedBy(SendToAuditorFlow::class)
class ReceiveAsAuditorFlow(private val otherSideSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
// We record all the visible states in the transactions we receive.
subFlow(ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ALL_VISIBLE))
}
}
然后对于partyA
和partyB
之间的所有后续交易,您需要执行以下操作以通知审计员:
@InitiatingFlow
@StartableByRPC
class RegularFlow : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val transaction: SignedTransaction = TODO("Regular flow activity to agree transaction.")
val auditor = serviceHub.identityService.partiesFromName("Auditor", true).single()
val session = initiateFlow(auditor)
subFlow(SendToAuditorFlow(session, transaction))
}
}
或者,partyA
和 partyB
可以从他们节点的数据库中提取所有过去的交易,并将它们直接发送给审计员。然后审计员可以检查交易及其签名 off-platform.
我想在 corda 中添加某种审核员同行。我的用例是否可行?:
当前网络有两个节点:partyA 和 partyB。涉及双方的交易大约有 100 笔。假设稍后 C 方(审计员)加入网络:是否可以让 C 方访问分类帐中涉及 A 方和 B 方的所有那些已经发布(和未来)的交易?
您应该使用观察者节点功能。请参阅教程 here and the Observable States sample here。
在您的情况下,您需要 partyA
或 partyB
的以下流程,以便在审计员首次加入网络时将所有过去的交易发送给审计员:
@InitiatingFlow
@StartableByRPC
class SendAllPastTransactionsToAuditor : FlowLogic<Unit>() {
@Suspendable
override fun call() {
// We extract all existing transactions from the vault.
val transactionFeed = serviceHub.validatedTransactions.track()
transactionFeed.updates.notUsed()
val transactions = transactionFeed.snapshot
// We send all the existing transactions to the auditor.
val auditor = serviceHub.identityService.partiesFromName("Auditor", true).single()
val session = initiateFlow(auditor)
transactions.forEach { transaction ->
subFlow(SendToAuditorFlow(session, transaction))
}
}
}
@InitiatingFlow
class SendToAuditorFlow(val session: FlowSession, val transaction: SignedTransaction) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
subFlow(SendTransactionFlow(session, transaction))
}
}
@InitiatedBy(SendToAuditorFlow::class)
class ReceiveAsAuditorFlow(private val otherSideSession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
// We record all the visible states in the transactions we receive.
subFlow(ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ALL_VISIBLE))
}
}
然后对于partyA
和partyB
之间的所有后续交易,您需要执行以下操作以通知审计员:
@InitiatingFlow
@StartableByRPC
class RegularFlow : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val transaction: SignedTransaction = TODO("Regular flow activity to agree transaction.")
val auditor = serviceHub.identityService.partiesFromName("Auditor", true).single()
val session = initiateFlow(auditor)
subFlow(SendToAuditorFlow(session, transaction))
}
}
或者,partyA
和 partyB
可以从他们节点的数据库中提取所有过去的交易,并将它们直接发送给审计员。然后审计员可以检查交易及其签名 off-platform.