ygnr
ygnr

Reputation: 115

Query for an input state that has been consumed in the transaction

Let say, I have defined two states StateA and StateB and executed the following actions.

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

Answers (1)

Joel
Joel

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:

  1. Query the vault for the current unconsumed StateB

    val stateBStateAndRef = serviceHub.vaultService.queryBy<StateB>().states.single()
    
  2. Use the StateRef of the retrieved state to load the corresponding transaction

    val stateBTransaction = serviceHub.validatedTransactions.getTransaction(stateBStateAndRef.ref.txhash)!!
    
  3. Load the states corresponding to the inputs of the loaded transaction

    val consumedInputs = stateBTransaction.inputs.map { stateRef -> serviceHub.loadState(stateRef) }
    

Upvotes: 2

Related Questions