This CorDapp creates Delivery-vs-Payment atomic transaction for on ledger Asset
transfer for Cash
with three participants.
CorDapp Nodes:
- Security Seller: This party is owner of
Asset
state of typeOwnableState
on ledger. He sells these assets for cash by creating Corda transaction. - Security Buyer: This party has some
Cash
tokens on his ledger. He purchasesAsset
securities for Cash. - Clearing House: coordinates
Seller
andBuyer
parties to process the settlement transaction. It initiate settlement ofAsset
transfer request and collect the required states (i.e. Asset and Cash) from counterparties (i.e. Seller and Buyer) in-order to complete the transaction. - Notary: notary node to check double-spend of input states then verify and sign final transaction.
This CorDapp example business-logic flows as below:
-
- The
Seller
party creates theAsset
state of typeOwnableState
on ledger.
- The
-
- Create
AssetTransfer
state and share it withBuyer
party who willing to buy theAsset
.
- Create
-
- The
Buyer
party review and accept theAssetTransfer
transaction and further share this state withClearingHouse
party.
- The
-
- The
ClearingHouse
party - offline review and validate theAsset
data received along withAssetTransfer
state. If everything is good, he initiate theAssetSettlementInitiatorFlow
flow to create the settlement transaction with three participants. On completion of settlement transactionBuyer
party became owner ofAsset
state and issuesCash
tokens equals to the amount ofAsset.purchaseCost
toSeller
party on ledger.
- The
Use relevant node's Shell console to initiate the flows.
Let's start flows from each Corda node's shell console step-by-step:
1. To create Asset
- run below command on SecuritySeller
node's console:
flow start com.botkul.cordapp.seller.flows.CreateAssetStateFlow$Initiator cusip: "CUSIP222", assetName: "US Bond", purchaseCost: $10000
To see state created run below command:
run vaultQuery contractStateType: com.botkul.cordapp.state.Asset
Now we have on ledger asset of type OwnableState and ready to sell it to other party on network.
2. To create AssetTransfer
- run below command again on SecuritySeller
node's console:
flow start com.botkul.cordapp.seller.flows.CreateAssetTransferRequestInitiatorFlow cusip: "CUSIP222", securityBuyer: "O=SecurityBuyer,L=New York,C=US"
To see AssetTransfer
state created run below command again:
run vaultQuery contractStateType: com.botkul.cordapp.state.AssetTransfer
You can see the AssetTransfer state data and copy the linearId.id
field value of it and save it with you as we required it in next step.
3. The Buyer
party confirm AssetTransfer
request received by running below command on counterparty SecurityBuyer
node's console:
flow start com.botkul.cordapp.buyer.flows.ConfirmAssetTransferRequestInitiatorFlow linearId: "<Replace with AssetTransfer.linearId.id>", clearingHouse: "O=ClearingHouse,L=New York,C=US"
This flow update the AssetTransfer.status
value to PENDING
from it's initial value PENDING_CONFIRMATION
.
4. The Buyer
party self-issue the Cash
tokens on ledger using:
flow start net.corda.finance.flows.CashIssueFlow amount: $20000, issuerBankPartyRef: 1234, notary: "O=Notary,L=New York,C=US"
To see the issued cash balance run:
run vaultQuery contractStateType: net.corda.finance.contracts.asset.Cash$State
5. Run below command on the ClearingHouse
party node's console to create settlement transaction and distribute to three participants:
flow start com.botkul.cordapp.clearinghouse.flows.AssetSettlementInitiatorFlow linearId: "<Replace with AssetTransfer.linearId.id>"
On successful completion of flows the AssetTransfer.status
field value became TRANSFERRED
. Now you can cross-check the available Asset
and Cash
states on each counterparty corda node.