Reputation: 115
Let say, I have defined two states StateA
and StateB
and executed the following actions.
StateA
with no inputs. (NoInput -> StateA-sa1
)StateA
. (StateA-sa1
-> StateA-sa2
)StateB
with unconsumed StateA
as input. (StateA-sa2
-> StateB-sb1
)Is it possible to construct a single query to get current unconsumed StateB
(StateB-sb1
) and inputs(StateA-sa2
) that went into creating this state?
Upvotes: 0
Views: 238
Reputation: 23140
As of Corda 3.1, no. It's not possible to achieve this with a single query. You actually need to perform three steps:
Query the vault for the current unconsumed StateB
val stateBStateAndRef = serviceHub.vaultService.queryBy<StateB>().states.single()
Use the StateRef
of the retrieved state to load the corresponding transaction
val stateBTransaction = serviceHub.validatedTransactions.getTransaction(stateBStateAndRef.ref.txhash)!!
Load the states corresponding to the inputs of the loaded transaction
val consumedInputs = stateBTransaction.inputs.map { stateRef -> serviceHub.loadState(stateRef) }
Upvotes: 2