corda - 当在 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] 入院状态
解决方案
- 指定命令时应该传递
requiredSigners
list ;目前你正在通过participantsList
。 - 顺便说一句,预言机不应该是参与者。它通常是提供经过验证的数据的第三方。
如果您要通过使其成为参与者来在 oracle 中注册完整的交易和相关状态(假设participantsList
是您将在最终流程中使用的内容),那么向 oracle 发送过滤交易有什么意义。 - 您应该使用
WireTransaction
来构建过滤的事务(即localSignedTx.tx.buildFilteredTransaction()
)(注意.tx
)。 - 你有一个错字,你用
filteredTransaction
inSignFlow
; 你的变量名是filteredTx
.
推荐阅读
- python - 如何找出我正在使用的 python 虚拟环境?
- android - Microsoft Face API (Android) - 将人员添加到人员组
- java - 有什么理由让 Spring 单例 bean 中的私有方法成为静态的?
- javascript - 在使用 Firebase 的 React-native GiftedChat 聊天应用程序中加载早期消息时遇到问题
- python - 优化和改进模拟投掷棒球的 3D 轨迹的 Python 代码
- haskell - 了解 Haskell 类型类在类型声明中的使用
- python - 在 Python/Micropython 中使用 ADS1x15 库和 ADS1114
- nativescript - ListView 滑动删除
- python - 如何获取 youtube 混合播放列表?
- c# - UWP 中的蓝牙 LE 设备发现