Daniel Bedggood
Daniel Bedggood

Reputation: 55

Corda view consumed states in terminal

is there an easy way to view the consumed states in the terminal with the CordaRPCOps interface? It seems that vaultQuery returns unconsumed states by default and I can't figure out how to use vaultQueryBy or anything with the criteria.

I know that there should be consumed states because I can see them with H2

Upvotes: 4

Views: 921

Answers (2)

Joel
Joel

Reputation: 23140

As Ricky says, you'll have to provide an API or write a client to speak to your CorDapp via RPC (e.g. https://github.com/corda/cordapp-example/blob/release-V1/kotlin-source/src/main/kotlin/com/example/client/ExampleClientRPC.kt).

In theory, run vaultQueryByCriteria contractStateType: com.example.state.IOUState, criteria: { Vault.StateStatus.CONSUMED } could work. However, in vaultQueryByCriteria, the criteria parameter is of type QueryCriteria, which is an abstract class. There is no way currently in the shell to specify which concrete subclass of QueryCriteria you wish to use.

I have raised an issue here: https://github.com/corda/corda/issues/2351.

Upvotes: 0

Rickky13
Rickky13

Reputation: 431

Hi you could always write a short API to expose the states:

there is a sample for /asset in corda existing samples:

here is a code snippet api for your scenario:

@GET
@Path("asset")
@Produces(MediaType.APPLICATION_JSON)
fun getAssets(): List<StateAndRef<ContractState>> {
    val consumedCriteria = QueryCriteria.VaultQueryCriteria(Vault.StateStatus.CONSUMED)
    return services.vaultQueryBy<ContractState>(consumedCriteria).states
}

Upvotes: 2

Related Questions