【问题标题】:Query Corda transaction id of the transaction in which Linear state is consumed查询消费Linear状态的事务的Corda事务id
【发布时间】:2020-11-05 05:08:26
【问题描述】:

我们有线性状态“A”。我们有两个流程,一个用于创建状态“A”,另一个用于使用状态“A”。我们必须编写一个新流程,它将状态“A”的线性 id 作为参数,并返回消耗状态“A”的事务的 SingedTransaction id。我们如何在 Corda 中实现这一点?

【问题讨论】:

    标签: corda


    【解决方案1】:

    应该是这样的,但我不确定您将获得的交易是创建状态还是消费状态的交易;您需要测试以下代码:

    // Get the consumed state by its linearId.
    QueryCriteria consumedCriteria = new VaultQueryCriteria(Vault.StateStatus.CONSUMED);
    LinearStateQueryCriteria linearCriteria = new LinearStateQueryCriteria()
                        .withExternalId(Collections.singletonList("linearId"));
    Page<YourState> results = getServiceHub().getVaultService()
                        .queryBy(YourState.class, consumedCriteria.and(linearCriteria));
            
    // Get the transaction by its ID.
    // This is a simplified example which assumes that only one result is returned, 
    // you might get multiple results if your state was consumed (updated)
    // multiple times.    
    SecureHash txId = results.getStates().get(0).getRef().getTxhash();
    SignedTransaction tx = getServiceHub().getValidatedTransactions().getTransaction(txId);
    
    

    【讨论】:

    • 感谢阿德尔的回复。但是,上面的示例将在创建状态时给出事务。当状态被消费时,我们需要事务。
    • 是的,我不知道你会怎么做。
    猜你喜欢
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    相关资源
    最近更新 更多