首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Corda:如何向网络上的其他各方显示双方之间的协议?

问Corda:如何向网络上的其他各方显示双方之间的协议?
EN

Stack Overflow用户
提问于 2018-02-21 18:23:02
回答 1查看 74关注 0票数 2

爱丽丝和鲍勃有一份欠条协议。如果爱丽丝想证明她真的和鲍勃有协议,她有没有可能把和鲍勃的借条协议拿给查利看?查利如何验证爱丽丝和鲍勃之间的借条是真的而不是假的?这个用例的流程是什么?

EN

回答 1

Stack Overflow用户

发布于 2018-02-21 22:48:33

爱丽丝可以通过将创建协议的事务发送给查利,向查利证明她与鲍勃之间存在有效的协议。

然后,查理会检查事务是否有效,是否具有所有必需的签名者,以及是否已由Alice和Bob签名。

下面的流对将实现这一点:

代码语言:javascript
复制
/**
 * 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
        }
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48903445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档