'How to display the states on Corda terminal
I am new to Corda and am designing a Cordap. I want to display the states onto the terminal based on some arguments passed during initiating the flow. My approach was I created a List of type StateAndRef storing all the states. Now I loop through the list and display the state based on if else condition.
But the issue I am facing is somethimes all the states the printed and sometimes only few of them are printed. Please help me to solve this problem. My main motive is I should be able to display on the screen those states which have name Car.
PS: I am using Java for designing the Cordapp.
Solution 1:[1]
You don't really need a flow to display states. You con using vaultQuery to do so:
run vaultQuery contractStateType: <fully-qualified name of the state type>
Refer documentation here for: https://docs.corda.net/docs/corda-os/4.4/shell.html#examples
In case you want to do complex querying, it's not supported in the CRaSH shell. However, you could do so in the RPC Client using the vault Query API. The VaultQuery API is very flexible and provide a number of mechanisms to access the vault.
Check the documentation here: https://docs.corda.net/docs/corda-os/4.4/api-vault-query.html#api-vault-query
Solution 2:[2]
As Ashutosh has already mentioned, complex querying doesn't seem to be supported yet. However a way to accomplish querying a subset of all states would be to create another class for those states.
For Ex - CARState for the subset you want to query on and the other states can be CAR2State, and then just use the
run vaultQuery contractStateType: com.template.CARState
Im not sure if this helps since I don't know for what reasons you want to use arguments passed in the flow. But the RPC client is the way to achieve complex queries, unfortunately that is not covered in my course on Udemy.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ashutosh Meher |
Solution 2 | Tejus Kabadi |