问题
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
回答1:
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
}
回答2:
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.
来源:https://stackoverflow.com/questions/48195934/corda-view-consumed-states-in-terminal