为什么用Oraclize无法将null强制转换为非null类型net.corda.core.identity.Party错误?

时间:2018-07-10 13:20:09

标签: kotlin corda

我一直在尝试将Oraclize实施到我的CorDapp中,并且创建的流程运行完美,但是当我尝试添加Oraclize查询时,我收到错误消息:null不能转换为非null类型net.corda.core身份方。这是有问题的代码。

        val current = LocalDateTime.now().toString()
        val airplaneStatus = subFlow(OraclizeQueryAwaitFlow(
            datasource = "URL",
            query = "json(https://api.flightstats.com/flex/flightstatus/rest/v2/json/flight/status/" + flight.subSequence(0,2) + "/" + flight.subSequence(2, flight.length) + "/arr/" +
            current.subSequence(0,4) + "/" + current.subSequence(5,7) + "/" + current.subSequence(8,10) + "?appId=******&appKey=***********&utc=false).flightStatuses.status",
            proofType = ProofType.TLSNOTARY,
            delay = 1
        ))

航班是简单的航班ID,例如AC345或WS9405。整个流程在这里:https://pastebin.com/7uvPnjEf

更新:我添加了delay参数,但错误仍然存​​在(尝试0和1)。我还验证了ProofType.TLSNOTARY不为空。

谢谢!

日志错误报告:

[WARN ] 2018-07-10T16:08:00,619Z [Node thread-1] flow.[a0362ed5-74b5- 
4519-a80e-4adda70adca7].run - Terminated by unexpected exception {}
kotlin.TypeCastException: null cannot be cast to non-null type net.corda.core.identity.Party
at it.oraclize.cordapi.flows.OraclizeQueryAwaitFlow.call(OraclizeQueryAwaitFlow.kt:36) ~[InsureFlight-0.1.jar:?]
at it.oraclize.cordapi.flows.OraclizeQueryAwaitFlow.call(OraclizeQueryAwaitFlow.kt:18) ~[InsureFlight-0.1.jar:?]
at net.corda.core.flows.FlowLogic.subFlow(FlowLogic.kt:290) ~[corda-core-3.1-corda.jar:?]
at com.insureflight.flows.IssuePolicy$Initiator.call(IssuePolicy.kt:76) ~[cordapp-0.1.jar:?]
at com.insureflight.flows.IssuePolicy$Initiator.call(IssuePolicy.kt:37) ~[cordapp-0.1.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:96) [corda-node-3.1-corda.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:44) [corda-node-3.1-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_172]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_172]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_172]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_172]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_172]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_172]
at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:62) [corda-node-3.1-corda.jar:?]

3 个答案:

答案 0 :(得分:1)

从github上的库中查找存储库,并记录日志错误(OraclizeQueryAwaitFlow.kt的第36行,请参见here),我认为该问题的发生是因为

  • 呼叫serviceHub.identityService.wellKnownPartyFromX500Name(OraclizeUtils.getNodeName())返回null
  • 想要为Party强制转换为null值,但无法抛出TypeCastException

我的建议

1。(推荐)(在此存储库中打开一个问题,要求该错误解决方案,然后等待开发人员的响应,或者

2。。分叉此存储库,然后您验证此投射尝试并使用分叉的存储库

答案 1 :(得分:0)

您忘记传递第四个参数,即参数delay

OraclizeQueryAwaitFlow(val datasource: String,
                             val query: Any,
                             val proofType: Int = 0,
                             val delay: Int = 0) //here <------

为什么?

此参数为非空(它没有elvis(?)运算符),需要进行赋值

答案 2 :(得分:0)

您是否将Cordapp加载到公共测试网上?如果不是,那可能是问题所在,因为identityService无法到达我们的公共节点。我们目前正在开发一种用于在专用网络上进行测试的工具,但与此同时,您应该将cordapp加载到连接到公共测试网的节点上。