Is it possible to add an auditor peer in corda?

Deadly 提交于 2019-12-24 12:25:13

问题


I would like to add some sort of an auditor peer in corda. Is it possible with my use case?:

Currently the network has two peers: partyA and partyB. There are about 100 transactions involving both parties. Lets say later on a partyC (the auditor) joins the network: is it possible to give partyC access to all of those already posted (and future) transactions in the ledger involving partyA and partyB?.


回答1:


You should use the observer nodes feature. See the tutorial here and the Observable States sample here.

In your case, you need the following flows for partyA or partyB to send all the past transactions to the auditor when the auditor first joins the network:

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

Then for all subsequent transactions between partyA and partyB, you need to do the following to notify the auditor:

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

Alternatively, partyA and partyB could extract all the past transactions from their node's database, and send them to the auditor directly. The auditor can then check the transactions and their signatures off-platform.



来源:https://stackoverflow.com/questions/49217202/is-it-possible-to-add-an-auditor-peer-in-corda

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!