Можно ли разрешить указатель из CordaRPCOps? - PullRequest
0 голосов
/ 06 марта 2020

Рассмотрим следующее:

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

Могу ли я как-то, как этот пост Мэтью Литона , кажется, предложить, получить дочернее состояние, запрашивая только родителя снаружи модуля, используя 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)

1 Ответ

0 голосов
/ 09 марта 2020

Реализация по умолчанию StatePointer в Corda не поддерживает разрешение указателя с использованием CordaRPCOps. Это может быть решено только с помощью ServiceHub или LedgerTransation. Ниже приведены методы, определенные в классе StatePointer в Corda.

/**
 * 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>

Ни ServiceHub, ни LedgerTransaction не доступны в клиенте rp c, следовательно, для разрешения указателя используя CordaRPCOps, вам нужно написать собственную реализацию, как описано в блоге , который вы упомянули.

...