This repository is cloned for recording developer's personal learning curves and solution.
There are two organizations namely Magnetocorp & Digibank and two individuals both representing respective organizations namely Isabella & Balaji.
Roles:-
- Magnetocorp - CP holder
- Digibank - CP underwriter
- Isabella - Magnetocorp representative and admin for Magnetocorp (issuer).
- Balaji - Digibank representative and admin for Digibank for CP (buyer/redeem).
- Start the fabric-test network by going inside test-network/ and run
./network-starter.sh
- Navigate inside
./configuration/cli/
and runmonitordocker.sh
. Parameter <network_name> can also be supplied to monitor specific network otherwise all docker networks will be monitored and this terminal will be used to monitor all transactional and debug logs.
In general there are severals variable paths have to be set in order to prepare the organizations. An organization requires:
PATH=
set to/bin
FABRIC_CFG_PATH=
set to/config
CORE_PEER_TLS_ENABLED=
set totrue
CORE_PEER_LOCALMSPID=
set to organization MSPCORE_PEER_TLS_ROOTCERT_FILE=
set to the location of certificate authority .crt fileCORE_PEER_MSPCONFIGPATH=
set touser/OrgAdmin/msp
folderCORE_PEER_ADDRESS=
set to organizationaddress:port
In this demo, run the script to source all the relevant paths.
source magnetocorp.sh
The chaincode has to be packaged before being installed.
peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0
peer lifecycle chaincode install cp.tar.gz
peer lifecycle chaincode queryinstalled
Set the PACKAGE_ID=
to the package ID that was just installed.
Depending on thee business logics, the smart contract will be required to be approved by both or singular organization(s)
peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name papercontract -v 0 --package-id $PACKAGE_ID --sequence 1 --tls --cafile $ORDERER_CA
The process of generating, installing, sourcing of chaincode will be the same for Digibank.
source digibank.sh
peer lifecycle chaincode install cp.tar.g
export PACKAGE_ID=
peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name papercontract -v 0 --package-id $PACKAGE_ID --sequence 1 --tls --cafile $ORDERER_CA
Now that both organizations has approved the contract, Digibank will proceed to commit the chaincode into the network.
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --peerAddresses localhost:7051 --tlsRootCertFiles ${PEER0_ORG1_CA} --peerAddresses localhost:9051 --tlsRootCertFiles ${PEER0_ORG2_CA} --channelID mychannel --name papercontract -v 0 --sequence 1 --tls --cafile $ORDERER_CA --waitForEvent
Once the smart contract has been configured and deployed into the network, a representative / admin will be assigned to conduct the issuance process. This will be done on behalf of Magnetocorp.
Nonetheless, I think in real world the issuance of corporate bond is usually done by the financial institution once both parties has agreed on the contract terms.
Anyways..
As Isabella has been appointed to conduct the issuance, she will first need to generate an identity / credential and stored it inside her wallet. The scripts are provided inside application/
of each organization.
Since the process of enrolling, creating and storing wallet and identity for her is written in Javascript, hence an installation of required dependencies will be required. For that, runs:
npm install && npm audit fix
Then Isabella is now ready to be enrolled as the issuer of the CP here.
./enrollUser.js
Isabella now have her own credential / identity which is now stored inside her wallet.
/magnetocorp/user/isabella/wallet
inside the file isabella.id
Now Isabella can issue to commercial paper.
node issue.js
The details of the issuance such as bond face value etc should be displayed.
Come to the role of Balaji as the buyer of bond, he will buy the bond subsequently redeem the bond and end the lifecycle of the contract. So navigate into digibank/application
directory and install the NodeJS dependencies (if haven't), and run:
node enrolluser.js
Just like Isabella, Balaji is now has been enrolled as the representative to buy the bond. To buy the bond run:
node buy.js
Finally, the final lifecyle of the CP is by redemption of the CP itself. For that, runs:
node redeem.js
The lifecycle of the bond is now ended.
navigate back to /commercial-paper
and run
./network-cleaner.sh