源自另一个节点的generateSpend

时间:2018-11-21 10:54:46

标签: corda

以下方法是否可以用于创建从乙方到甲方的支出,但是当甲方运行的流程调用该方法时?

这将替换运行流向乙方的当前节点的身份。但是,它会返回CashKeys的异常:

java.util.NoSuchElementException: Collection contains no element matching the predicate.

方法:

val (_, cashKeys) = Cash.generateSpend(serviceHub, builder, amount, partyBCert, forwardState.initiator)

PartyAndCertificate获取者:

private fun getPartyBCert(): PartyAndCertificate {
    val partyBIdentityAndCertList = serviceHub.networkMapCache.getNodeByLegalName(CordaX500Name("PartyB", "New York", "US"))
            ?.legalIdentitiesAndCerts
            ?: throw FlowException("PartyB not found on network.")
    return partyBIdentityAndCertList.component1()
}

堆栈跟踪:

java.util.NoSuchElementException: Collection contains no element matching the predicate.
at net.corda.node.services.keys.PersistentKeyManagementService.getSigningKeyPair(PersistentKeyManagementService.kt:110) ~[corda-node-3.3-corda.jar:?]
at net.corda.node.services.keys.PersistentKeyManagementService.getSigner(PersistentKeyManagementService.kt:85) ~[corda-node-3.3-corda.jar:?]
at net.corda.node.services.keys.PersistentKeyManagementService.freshKeyAndCert(PersistentKeyManagementService.kt:83) ~[corda-node-3.3-corda.jar:?]
at net.corda.finance.contracts.asset.Cash$Companion.generateSpend(Cash.kt:332) ~[corda-finance-3.3-corda.jar:?]
at net.corda.finance.contracts.asset.Cash$Companion.generateSpend(Cash.kt:265) ~[corda-finance-3.3-corda.jar:?]
at net.corda.finance.contracts.asset.Cash$Companion.generateSpend$default(Cash.kt:264) ~[corda-finance-3.3-corda.jar:?]
at com.template.flows.SettleCashFlow.call(SettleCashFlow.kt:117) ~[cordapp-0.1.jar:?]
at com.template.flows.SettleCashFlow.call(SettleCashFlow.kt:31) ~[cordapp-0.1.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:96) [corda-node-3.3-corda.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:44) [corda-node-3.3-corda.jar:?]
at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_191]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_191]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_191]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_191]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_191]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_191]
at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:62) [corda-node-3.3-corda.jar:?]

收款人可以更改我的流程,这种情况下是否还有另一种方法而不必将其分为两个单独的流程?

编辑:缺少附件的堆栈跟踪

net.corda.core.contracts.TransactionVerificationException$MissingAttachmentRejection: Contract constraints failed, could not find attachment for: com.template.ForwardContract, transaction: B5606C7142B87D424DD0BDF8FF749987D53BF5B7D279795F32DA6AA4340D5403
at net.corda.core.transactions.LedgerTransaction.verifyConstraints(LedgerTransaction.kt:96) ~[corda-core-3.3-corda.jar:?]
at net.corda.core.transactions.LedgerTransaction.verify(LedgerTransaction.kt:79) ~[corda-core-3.3-corda.jar:?]
at net.corda.core.transactions.TransactionBuilder.verify(TransactionBuilder.kt:143) ~[corda-core-3.3-corda.jar:?]
at com.template.flows.SettleCashFlow.call(SettleCashFlow.kt:119) ~[cordapp-0.1.jar:?]
at com.template.flows.SettleCashFlow.call(SettleCashFlow.kt:32) ~[cordapp-0.1.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:96) [corda-node-3.3-corda.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:44) [corda-node-3.3-corda.jar:?]
at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_191]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_191]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_191]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_191]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_191]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_191]
at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:62) [corda-node-3.3-corda.jar:?]

这是由于generateSpend中缺少键吗?如果是,您如何以与甲方->乙方现金产生类似的方式从交易对手流程中检索密钥。 verifyConstraints()表示,来自另一个节点的事务需要验证附件。

1 个答案:

答案 0 :(得分:1)

代表其他人致电public function EncryptDB(){ if($this->UsersDAO->EncryptDB()){ echo 'done'; } else { echo 'error'; } } 根本行不通。它希望由现金所有者调用。

但是,您仍然可以在单个流程中添加现金。最简单的方法可能是将Cash.generateSpend发送到交易对手并让他们致电TransactionBuilder。用伪代码:

Cash.generateSpend

请注意,您需要将@InitiatingFlow @StartableByRPC class Initiator(val counterparty: Party) : FlowLogic<Unit>() { override val progressTracker = ProgressTracker() @Suspendable override fun call() { val txBuilder = TransactionBuilder() // TODO: Update TransactionBuilder. val counterpartySession = initiateFlow(counterparty) val updatedTxBuilder = counterpartySession .sendAndReceive<TransactionBuilder>(txBuilder) .unwrap { it -> it } // Check `updatedTxBuilder still has all the stuff you put in // originally, plus a new set of input/output cash states. // Finish flow using the `updatedTxBuilder`. } } @InitiatedBy(Initiator::class) class Responder(val counterpartySession: FlowSession) : FlowLogic<Unit>() { @Suspendable override fun call() { val txBuilder = counterpartySession .receive<TransactionBuilder>() .unwrap { it -> it } // Pass the correct arguments here. Cash.generateSpend(serviceHub, txBuilder, ...) counterpartySession.send(txBuilder) } } 添加到节点的序列化白名单中,才能在流中发送和接收它的实例。