Corda:收集网络中其他各方的输入 [英] Corda: Gathering inputs from other parties in the network

查看:29
本文介绍了Corda:收集网络中其他各方的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本教程中,提到了一个节点可以要求另一方查询其保管库并提供所需的结果.是否存在可用于在流程中集成此逻辑的API?另外,是否可以要求我们的对手方收集对方的意见并返回累计结果.请共享示例代码(如果有).谢谢.

In the tutorial, it is mentioned that a node can ask the other party to query its vault and give the required results. Is there an API that can be used to integrate this logic in the flow? Also, is it possible to ask our counter parties to gather inputs from their counter parties and return the cumulative results. Please share the example code, if any. Thanks.

推荐答案

没有专门的API.您只需使用标准的 FlowSession.send / FlowSession.receive / FlowSession.sendAndReceive 调用.

There is no specialised API. You just use the standard FlowSession.send / FlowSession.receive / FlowSession.sendAndReceive calls.

但是,在从交易对手(通常是 SignedTransaction StateAndRef )接收到数据之后,请确保使用 ResolveTransactionsFlow 来解析其依赖项链.代码>,以便您可以验证它是通过有效的交易序列创建的.

However, upon receiving the data from the counterparty (usually either a SignedTransaction or a StateAndRef), make sure you resolve its dependency chain using ResolveTransactionsFlow so that you can verify it was created through a valid sequence of transactions.

还有一个内置的 SendTransactionFlow / ReceiveTransactionFlow 对,可自动执行接收交易,拆开交易和解决其依赖关系的过程.

There is also a built-in SendTransactionFlow / ReceiveTransactionFlow pair that automates the process of receiving a transaction, unwrapping it, and resolving its dependencies.

这是一个示例,该节点接收交易对手发送的 StateAndRef< ContractState> :

Here's an example of a node receiving a StateAndRef<ContractState> sent by a counterparty:

@InitiatingFlow
@StartableByRPC
class Initiator(private val counterparty: Party) : 
FlowLogic<StateAndRef<ContractState>>() {
    @Suspendable
    override fun call(): StateAndRef<ContractState> {
        val counterpartySession = initiateFlow(counterparty)
        // Our flow will suspend and wait for a StateAndRef from the counterparty.
        val untrustedData = counterpartySession.receive<StateAndRef<ContractState>>()
        // Data received off the wire is considered untrustworthy, and must be unwrapped.
        val stateAndRef = untrustedData.unwrap { stateAndRef ->
            // We resolve the chain of transactions that generated this StateAndRef.
            subFlow(ResolveTransactionsFlow(setOf(stateAndRef.ref.txhash), counterpartySession))
            // TODO: More checking of what we've received.
            stateAndRef
        }
        return stateAndRef
    }
}

@InitiatedBy(Initiator::class)
class Responder(val counterpartySession: FlowSession) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        // We extract the first StateAndRef in our vault...
        val stateAndRef = serviceHub.vaultService.queryBy(ContractState::class.java).states.first()
        // ...and send it to our counterparty.
        counterpartySession.send(stateAndRef)
    }
}

这篇关于Corda:收集网络中其他各方的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆