This CorDapp allows a node to create and issue an apple stamp to another node. Example use of an apple stamp: "One stamp can be exchanged for a basket of Honey Crisp Apples".
AppleStamp: This is a LinearState that represents an Apple Stamp that can be issued by one party (issuer) to another party (holder).BasketOfApples: This state represents a specific basket of apples (description of the brand/type, farm, owner, and weight). To change ownership of this basket of apples, thechangeOwnerfunction can be used.
AppleStampContract: This is used to govern the evolution of anAppleStampstate. This file includes validation rules governing theIssuecommand forAppleStamp.BasketOfApplesContract: This is used to govern the evolution of anBasketOfApplesstate. This file includes validation rules governing thepackBacketand theRedeemcommand for aBasketOfApples.
CreateAndIssueAppleStampInitiatorandCreateAndIssueAppleStampResponderflows are used to create and issue anAppleStampstate. It takes 2 arguments as the parameters: thestampDescription(String) and theholder(Party).PackApplesInitiatorflow is used to create aBasketOfApplesstate in the initiating node's vault. It takes 2 arguments as the parameters: theappleDescription(String) and theweight(Int).RedeemApplesInitiatorandRedeemApplesResponderflows are used to redeem aBasketOfApplesagainst anAppleStamp. It takes 2 arguments as the parameters: thebuyer(Party) and thestampId(UniqueIdentifier).
For development environment setup, please refer to: Setup Guide.
Open a terminal and go to the project root directory and type: (to deploy the nodes using bootstrapper)
./gradlew clean build deployNodes
Then type: (to run the nodes)
./build/nodes/runnodes
This should open up 3 new tabs in the terminal window with Corda interactive shells.
One for the Notary, one for Peter, and one for Apple Farm.
(If any of the nodes is missing a Corda interactive shell, from the root folder, navigate to ./build/node/{missing party node} and run java -jar corda.jar to boot up the Corda interactive shell manually.)
- Navigate to Apple Farm's Corda Interactive Shell and type the following command:
flow start CreateAndIssueAppleStampInitiator stampDescription: "FujiApples", holder: Peter
Apple Farm has now created and issued an Apple Stamp that is redeemable against a basket of fuji apples to Peter.
- Next, in Apple Farm's Corda Interactive Shell, type the following command:
flow start PackApplesInitiator appleDescription: "FujiApples", weight: 5
Apple Farm has now packed one basket of fuji apples.
- To check that this
BasketOfApplesstate has been successfully stored in Apple Farm's vault, in Apple Farm's Corda Interactive Shell, type the following command:
run vaultQuery contractStateType: com.tutorial.states.BasketOfApples
The output should be the BasketOfApples state that you have just created.
- If you type the same command into Peter's Corda Interactive Shell, it shouldn't be there as he is not the owner of this state (yet). In order to make him the owner of this basket of fuji apples, he will need to redeem it using his
AppleStamp. To find out the unique identifier of theAppleStamptype the following command into Peter's Corda Interactive Shell:
run vaultQuery contractStateType: com.tutorial.states.AppleStamp
From the output, copy the value of id in linearId field.
- Navigate to Apple Farm's Corda Interactive Shell and type in the following command:
flow start RedeemApplesInitiator buyer: Peter, stampId: {paste the copied linearID here}
Upon completion of the flow, you should see the output Flow completed with result: SignedTransaction(id=XXXXXXX).
Now Peter has successfully redeemed his AppleStamp against a BasketOfApples, we can double-check to make sure that this BasketOfApples is stored in his vault.
- In Peter's Corda Interactive Shell, type:
run vaultQuery contractStateType: com.tutorial.states.BasketOfApples
You should now be able to see the respective BasketOfApples in Peter's vault.