问题
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