gpt4 book ai didi

java - 生成TransactionBuilder时出错: Parameter specified as non-null is null

转载 作者:行者123 更新时间:2023-11-30 05:40:01 25 4
gpt4 key购买 nike

首先,我正在部署一个没有公证人的 Corda 网络,因为生成的交易不会使用任何输入状态或时间戳,而且我正在用 Java 编写 CorDapps,因为我的 Kotlin 知识有限。

在我的 IOUFlow 类(这个类实现 FlowLogic)的 call() 方法中,创建了一个 TransactionBuilder 对象,并且没有定义公证人。项目编译成功,并在节点启动时包含在 cordapps 文件夹中。当我尝试创建交易时出现问题,应用程序给我一个错误。

请问有人可以看一下我的 Java 代码并给我一些有关问题的线索吗?

@Suspendable
@Override
public Void call() throws FlowException {
// We retrieve the notary identity from the network map.
//Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
@NotNull
Party notary = null;

// We create the transaction components.
IOUState outputState = new IOUState(iouAmount, iouCurrencyCode, bank, getOurIdentity(), recipient);
List<PublicKey> requiredSigners = Arrays.asList(bank.getOwningKey(), getOurIdentity().getOwningKey(), recipient.getOwningKey());
Command command = new Command<>(new IOUContractCreate.Create(), requiredSigners);

// We create a transaction builder and add the components.
//TransactionBuilder txBuilder = new TransactionBuilder(null).addOutputState(outputState, IOUContractCreate.ID).addCommand(command);
//TransactionBuilder txBuilder = new TransactionBuilder(notary).addOutputState(outputState, IOUContractCreate.ID).addCommand(command);

TransactionBuilder txBuilder = new TransactionBuilder(notary);
//txBuilder.setNotary(notary);
//txBuilder.addInputState(null);
txBuilder.addOutputState(outputState, IOUContractCreate.ID);
txBuilder.addCommand(command);

// Verifying the transaction.
txBuilder.verify(getServiceHub());

// Signing the transaction.
SignedTransaction signedTx = getServiceHub().signInitialTransaction(txBuilder);

// Creating a session with the other parties.
FlowSession bankFlowSession = initiateFlow(bank);
FlowSession recipientFlowSession = initiateFlow(recipient);

// Obtaining the counterparty's signature.
SignedTransaction fullySignedTx = subFlow(new CollectSignaturesFlow(signedTx, Arrays.asList(bankFlowSession, recipientFlowSession), CollectSignaturesFlow.tracker()));

// Finalising the transaction.
subFlow(new FinalityFlow(fullySignedTx, bankFlowSession, recipientFlowSession));

return null;
}

执行此命令时出错:启动 IOUFlow iouAmount: 99,iouCurrencyCode: "USD",银行:"O=Bank,L=Philadelpia,C=US",收件人:"O=User2,L=Madrid,C= ES”

[ERROR] 2019-04-24T22:26:42,112Z [Node thread-1] proxies.ExceptionSerialisingRpcOpsProxy.log - Error during RPC invocation [errorCode=hq8kcg, moreInformationAt=https://errors.corda.net/OS/4.0/hq8kcg] {actor_id=internalShell, actor_owning_identity=O=User1, L=New York, C=US, actor_store_id=NODE_CONFIG, fiber-id=10000001, flow-id=d0b507d1-6497-4408-8afe-bab039e28543, invocation_id=657d59ff-4f41-4ab5-9288-4eeb9033604c, invocation_timestamp=2019-04-24T22:26:41.792Z, origin=internalShell, session_id=c4bd127e-0030-4b49-9cd0-d6a139601e87, session_timestamp=2019-04-24T22:26:41.283Z, thread-id=249}
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method net.corda.core.transactions.TransactionBuilder.<init>, parameter notary
at net.corda.core.transactions.TransactionBuilder.<init>(TransactionBuilder.kt) ~[corda-core-4.0.jar:?]
at com.template.flows.IOUFlow.call(IOUFlow.java:85) ~[?:?]
at com.template.flows.IOUFlow.call(IOUFlow.java:40) ~[?:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:228) ~[corda-node-4.0.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:45) ~[corda-node-4.0.jar:?]
at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092) ~[quasar-core-0.7.10-jdk8.jar:0.7.10]
at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788) ~[quasar-core-0.7.10-jdk8.jar:0.7.10]
at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) ~[quasar-core-0.7.10-jdk8.jar:0.7.10]
at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) ~[quasar-core-0.7.10-jdk8.jar:0.7.10]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_202]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_202]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source) ~[?:1.8.0_202]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) ~[?:1.8.0_202]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[?:1.8.0_202]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[?:1.8.0_202]
at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:63) ~[corda-node-4.0.jar:?]

最佳答案

因此,您将变量声明为 @NotNull 并同时为其分配 null。您应该删除该注释或该作业。

@NotNull
Party notary = null;

关于java - 生成TransactionBuilder时出错: Parameter specified as non-null is null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55840033/

25 4 0