【问题标题】:Find a state by unique ID in a cordapp api/flow在 cordapp api/flow 中通过唯一 ID 查找状态
【发布时间】:2018-10-12 14:25:26
【问题描述】:

我可以找到一个带有 txhash 的状态吗?我想要这样的东西:val state = rpcOps.findStateFromTXhash(txhash)

我发现有一种名为 linearState 的状态具有 linearId 属性。还有一个哈希属性,但我不知道它是否是我搜索的。

【问题讨论】:

    标签: corda


    【解决方案1】:

    在您的流程中,您可以在此处执行 getServiceHub().loadState(),您可以传入 securehash 以获取您的状态。不确定我们是否可以直接从 CordaRpcConnection 对象做类似的事情。

    如果它是一种线性状态,您的状态将有一个 linearId。您可以使用 linearId 轻松搜索您的状态。 阅读here。 我建议您阅读有关州的更多信息,以了解最适合您的要求。 Link

    【讨论】:

      【解决方案2】:

      在给定事务 ID 的情况下,没有 RPC 操作来加载事务的状态。

      但是,您可以编写一个流程来执行此操作,如下所示,然后通过 RPC 调用此流程:

      @InitiatingFlow
      @StartableByRPC
      class GetStatesFromTransactionFlow(val transactionID: SecureHash) : FlowLogic<List<ContractState>>() {
      
          @Suspendable
          override fun call(): List<ContractState> {
              val signedTransaction = serviceHub.validatedTransactions.getTransaction(transactionID)
      
              if (signedTransaction == null) {
                  throw FlowException("Transaction does not exist in node's transaction storage.")
              }
      
              val ledgerTransaction = signedTransaction.toLedgerTransaction(serviceHub)
              val inputs = ledgerTransaction.inputs.map { it.state.data }
              val outputs = ledgerTransaction.outputs.map { it.data }
      
              return inputs + outputs
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2016-07-04
        • 2020-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多