首页 > 解决方案 > 当在 corda 中使用帐户和 oracle 时,谓词返回 false

问题描述

我正在尝试在corda中使用帐户功能以及oracle功能,问题在于构建过滤函数以获取oracle签名。我的 kotlin 代码,它使用谓词检查我的交易中是否有 oracle 密钥总是返回 false,即使我在用于签署初始交易的公钥列表中添加了 oracle publickey。

var requiredSigners = Arrays.asList(oracle.owningKey, urIdentity.owningKey, lenderAccountNewKey)
val output = IOUState(exchangeRate * value, lenderAccountNewKey, borrowerAccountNewKey)
    val transactionBuilder = TransactionBuilder(notary)
    var participantsList = ArrayList<AbstractParty>(output.participants)
    participantsList.add(oracle)
    transactionBuilder.addOutputState(output, IOUContract.ID)
            .addCommand(IOUContract.Commands.Create(), participantsList.map { it.owningKey })
    transactionBuilder.verify(serviceHub)

 var localSignedTx = serviceHub.signInitialTransaction(transactionBuilder)

        var filteredTx = localSignedTx.buildFilteredTransaction(Predicate {
            when (it) {
                is Command<*> -> oracle.owningKey in it.signers
                else -> false
            }
        }
val oracleSignature = subFlow(SignFlow(oracle, filteredTransaction))
    val stx = locallySignedTransaction.withAdditionalSignature(oracleSignature)


当尝试使用以下代码运行时,日志如下所示。

[信息] 2020-05-26T07:00:59,660Z [节点线程 1]corda.flow。- Flow 引发错误:集合不包含与谓词匹配的元素。将其发送到流医院进行分类。{actor_id=internalShell,actor_owning_identity=O=PartyA,L=London,C=GB,actor_store_id=NODE_CONFIG,fiber-id=10000003,flow-id=040d69f9-f93a-4a23-bdb4-594c41d38987,invocation_id=3da3d8a0-64ec-4a41 -8f18-b0ca05557490, invocation_timestamp=2020-05-26T07:00:58.102Z, origin=internalShell, session_id=dec88c8e-1441-425b-bfe0-f00ad6b12126, session_timestamp=2020-05-26T06:58:59.126Z, threadid- =161} [INFO] 2020-05-26T07:00:59,666Z [节点线程 1] statemachine.StaffedFlowHospital。- 流程 [040d69f9-f93a-4a23-bdb4-594c41d38987] 入院状态

标签: corda

解决方案


  • 指定命令时应该传递requiredSignerslist ;目前你正在通过participantsList
  • 顺便说一句,预言机不应该是参与者。它通常是提供经过验证的数据的第三方。
    如果您要通过使其成为参与者来在 oracle 中注册完整的交易和相关状态(假设participantsList是您将在最终流程中使用的内容),那么向 oracle 发送过滤交易有什么意义。
  • 您应该使用WireTransaction来构建过滤的事务(即localSignedTx.tx.buildFilteredTransaction())(注意.tx)。
  • 你有一个错字,你用filteredTransactionin SignFlow; 你的变量名是filteredTx.

推荐阅读