|
| 1 | +<p align="center"> |
| 2 | + <img src="https://www.corda.net/wp-content/uploads/2016/11/fg005_corda_b.png" alt="Corda" width="500"> |
| 3 | +</p> |
| 4 | + |
| 5 | +# State Reissuance Sample CorDapp |
| 6 | + |
| 7 | +This cordapp serves as a sample for state reissuance feature of Corda. This feature enables developers to break long |
| 8 | +transaction backchains by reissuing a state with a guaranteed state replacement. This is particularly useful in situations |
| 9 | +when an party doesn't want to share state history with other parties for privacy or performance concerns. |
| 10 | + |
| 11 | +This samples demonstrates the feature with the help of a linear state, represented by a land title issued on Corda ledger. |
| 12 | +The land title can be transferred multiple times and when the transaction backchain becomes long, the land title could be |
| 13 | +reissued and the transaction backchain could be pruned. |
| 14 | + |
| 15 | +# Pre-Requisites |
| 16 | + |
| 17 | +See https://docs.corda.net/getting-set-up.html. |
| 18 | + |
| 19 | +# Usage |
| 20 | + |
| 21 | +## Running the CorDapp |
| 22 | + |
| 23 | +Open a terminal and go to the project root directory and type: (to deploy the nodes using bootstrapper) |
| 24 | + |
| 25 | +`./gradlew clean deployNodes` |
| 26 | + |
| 27 | +Then type: (to run the nodes) |
| 28 | + |
| 29 | +`./build/nodes/runnodes` |
| 30 | + |
| 31 | +## Interacting with the CorDapp |
| 32 | + |
| 33 | +PartyA issues a land title to PartyB, Go to PartyA's terminal and run the below command |
| 34 | + |
| 35 | +`start IssueLandTitleFlow owner: PartyB, dimensions: 40X50, area: 1200sqft` |
| 36 | + |
| 37 | +Verify the land title has been issued correctly by querying the ledgers of PartyA and PartyB using the below command. |
| 38 | +PartyA should be issuer and PartyB should be the owner of the land title. |
| 39 | + |
| 40 | +`run vaultQuery contractStateType: net.corda.samples.statereissuance.states.LandTitleState` |
| 41 | + |
| 42 | +Once land title has been issued to PartyB, he could transfer it to PartyC. Go to PartyB's terminal and run the below command |
| 43 | + |
| 44 | +`start TransferLandTitleFlow owner: PartyC, plotIdentifier: <plot-identifier>` |
| 45 | + |
| 46 | +You could find the `plot-identifier` from the result of the vaultQuery command used earlier to query the ledgers. |
| 47 | + |
| 48 | +Verify the land title has been correctly tranferred to PartyC by querying the ledgers of PartyA and PartyC using the below command |
| 49 | + |
| 50 | +`run vaultQuery contractStateType: net.corda.samples.statereissuance.states.LandTitleState` |
| 51 | + |
| 52 | +Note that PartyB is no more able to see the land title, since he is no longer a party to the state as he has transferred |
| 53 | +the title to PartyC. It is currently only visible to PartyA and PartyC. |
| 54 | + |
| 55 | +Consider that PartyC now wants to reissue the title to get rid of the backchain. He needs to request a reissuace to the issuer. |
| 56 | +Go to PartyA's terminal and run the below command |
| 57 | + |
| 58 | +`start RequestReissueLandStateFlow issuer: PartyA, plotIdentifier: <plot-identifier>` |
| 59 | + |
| 60 | +Now a reissuance request is created on the ledgers of PartyA and PartyC, when can be verified using the below command |
| 61 | + |
| 62 | +`run vaultQuery contractStateType: com.r3.corda.lib.reissuance.states.ReissuanceRequest` |
| 63 | + |
| 64 | +The issuer could either accept or reject the reissuance request. Let's consider the case where the issuer accepts the |
| 65 | +reissuance request. To accept the request goto PartyA's (issuer) terminal and run the below command |
| 66 | + |
| 67 | +`start AcceptLandReissuanceFlow issuer: PartyA, stateRef: {index: <output-index>, txhash: <trnx-hash>}` |
| 68 | + |
| 69 | +The `<output-index>` and `<trnx-hash>` are of the transaction which created the state to the reissued. They can be found |
| 70 | +in the `ReissuanceRequest` queried earlier. |
| 71 | + |
| 72 | +On successful completion of the above flow, the a duplicate land title would be issued, however it would be currently |
| 73 | +locked and it could not be spend. In order to spend it, the older state which was requested to be reissued must be exited |
| 74 | +and that would allow the new reissued state to be unlocked and spend. |
| 75 | + |
| 76 | +To exit the older land title run the below command from PartyC's terminal. |
| 77 | + |
| 78 | +`start ExitLandTitleFlow stateRef: {index: <output-index>, txhash: <trnx-hash>}` |
| 79 | + |
| 80 | +Once the previous land title is exited, unlock the reissued land title using the below command from PartyC's terminal |
| 81 | + |
| 82 | +`start UnlockReissuedLandStateFlow reissuedRef: {index: <output-index>, txhash: <tx-hash>}, reissuanceLockRef: {index: <output-index>, txhash: <tx-hash>}, exitTrnxId: <tx-hash>` |
| 83 | + |
| 84 | +The `reissuedRef` is the stateRef of the reissued state, `reissuanceLockRef` is the stateRef of the reissuance lock generated, |
| 85 | +which can queried usinf `run vaultQuery contractStateType: com.r3.corda.lib.reissuance.states.ReissuanceLock` and `exitTrnxId` is the |
| 86 | +transaction hash of the transaction used to exit the older state. |
| 87 | + |
| 88 | +Note that the lock uses the encumbrance feature of Corda. You can check out the sample on encumbrance [here](https://github.com/corda/samples-java/tree/master/Features/encumbrance-avatar) |
| 89 | + |
| 90 | +Now the reissue process is completed and the reissued state can be spent freely. |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
0 commit comments