爱丽丝和鲍勃有一份欠条协议。如果爱丽丝想证明她真的和鲍勃有协议,她有没有可能把和鲍勃的借条协议拿给查利看?查利如何验证爱丽丝和鲍勃之间的借条是真的而不是假的?这个用例的流程是什么?
发布于 2018-02-21 22:48:33
爱丽丝可以通过将创建协议的事务发送给查利,向查利证明她与鲍勃之间存在有效的协议。
然后,查理会检查事务是否有效,是否具有所有必需的签名者,以及是否已由Alice和Bob签名。
下面的流对将实现这一点:
/**
* Sends a transaction with the given [txHash] to the [counterparty]:
*
* @param txHash the transaction to send.
* @param counterparty the counterparty to send the transaction to.
*/
@InitiatingFlow
@StartableByRPC
class Initiator(val txHash: SecureHash,
val counterparty: Party) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val tx = serviceHub.validatedTransactions.getTransaction(txHash)!!
val counterpartySession = initiateFlow(counterparty)
counterpartySession.send(tx)
}
}
/**
* Receives a transaction from the counterparty and checks that:
* - It is valid
* - It has valid signatures from all required signers
* - The [requiredSigners] have all signed the transaction
*
* @param counterpartySession a session with the party sending the transaction to be checked.
* @param requiredSigners the parties who are required to have signed the transaction.
*/
@InitiatedBy(Initiator::class)
class Acceptor(val counterpartySession: FlowSession,
val requiredSigners: List<CordaX500Name>) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
return counterpartySession.receive<SignedTransaction>().unwrap { tx ->
// Transaction is valid and all the required signatures are present and valid.
tx.verify(serviceHub)
val requiredSigningParties = requiredSigners.map { serviceHub.networkMapCache.getPeerByLegalName(it)!! }
val allHaveSigned = requiredSigningParties.all { party -> tx.sigs.any { sig -> sig.by == party.owningKey } }
if (!allHaveSigned) {
throw FlowException("The required parties have not signed the transaction.")
}
// TODO: Additional checking of the transaction (e.g. the properties of the inputs and outputs).
tx
}
}
}https://stackoverflow.com/questions/48903445
复制相似问题