我有情景:
NodeA向NodeB发送状态(State:value = 100,CustomerFlag = 0 )
NodeB检查状态/值并发送已批准的标志 签名。(州:值= 100,CustomerFlag = 1 )
你可以帮我看看如何在NodeB响应批准/拒绝时添加该值吗?
发起人类:
@Suspendable
override fun call(): SignedTransaction {
val notary = serviceHub.networkMapCache.notaryIdentities[0]
val iouState = IOUState(iouValue, serviceHub.myInfo.legalIdentities.first(), otherParty)
val txCommand = Command(IOUContract.Commands.Create(), iouState.participants.map { it.owningKey })
val txBuilder = TransactionBuilder(notary).withItems(StateAndContract(iouState, IOU_CONTRACT_ID), txCommand)
txBuilder.verify(serviceHub)
otherPartyFlow.send(partSignedTx)
val partSignedTx = serviceHub.signInitialTransaction(txBuilder)
val otherPartyFlow = initiateFlow(otherParty)
otherPartyFlow.send(partSignedTx)
return partSignedTx
}
}
接受者类:
@InitiatedBy(Initiator::class)
class Acceptor(val otherPartyFlow: FlowSession) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val receivedData = otherPartyFlow.receive<SignedTransaction>()
receivedData.unwrap {data -> data }
<<<<< Need help here how to add value and send back >>>>
return updatedData
}
}
答案 0 :(得分:2)
您可能需要稍微重新考虑一下您的流程才能使其正常运行。我想说你最好的选择不是将签署的交易发送给接受者,而是发送IOU状态。然后,Acceptor类可以在状态中更改此标志,并创建/签署事务。然后可以将其发送回启动器类,以验证标志是否已更改,签署事务,然后将其提交到分类帐。
@Suspendable
override fun call(): SignedTransaction {
val iouState = IOUState(iouValue, serviceHub.myInfo.legalIdentities.first(), otherParty)
val otherPartyFlow = initiateFlow(otherParty)
otherPartyFlow.send(iouState)
//Receieve back the signedTransaction
val ptx = otherPartyFlow.receive<SignedTransaction>().unwrap{it}
val stx = serviceHub.addSignature(ptx)
//Resolve and commit to the ledger
subFlow(ResolveTransactionsFlow(stx, otherPartyFlow))
return subFlow(FinalityFlow(stx))
}
}
@InitiatedBy(Initiator::class)
class Acceptor(val otherPartyFlow: FlowSession) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val notary = serviceHub.networkMapCache.notaryIdentities[0]
val receivedData = otherPartyFlow.receive<IOUState>().unwrap{
//Do any state verification here
it
}
receivedData.customerFlag = 1
//Create the txn
val txCommand = Command(IOUContract.Commands.Create(), receivedData.participants.map { it.owningKey })
val txBuilder = TransactionBuilder(notary).withItems(StateAndContract(receivedData, IOU_CONTRACT_ID), txCommand)
//Sign the transaction
val partSignedTx = serviceHub.signInitialTransaction(txBuilder)
otherPartyFlow.send(partSignedTx)
return waitForLedgerCommit(partSignedTx.id)
}
}
您还可以考虑使用signTransactionsFlow来收集签名,而不是像上面所做的那样来回发送stx - 请参阅https://docs.corda.net/flow-state-machines.html
答案 1 :(得分:0)
我创建了2个独立的流客户端和客户。
客户流程1: 创建状态,将批准标志设置为0并提交到分类帐。
subFlow(FinalityFlow(fullySignedTx, FINALISING_TRANSACTION.childProgressTracker()))
客户流程2:
提取客户提交的状态,并将该状态用作客户流的输入。
val criteria = QueryCriteria.VaultQueryCriteria(status = Vault.StateStatus.UNCONSUMED)
val results = serviceHub.vaultService.queryBy<POCState>(criteria)
val pocState = results.states.last().state.data
重置审批标志= 1并提交分类帐。
val ourOtherOutputState: POCState = pocState.copy(stateCode = pocStateCode)
val txCommand = Command(BankContract.Commands.Create(), pocState.participants.map { it.owningKey })
val txBuilder = TransactionBuilder(notary).withItems(StateAndContract(ourOtherOutputState, POC_CONTRACT_ID), txCommand)
val partSignedTx = serviceHub.signInitialTransaction(txBuilder)
val fullySignedTx = subFlow(CollectSignaturesFlow(partSignedTx, setOf(otherPartyFlow), GATHERING_SIGS.childProgressTracker()))
return subFlow(FinalityFlow(fullySignedTx, FINALISING_TRANSACTION.childProgressTracker()))
感谢@Raymond Mogg的支持!