Skip to content

Blueprint/Boilerplate For Golang Smart-Contract Hyperledger Projects

License

Notifications You must be signed in to change notification settings

janrockdev/simple-contract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blueprint/Boilerplate For Golang Smart-Contract Hyperledger Projects

Version: 1.1

Hyperledger deployment:

Run all from path: ~/fabric-samples/test-network:

# export PATH=/home/janrock/fabric-samples/bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:7051

(Second organisation)

# export PATH=/home/janrock/fabric-samples/bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:9051

Arguments: (TId, CId, TTs generated)

id (example: "7")
timestamp (example: "1623747164")
instrument (example: "XAU_USD")
size (example: "1.1")
side (example: "LONG")
price (example: "1900.4")
tp (example: "1930.4")
sl (example: "1890.4")

Create channel:

./network.sh up createChannel -c uni

Deploy chaincode(smart-contact) to channel:

sudo ./network.sh deployCC -ccn ob -ccp ../asset-transfer-basic/chaincode-ob -ccl go -c uni

Initialise Assets:

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C uni -n ob --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}'

Create Asset:

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C uni -n ob --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"CreateAsset","Args":["7","2000000000","XAU_USD","6.1","LONG","1900.4","1901","1899"]}'

Check Assets:

peer chaincode query -C uni -n ob -c '{"Args":["GetAllAssets"]}'

Search Asset (ID, first parameter of the struct):

peer chaincode query -C uni -n ob -c '{"Args":["ReadAsset","1"]}'

Delete Asset:

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C uni -n ob --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"DeleteAsset","Args":["7"]}'

Remove channel:

./network.sh down

About

Blueprint/Boilerplate For Golang Smart-Contract Hyperledger Projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages