0 votes
1 view
in Blockchain by (12.8k points)

I have a sample loan use case, where I have two states:

  • Invoice State, and
  • Loan State.

Loan State is created by passing Invoice State as input.

enter image description here

Now as Corda follows UTXO model, when I do the default vault query, the Invoice state is not showed as it's consumed now.

To solve this, there are two possible ways:

  1. Either, I query on all states i.e consumed and unconsumed.
  2. Or, I can maintain a status at Invoice state and mark the status to something as Invoice paid after consuming it to create Loan State (So this is more like evolving state, something like bitcoin where balance is always getting transferred.). Something like this:

enter image description here

Can anybody please recommend what would be the correct architecture decision?

1 Answer

0 votes
by (29.8k points)

Hi, I think you should consiuder the following changes

Your Invoice should have a 'state' field with and enum of at least 'UNPAID' and 'PAID' Your 'payInvoice' command should have the following inputs and outputs: inputs: Invoice - state=UNPAID outputs Invoice - state=PAID Loan

The verify function should check that the inputs and outputs for this command are as above. After which the 'UNPAID' invoice state is spent and cannot be used again. I hope that makes sense.

Check out the 'MeteringInvoiceCommands.Pay' method in the following code. This is similar to what you need, but in this case, it is checking that a payment is produced as well as the input state is 'ISSUED' and output state is 'PAID'

https://gitlab.com/cordite/cordite/blob/master/cordapps/metering-contracts-states/src/main/kotlin/io/cordite/metering/contract/MeteringInvoiceContract.kt

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...