是否可以在corda中添加审核员对等体?

时间:2018-03-11 06:12:04

标签: corda

我想在corda中添加一些审计员同行。是否可以使用我的用例?:

目前,该网络有两个对等方:partyA和partyB。涉及双方的约100项交易。让我们稍后说一个partyC(审计员)加入网络:是否有可能让partyC访问涉及partyA和partyB的分类账中所有已发布(和未来)的交易?

1 个答案:

答案 0 :(得分:1)

您应该使用观察者节点功能。请参阅教程here和可观察状态示例here

在您的情况下,当审核员首次加入网络时,您需要partyApartyB的以下流程将所有过去的交易发送给审核员:

@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))
    }
}

然后,对于partyApartyB之间的所有后续交易,您需要执行以下操作以通知审核员:

@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))
    }
}

或者,partyApartyB可以从其节点的数据库中提取所有过去的事务,并直接将它们发送给审计员。然后,审计员可以在平台外检查交易及其签名。