2017-10-18 2 views
0

이 자습서에서는 노드가 상대방에게 볼트를 쿼리하고 필요한 결과를 제공하도록 요청할 수 있다고 언급했습니다. 흐름에서이 논리를 통합하는 데 사용할 수있는 API가 있습니까? 또한 당사 상대방에게 상대방으로부터 정보를 수집하고 누적 결과를 반환하도록 요청하는 것이 가능합니다. 있는 경우 예제 코드를 공유하십시오. 감사.Corda : 네트워크의 다른 당사자로부터 입력 수집

답변

1

특수 API가 없습니다. 표준 FlowSession.send/FlowSession.receive/FlowSession.sendAndReceive 전화 만 사용하면됩니다. 상대방으로부터 데이터를 수신시 그러나

, (일반적으로 SignedTransaction 또는 StateAndRef 중 하나), 당신은 당신이이 거래의 올바른 순서를 작성 확인할 수 있도록 ResolveTransactionsFlow를 사용하여 의존성 체인을 해결해야합니다.

SendTransactionFlow/ReceiveTransactionFlow 쌍이있어 트랜잭션 수신, 언 래핑 및 종속성 해결 과정을 자동화합니다.

@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) 
    } 
} 
: 여기

에는 상대방에 의해 전송 된 수신 노드 A StateAndRef<ContractState>의 예
관련 문제