我可以从CordaRPCOps解析指针吗?
考虑以下几点:我可以从CordaRPCOps解析指针吗?,corda,Corda,考虑以下几点: data class ChildState( val name: Party, override val linearId : UniqueIdentifier = UniqueIdentifier() ) : LinearState data class ParentState( val name : Party, val children : LinearPointer<ChildState>,
data class ChildState(
val name: Party,
override val linearId : UniqueIdentifier = UniqueIdentifier()
) : LinearState
data class ParentState(
val name : Party,
val children : LinearPointer<ChildState>,
override val linearId : UniqueIdentifier = UniqueIdentifier()
) : LinearState
数据类子状态(
val名称:党,
重写val linearId:UniqueIdentifier=UniqueIdentifier()
):LinearState
数据类ParentState(
val名称:党,
val儿童:LinearPointer,
重写val linearId:UniqueIdentifier=UniqueIdentifier()
):LinearState
我是否可以像建议的那样,使用CordaRPCOps从模块外部获取仅查询父级的子状态?像这样的事情:
// rpc.proxy is a NodeRPCConnection containing the CordaRPCOps
val parentStateData = rpc.proxy.vaultQueryBy<ParentState>().states.single().state.data
// perhaps something like this?
parentStateData.children.resolve(rpc.proxy)
//rpc.proxy是一个包含CordaRPCOps的NodeRPCConnection
val parentStateData=rpc.proxy.vaultQueryBy().states.single().state.data
//也许是这样的?
parentStateData.children.resolve(rpc.proxy)
Corda中的StatePointer
的默认实现不支持使用CordaRPCOps
解析指针。只能使用ServiceHub
或LedgerTransation
解决此问题。下面是Corda中的StatePointer
类中定义的方法
/**
* Resolves a [StatePointer] to a [StateAndRef] via a vault query. This method will either return a [StateAndRef]
* or return an exception.
*
* @param services a [ServiceHub] implementation is required to resolve the pointer.
*/
@DeleteForDJVM
abstract fun resolve(services: ServiceHub): StateAndRef<T>
/**
* Resolves a [StatePointer] to a [StateAndRef] from inside a [LedgerTransaction]. The intuition here is that all
* of the pointed-to states will be included in the transaction as reference states.
*
* @param ltx the [LedgerTransaction] containing the [pointer] and pointed-to states.
*/
abstract fun resolve(ltx: LedgerTransaction): StateAndRef<T>
/**
*通过vault查询将[StatePointer]解析为[StateAndRef]。此方法将返回[StateAndRef]
*或者返回一个异常。
*
*@param services解析指针需要[ServiceHub]实现。
*/
@DeleteForDJVM
抽象趣味解析(服务:ServiceHub):StateAndRef
/**
*从[LedgerTransaction]内部将[StatePointer]解析为[StateAndRef]。这里的直觉是
*所有指向的状态将作为参考状态包含在交易中。
*
*@param ltx包含[pointer]并指向状态的[LedgerTransaction]。
*/
抽象趣味解析(ltx:LedgerTransaction):StateAndRef
rpc客户端既不能访问ServiceHub
也不能访问LedgerTransaction
,因此,为了使用CordaRPCOps
解析指针,您需要编写一个自定义实现,如您提到的中所述。感谢您的澄清。