vishal gawde
vishal gawde

Reputation: 168

Corda is it possible to issue and consume state in same flow

I am trying to do simple fund transfer from one account to another account using simple state. 2 Flows have been created one for issue of transfer request with cash transfer and flow created to just consumed that transaction. My question is, is it possible to transfer and consume state in one flow ?

As per my opinion transaction must be consumed after transfer but also want to show it on UI.

Corda RPCQuery allowed to bring information of unconsumed states only, if I consume above transaction, is there way to show consumed transactions last state?

Upvotes: 0

Views: 474

Answers (2)

Sagaranand
Sagaranand

Reputation: 143

  • From any flow, you need to call FinalityFlow, in order to notarize and record the transaction in individual parties' vault. So I think after the issuance (or transfer), you need to call FinalityFlow first. Only then you can use the issued state as input for the new transaction.
  • The notary is responsible for avoiding the double spend of the input state in any transaction. So you can not use any newly issued state (as input to new transaction), until the notary is aware of it.
  • Thus I think in your case, you will need to call FinalityFlow twice, once after each transaction (i.e. issuance & consumption).

Upvotes: 0

Joel
Joel

Reputation: 23210

CordaRPCOps allows you to query for unconsumed states, consumed states, or both. Here's a simple way of querying for all states:

val criteria = QueryCriteria.VaultQueryCriteria(Vault.StateStatus.ALL)
val results = proxy.vaultQueryBy<ContractState>(criteria)

To show the last consumed state, you could retrieve all the consumed states in descending order of consumption and grab the first one, as follows:

val criteria = QueryCriteria.VaultQueryCriteria(Vault.StateStatus.UNCONSUMED)
val sortColumn = Sort.SortColumn(SortAttribute.Standard(Sort.VaultStateAttribute.CONSUMED_TIME), Sort.Direction.DESC)
val sorting = Sort(listOf(sortColumn))
val results = proxy.vaultQueryBy<Obligation>(criteria, sorting = sorting)
val lastConsumedState = results.states[0]

Upvotes: 1

Related Questions