Git Product home page Git Product logo

aws-mbc-client's Introduction

AWS Managed Blockchain Client Implementation

Setup an AWS Managed Blockchain Service

Provide configuration details of AWS Blockchan Network on asset-fabric/cli/fabric-network.sh

Execute following command to make all scripts executable

find ~/aws-mbc-client/ -type f -iname "*.sh" -exec chmod +x {} \;

Export Network Configurations

cd ~/aws-mbc-client/asset-fabric
./start.sh

Perform Channel Deployment

Set Fabric Configurations

source ~/aws-mbc-client/asset-fabric/cli/fabric-network.sh

Ensure Configurations Specific to Org1

export CHANNEL=mychannel
export PEER=$PEERSERVICEENDPOINT
export MSP_PATH=/opt/home/admin-msp
export MSP=$MEMBERID

Ensure Configurations Specific to Org2

export CHANNEL=mychannel
export PEER=$PEERSERVICEENDPOINTORG2
export MSP_PATH=/opt/home/admin-msp
export MSP=$MEMBERIDORG2

Creating channel

docker exec cli configtxgen -outputCreateChannelTx /opt/home/$CHANNEL.pb -profile TwoOrgChannel -channelID $CHANNEL --configPath /opt/home/

ls -lt ~/$CHANNEL.pb 

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" -e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" cli peer channel create -c $CHANNEL -f /opt/home/$CHANNEL.pb -o $ORDERER --cafile /opt/home/managedblockchain-tls-chain.pem --tls --timeout 900s

ls -lt /opt/home/

Fetching channel config

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem"  \
    -e "CORE_PEER_ADDRESS=$PEER"  -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
    cli peer channel fetch oldest /opt/home/$CHANNEL.block \
    -c $CHANNEL -o $ORDERER --cafile /opt/home/managedblockchain-tls-chain.pem --tls

Joining the channel Org1 & Org2

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
    -e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
    cli peer channel join -b /opt/home/$CHANNEL.block  -o $ORDERER --cafile /opt/home/managedblockchain-tls-chain.pem --tls

mkdir /home/ec2-user/fabric-samples/chaincode/asset

cp ~/aws-mbc-client/asset-smartcontract/src/* /home/ec2-user/fabric-samples/chaincode/asset/

Installing the Sample chaincode

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
    -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" -e "CORE_PEER_ADDRESS=$PEER"  \
    cli peer chaincode install -n mtransfer -v v0 -p github.com/chaincode_example02/go

Instantiating the sample chaincode

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
    -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" -e "CORE_PEER_ADDRESS=$PEER"  \
    cli peer chaincode instantiate -o $ORDERER -C $CHANNEL -n mtransfer -v v0 -c '{"Args":["init","a","100","b","200"]}' --cafile /opt/home/managedblockchain-tls-chain.pem --tls -P "AND ('$MEMBERID.member', '$MEMBERIDORG2.member')"

Querying the sample chaincode

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
    -e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
    cli peer chaincode query -C $CHANNEL -n mtransfer -c '{"Args":["query","a"]}'

Installing the asset chaincode

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
    -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" -e "CORE_PEER_ADDRESS=$PEER"  \
    cli peer chaincode install -n $CHAINCODENAME -l node -v v1 -p $CHAINCODEDIR

Instantiating the asset chaincode

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
    -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" -e "CORE_PEER_ADDRESS=$PEER"  \
    cli peer chaincode upgrade -o $ORDERER -C $CHANNEL -n $CHAINCODENAME -v v1 -c '{"Args":["init"]}' --cafile /opt/home/managedblockchain-tls-chain.pem --tls -P "AND ('$MEMBERID.member', '$MEMBERIDORG2.member')"

Querying the asset chaincode

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
    -e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
    cli peer chaincode query -C $CHANNEL -n $CHAINCODENAME -c '{"Args":["queryAllAssets"]}'

Invoking transactions on sample chaincode

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
    -e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
    cli peer chaincode invoke -o $ORDERER -C $CHANNEL -n mtransfer \
    -c '{"Args":["invoke","a","b","10"]}' --peerAddresses $PEERSERVICEENDPOINT --tlsRootCertFiles /opt/home/managedblockchain-tls-chain.pem --peerAddresses $PEERSERVICEENDPOINTORG2 --tlsRootCertFiles /opt/home/managedblockchain-tls-chain.pem --peerAddresses $PEERSERVICEENDPOINT --tlsRootCertFiles /opt/home/managedblockchain-tls-chain.pem --cafile /opt/home/managedblockchain-tls-chain.pem --tls

Invoking transactions on asset chaincode

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" -e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" cli peer chaincode invoke -o $ORDERER -C $CHANNEL -n $CHAINCODENAME -c '{"Args":["createAsset","{\"assetOwnerName\":\"Rohit\", \"email\":\"[email protected]\",\"assetName\": \"CAR 201\",\"assetId\": \"CAR201\",     \"assetType\": \"car\",\"docType\":\"asset\",\"registeredDate\":\"2020-09-09T11:52:20.182Z\"}"]}' --peerAddresses $PEERSERVICEENDPOINT --tlsRootCertFiles /opt/home/managedblockchain-tls-chain.pem --peerAddresses $PEERSERVICEENDPOINTORG2 --tlsRootCertFiles /opt/home/managedblockchain-tls-chain.pem --peerAddresses $PEERSERVICEENDPOINT --tlsRootCertFiles /opt/home/managedblockchain-tls-chain.pem --cafile /opt/home/managedblockchain-tls-chain.pem --tls

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
    -e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
    cli peer chaincode invoke -o $ORDERER -C $CHANNEL -n $CHAINCODENAME \
    -c '{"Args":["createAsset","{\"assetOwnerName\":\"Ravi\", \"email\":\"[email protected]\",\"assetName\": \"CAR 202\",\"assetId\": \"CAR202\",
      \"assetType\": \"car\",\"docType\":\"asset\",\"registeredDate\":\"2020-09-09T11:52:20.182Z\"}"]}' --cafile /opt/home/managedblockchain-tls-chain.pem --tls

Querying the asset chaincode

docker exec -e "CORE_PEER_TLS_ENABLED=true" -e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
    -e "CORE_PEER_ADDRESS=$PEER" -e "CORE_PEER_LOCALMSPID=$MSP" -e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
    cli peer chaincode query -C $CHANNEL -n $CHAINCODENAME -c '{"Args":["queryAsset","{\"assetId\":\"CAR201\"}"]}'

Start REST API

cd ~/aws-mbc-client/aws-rest-api
./start.sh

Test Asset Manager APIs

Generate Connection Profile

cd ~/aws-mbc-client ./gen-connection-profile.sh

Register/enroll a user

curl -s -X POST http://localhost:3000/users -H "content-type: application/x-www-form-urlencoded" -d 'username=susmit&orgName=Org1'

Create an Asset

curl -s -X POST "http://localhost:3000/assets" -H "content-type: application/json" -d '{ 
   "assetOwnerName":"Nikhil",
   "email":"[email protected]",
   "assetName": "CAR 301",
   "assetId": "301",
   "assetType": "car",
   "registeredDate":"2018-10-22T11:52:20.182Z"
}'

Fetch All Assets

curl -s -X GET   "http://localhost:3000/assets" -H "content-type: application/json"

aws-mbc-client's People

Contributors

susmitsil avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.