在搜索链中,我可以找到是否已消耗某些东西以及消耗了什么东西吗? [英] Searching the chain can i find if something has been consumed and what it was consumed by?

查看:28
本文介绍了在搜索链中,我可以找到是否已消耗某些东西以及消耗了什么东西吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将信息传递给一个节点,但是最初发送该节点时该节点可能不在网络上.因此,要解决此问题,我使用的是事务引用,事务使用"addReferenceState"引用以前的状态,然后使服务中心能够递归地遍历这些信息.

I am trying to pass out information to a node but that node may not have been on the network when it was initially sent out. So to work around this I am using transaction references, the transaction uses "addReferenceState" to reference previous states, and then the service hub to have the ability to recursively run back through the information.

所以我有一种很好并且可行的方法.

So I have this method that's all fine and works.

private fun findInChain(infoState: StateAndRef<InfoState>): StateAndRef<InfoState> {
    val stx = serviceHub.validatedTransactions.getTransaction(state.ref.txhash)!!
    if (infoState.state.data.id == id) {
        return state
    } else {
        val prvRef =
            stx.tx.references.single()
        val prvState = serviceHub.validatedTransactions.getTransaction(prvRef.txhash)!!.tx.outRefsOfType<InfoState>()
                .single()
        return findInChain(prvState)
    }
}

但是我现在有一个新的要求,即可以将这些状态中的任何一个都用作更新信息的输入.

However I now have a new requirement that any one of those states could be consumed as an input to update the pice of information.

因此,新要求意味着我首先需要在返回状态之前检查状态是否已被消耗,其次需要找到消耗状态的事务...

So the new requirement means I first of all need to check if a state has been consumed before sending it back and secondly need to find the transaction that consumed it ...

private fun findInChain(infoState: StateAndRef<InfoState>): StateAndRef<InfoState> {
    val stx = serviceHub.validatedTransactions.getTransaction(state.ref.txhash)!!
    if (infoState.state.data.id == id) {
        
        // 1st Check if the state is consumed

        // 2nd: If the state is consumed find what consumed it

        return state
    } else {
        val prvRef =
            stx.tx.references.single()
        val prvState = serviceHub.validatedTransactions.getTransaction(prvRef.txhash)!!.tx.outRefsOfType<InfoState>()
                .single()
        return findInChain(prvState)
    }
}

非常感谢您提前提供帮助

Thanks for any help in advance

推荐答案

我需要了解您的用例以获得更好的答案.我相信您使用的参考状态不正确. ReferenceStates 用于需要访问事务中的状态数据而不使用它的情况.您可以将其视为存储主数据的对象,并且可以在不同的事务中引用它,而不必使用它们.

I would need to understand your use case to have a better answer. I believe you are using the reference state incorrectly. ReferenceStates are used in situations where you want to have access to a state's data in a transaction without consuming it. You could think of it as something that stores master data and you can refer to it in different transactions without necessarily consuming it.

根据您的要求,您可以使用 Vault.StateStatus.ALL 条件执行vaultQuery,无论是否消耗该状态,都将获取状态.然后,您可以检查状态以识别其是否已消耗.或者只是获取已消耗/未消耗并根据返回的结果数进行检查.无论哪种方式.

As per your requirement, you could do a vaultQuery with Vault.StateStatus.ALL criteria, which would fetch the state irrespective it's consumed to not. You could then check the status to identify if it's consumed. Or just fetch the Consumed/ Unconsumed and check based on the number of results returned. Either way you like.

尽管可以将trnx链向后移动,但我不知道直接的API可以为您提供哪个事务消耗了状态.您可能需要为此构建自定义解决方案.

Though one could walk the trnx-chain in backward direction, I am not aware of a direct API which can give you which transaction consumed a state. You might perhaps have to build a custom solution for this.

这篇关于在搜索链中,我可以找到是否已消耗某些东西以及消耗了什么东西吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆