diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/MAINTAINERS.md b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/MAINTAINERS.md new file mode 100644 index 0000000..042feef --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/MAINTAINERS.md @@ -0,0 +1,5 @@ +# Overall repo +For the overall repo, the committers are @hyperledger/learning-materials-dev-committers . In case it's necessary to be a member of the hyperledger GitHub organization to access that alias and you are not a member, you can reach out to the individuals: At this time, they are GitHub users tkuhrt, nathalie-ckc, bobbi28, ravinayag + +# Individual projects +1, Fabric-samples-BYFN-EYFN-Explained - ravinayag@gmail.com diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/README.md b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/README.md new file mode 100644 index 0000000..0856815 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/README.md @@ -0,0 +1,536 @@ +# Audience: Newcommers, Hyperledger Network Admins. + +## Learn Hyplerledger fabric with default samples ( BYFN/EYFN) +## A) Explained in detail of the [fabric-samples/firstnetwork/byfn.sh] script. How the fabric network was organised with 2 orgs, 2 peers with Solo Orderer. +## B) Followed by org3 addition [fabric-samples/firstnetwork/eyfn.sh] script. +##### source contributor https://github.com/ravinayag/fabric-samples-explained/blob/master/README.md + +Here is the Network Diagram for the fabric ![Network diagram](https://github.com/ravinayag/fabric-samples-explained/blob/master/network.png) + +Ensure all prerequesties are completed,if not refer this +* 1, Phy/Virtual Machine : Running Ubuntu OS 16.4 LTS +* 2, [Pre_req_script](https://github.com/ravinayag/Hyperledger/raw/master/prereqs_hlfv14.sh) for ref. (Installs : Docker, Docker-composer,Npm, node, python, ca-certs and sudo access.) +* 3, [Download_script](https://github.com/ravinayag/Hyperledger/raw/master/download_hlf.sh) for ref. (Installs : Fabric-samples, binaries, docker images ) + +*Note 1: This Will download Fabric-samples binaries in current folder and docker images. +I have run this script from my homefolder ex: /home/ravinayag and Fabric-samples folder will be created here.* + + + +*Note 2 : The Recent Fabric samples masters(>1.4.3), chaincode_example02 is not availble. Hence i update this folder here. you have to copy this folder under fabric-samples/chaincode folder.* + +#### Check List for prereq readiness : +* 1, Docker, Docker-composer,Npm, node, python, ca-certs and sudo access. +* 2, Fabric-samples, binaries, docker images + +##### Do not proceed further if above pre req not completed. If you have issues, Please raise your hands over hyperledger chat or weekly call + +#### Lets begin to dirt our hands. + +### 1, Clone/download this repo and name it as "newnet" under fabric-samples folder and move as your working directory. + + +``` +~newnet$ mv +yourhomepath/fabric-samples/fabric-samples-explaind yourhomepath/fabric-samples/newnet + +``` + +## Stage -1 +#### 3, Now set the environment variables by running script which generates genisis block and run the docker contiainer + +``` + $ source ./scripts/1_envsetup.sh +``` +#### OR + +TechTip1 : Your Syschannel name should be different from the public channel name. Syschannel name is used to create Genesis block. +``` + +export PATH=${PWD}/../bin:${PWD}:$PATH +export FABRIC_CFG_PATH=${PWD} + +export SYS_CHANNEL=syschannel +export CHANNEL_NAME=mychannel2 +export IMAGE_TAG=latest +export COMPOSE_PROJECT_NAME=newnet + + +``` + +#### 1a, Run the this script to genrate the artifacts given in crypto-config file and generate genesis block +Note: This script has to execute first time only or fresh install, If clone you no need to run unless you delete manually crypto-config & channel-artifacts folder +``` + $ ./scripts/1a_firsttimeonly.sh +``` +#### OR +``` +### Generate artifacts +rm -rf crypto-config channel-artifacts +cryptogen generate --config=./crypto-config.yaml + +### Create Sys channel for genesis block +mkdir channel-artifacts +configtxgen -profile TwoOrgsOrdererGenesis -channelID $SYS_CHANNEL -outputBlock ./channel-artifacts/genesis.block + +### create channel.tx file + +configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME + +### create Anchor peer file for Org +configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP +configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP +``` + +#### Now you can Run the docker-compose to get the network containers up +``` +$ docker-compose -f docker-compose-cli.yaml up -d +$ docker ps -a ## this will show you all 6 containers up and running. ( orderer, 2 peers on each org's (2 org) and cli) +Note : If you have errors at this stage(dockers not up), then delete crypto-config folder and run script/1a_firsttimeonly.sh file + +``` + +#### 2, Create channel with script + +``` + $ ./scripts/2_chanlCrt.sh +``` +#### OR +``` +export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +export CHANNEL_NAME=mychannel2 +export CORE_PEER_TLS_ENABLED=true + +docker exec cli peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_TLS_ENABLED --cafile $ORDERER_CA +``` + + + + +#### 2a, Now join the peers to the channel one by one + + +``` +######### First peer0 of Org1 ######## + +newnet $ docker exec cli sh ./scripts/2a_peer0.org1_chljoin.sh +``` +OR + +``` +$ docker exec -it cli bash ### you get the root prompt for cli contianer and execute all commands from here. + +set -x +CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +CORE_PEER_LOCALMSPID=Org1MSP +CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +CORE_PEER_TLS_ENABLED=true +CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +CORE_PEER_ID=cli +CORE_PEER_ADDRESS=peer0.org1.example.com:7051 +CHANNEL_NAME=mychannel2 +peer channel join -b $CHANNEL_NAME.block +``` + + +#### 3, Now join the second peer of org1 to the channel +######### Second, peer1 of Org1 ######## +``` +newnet$ docker exec cli sh ./scripts/3_peer1.org1_chljoin.sh +``` +OR + +``` +$ docker exec -it cli bash ### you get the root prompt for contianer +set -x +CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +CORE_PEER_LOCALMSPID=Org1MSP +CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +CORE_PEER_TLS_ENABLED=true +CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +CORE_PEER_ID=cli +CORE_PEER_ADDRESS=peer1.org1.example.com:8051 +CHANNEL_NAME=mychannel2 +peer channel join -b $CHANNEL_NAME.block +``` + +#### 4, Now join the first peer of org2 to the channel +######### First peer of Org2 ########## +``` +$ docker exec cli sh ./scripts/4_peer0.org2_chljoin.sh +``` +OR +``` +set -x +CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +CORE_PEER_LOCALMSPID=Org2MSP +CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +CORE_PEER_TLS_ENABLED=true +CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +CORE_PEER_ID=cli +CORE_PEER_ADDRESS=peer0.org2.example.com:9051 +CHANNEL_NAME=mychannel2 +peer channel join -b $CHANNEL_NAME.block +``` + +#### 5, Now join the seond peer of org2 to the channel +######### Second peer of Org2 ########## +``` +$ docker exec cli sh ./scripts/5_peer1.org2_chljoin.sh +``` +OR +``` +set -x +CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +CORE_PEER_LOCALMSPID=Org2MSP +CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +CORE_PEER_TLS_ENABLED=true +CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +CORE_PEER_ID=cli +CORE_PEER_ADDRESS=peer1.org2.example.com:10051 +CHANNEL_NAME=mychannel2 +peer channel join -b $CHANNEL_NAME.block +``` +#### 6, Update anchor PEER channel for orgs, so the second peers will interact with peer0(anchor peer0) for transactions and only peer0 is exposed to the world. +``` +$ docker exec cli sh ./scripts/6_anchorpeerorg1.sh +``` +OR +``` +$ docker exec -it cli bash ### you get the root prompt for contianer +set -x +CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +CORE_PEER_LOCALMSPID=Org1MSP +CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +CORE_PEER_TLS_ENABLED=true +CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +CORE_PEER_ID=cli +CORE_PEER_ADDRESS=peer0.org1.example.com:7051 +ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org1MSPanchors.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA +``` +#### 7, Now update anchor peer for org2 to the channel +######### Repeat same from the second org - Org2 ########## + +``` +$ docker exec cli sh ./scripts/7_anchorpeerorg2.sh + +``` +OR +``` +set -x +CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +CORE_PEER_LOCALMSPID=Org2MSP +CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +CORE_PEER_TLS_ENABLED=true +CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +CORE_PEER_ID=cli +CORE_PEER_ADDRESS=peer0.org2.example.com:9051 +ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +CHANNEL_NAME=mychannel2 +peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org2MSPanchors.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA +``` +############################################################################################ +#### Now the Network is ready and docker Containers up and communicating with Channel +############################################################################################ + +##################### +##### Stage 2 ####### +##################### + +Now your network is up and running, you have to deploy chaincode/smartcontracts over the network +your network consists of one orderer and 4 peers ( 2 from each org.) +we have one cli container to execute our binaries. + +Lets install the chaincode on peer0.org1 export the variables first. +### 8, Chaincode install +``` +newnet$ docker exec cli sh ./scripts/8_ccinstallpeer0.org1.sh +``` +OR +``` +$ docker exec -it cli bash ### you get the root prompt for contianer + +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org1MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 +peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/ +``` +###### 9, Do it same for Org2 +Install chaincode on peer0.org2... +``` +newnet$ docker exec cli sh ./scripts/9_ccinstallpeer0.org2.sh +``` +OR +``` +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org2MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer0.org2.example.com:9051 +peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/ +``` +Installing chaincode on peer1.org2... +``` +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org2MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer1.org2.example.com:10051 +peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/ +``` +### 10, Instantiate +We have installed our chaincode/smartcontracts to peers, Now instantiate the chaincode/smartcontract to the network (channnel) +you can run the script or below with variables +``` +newnet$ docker exec cli sh ./scripts/10_ccinstantiate.org2.sh +``` +OR + +``` +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org2MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer0.org2.example.com:9051 +peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel2 -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')' +``` +Lets quickly go through the smart contact. you can refer the file under chaincode_example02/go/chaincode_example02.go. Where it declares the variables and functions with arithametic operations. +So we defined the variable for A = 10 and B = 200, and endorsing peers are from Org1 and Org2 compulsory you can also appy "OR" which means that the endorsing peers from any of these Org's. + + +After instantiate the chaincode, you can do query the assets to confirm its been registerd in ledger. you will get the value of "A" is 100. + +Tips : The ledgers are stored in /var/hyperledger/production/ on each peer. + +### 11, Querying chaincode on peer0.org1... + + +``` +newnet$ docker exec cli sh ./scripts/11_ccquery.org1.sh +``` +OR + +``` +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org1MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 +peer chaincode query -C mychannel2 -n mycc -c '{"Args":["query","a"]}' +``` +### 12, Invoke Transaction +Im transferring the some value from A to B +Lets invoke the transaction from "A" to "B" and do query from pee1.org2 for transaction status + + +``` +newnet$ docker exec cli sh ./scripts/12_ccinvoketransfer.sh +``` +OR + + +Sending invoke transaction on peer0.org2... +``` + +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org2MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer0.org2.example.com:9051 + +export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +export PEER0_ORG1_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +export PEER0_ORG2_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt + +peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel2 -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles $PEER0_ORG1_CA --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles $PEER0_ORG2_CA -c '{"Args":["invoke","a","b","10"]}' + + ``` + +### 13, Query from different peer + + Query from Peer1.org2 and you should get value of "a" is 90. + + +``` +newnet$ docker exec cli sh ./scripts/13_ccquery.org2.sh +``` +OR + +Querying chaincode on peer1.org2... +``` +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org2MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer1.org2.example.com:10051 +===================== Querying on peer1.org2 on channel 'mychannel2'... ===================== +Attempting to Query peer1.org2 ...3 secs +peer chaincode query -C mychannel2 -n mycc -c '{"Args":["query","a"]}' +``` + +############################################################################################ +#### Now the BYFN is tested with smartcontract transactions, +#### Let's see how the new Org can join the exsisting network and read the transactions. +############################################################################################ + +##################### +##### Stage 3 ####### +##################### + +## Now add the new organizations (org3) to exsisting network + +Copy files from first-network folder + +#### Directory of org3-artifacts and file docker-compose-org3.yaml +``` +newnet$ cp -r ../first-network/org3-artifacts . && cp ../first-network/docker-compose-org3.yaml . +``` +Change dir to /yourhomepath/fabric-samples/newnet/org3-artifacts + +#### 14, Doing pre requesties for Org3 +``` +newnet$ ./scripts/14_prereq_addorg.sh +``` +OR +``` + export PATH=${PWD}/../bin:${PWD}:$PATH + export FABRIC_CFG_PATH=${PWD} + +$ cryptogen generate --config=./org3-crypto.yaml ### Note : First time only. + +$ export FABRIC_CFG_PATH=$PWD && ../../bin/configtxgen -printOrg Org3MSP > ../channel-artifacts/org3.json +Note : If you have errors at this stage, then delete crypto-config folder and generate certs by cryptogen + +$ cd ../ && cp -r crypto-config/ordererOrganizations org3-artifacts/crypto-config/ +$ sudo apt-get -y update && sudo apt-get -y install jq ### Note : First time only. + +``` +#### 15, Gathering the Channel configurations and updating with new org to existing channel +``` +newnet$ docker exec cli sh ./scripts/15_addorg_netup.sh +``` +OR +``` +$ docker exec -it cli bash + +## Update the environment settings +$ export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +$ export CHANNEL_NAME=mychannel2 +$ peer channel fetch config config_block.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA + +##Convert the Configuration to JSON and add the new org +$ configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config.json +$ jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./channel-artifacts/org3.json > modified_config.json + +## Translate config.json back into a protobuf and Encode modified_config.json to modified_config.pb +$ configtxlator proto_encode --input config.json --type common.Config --output config.pb +$ configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb + +## Identify the difference between protobuf and decode to readable json format. +$ configtxlator compute_update --channel_id $CHANNEL_NAME --original config.pb --updated modified_config.pb --output org3_update.pb +$ configtxlator proto_decode --input org3_update.pb --type common.ConfigUpdate | jq . > org3_update.json + +## Wrap in an envelope message and encode to protobuf +$ echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel2", "type":2}},"data":{"config_update":'$(cat org3_update.json)'}}}' | jq . > org3_update_in_envelope.json +$ configtxlator proto_encode --input org3_update_in_envelope.json --type common.Envelope --output org3_update_in_envelope.pb + +##sign and submit the config updates from the org1 and org2 +$ peer channel signconfigtx -f org3_update_in_envelope.pb ### org1 signoff for adding org3 + +## Export the environment variables to sign as org2 +export CORE_PEER_LOCALMSPID="Org2MSP" +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ADDRESS=peer0.org2.example.com:9051 +peer channel update -f org3_update_in_envelope.pb -c $CHANNEL_NAME -o orderer.example.com:7050 --tls --cafile $ORDERER_CA +``` + +#### 16, Lets the org3 container spin up and get into org3cli to join the network channel + +``` +~newnet$ ./scripts/16_addorg_joinnet.sh +``` +OR + +``` +$ docker-compose -f docker-compose-org3.yaml up -d +$ docker exec -it Org3cli bash + +##export variables and join the channel +$ export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +$ export CHANNEL_NAME=mychannel2 +$ peer channel fetch 0 mychannel2.block -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA +$ peer channel join -b mychannel2.block +``` +##### 17, Do this for second peer1.org3 ( this is optional for demo requirement) +``` +newnet$ docker exec Org3cli sh ./scripts/17_addorg_ccins_qry.sh +``` +OR + +``` +$ docker exec -it Org3cli bash +$ export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer1.org3.example.com/tls/ca.crt +$ export CORE_PEER_ADDRESS=peer1.org3.example.com:12051 +$ peer channel join -b mychannel2.block +``` +#### 17a, Install Chaincode/Query. +##### Comeback to peer0.org3 and install chaincode +##### Query from org3 node for the assets Do this step after chaincode has instantiated from Org2. +``` +$ export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt +export CORE_PEER_ADDRESS=peer0.org3.example.com:11051 + +peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/ + +peer chaincode query -C mychannel2 -n mycc -c '{"Args":["query","a"]}' + +``` + +Hope this helps you to understand the BYFN / EYFN. Give thumbsup to motivate me. +Thank you !!! + +################################################################################# \ No newline at end of file diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/base/docker-compose-base.yaml b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/base/docker-compose-base.yaml new file mode 100644 index 0000000..4c55ff9 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/base/docker-compose-base.yaml @@ -0,0 +1,110 @@ +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +version: '2' + +services: + + orderer.example.com: + container_name: orderer.example.com + extends: + file: peer-base.yaml + service: orderer-base + volumes: + - ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block + - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp + - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls + - orderer.example.com:/var/hyperledger/production/orderer + ports: + - 7050:7050 + + peer0.org1.example.com: + container_name: peer0.org1.example.com + extends: + file: peer-base.yaml + service: peer-base + environment: + - CORE_PEER_ID=peer0.org1.example.com + - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 + - CORE_PEER_LISTENADDRESS=0.0.0.0:7051 + - CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052 + - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052 + - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:8051 + - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051 + - CORE_PEER_LOCALMSPID=Org1MSP + volumes: + - /var/run/:/host/var/run/ + - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp + - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls + - peer0.org1.example.com:/var/hyperledger/production + ports: + - 7051:7051 + + peer1.org1.example.com: + container_name: peer1.org1.example.com + extends: + file: peer-base.yaml + service: peer-base + environment: + - CORE_PEER_ID=peer1.org1.example.com + - CORE_PEER_ADDRESS=peer1.org1.example.com:8051 + - CORE_PEER_LISTENADDRESS=0.0.0.0:8051 + - CORE_PEER_CHAINCODEADDRESS=peer1.org1.example.com:8052 + - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052 + - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:8051 + - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051 + - CORE_PEER_LOCALMSPID=Org1MSP + volumes: + - /var/run/:/host/var/run/ + - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp + - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls + - peer1.org1.example.com:/var/hyperledger/production + + ports: + - 8051:8051 + + peer0.org2.example.com: + container_name: peer0.org2.example.com + extends: + file: peer-base.yaml + service: peer-base + environment: + - CORE_PEER_ID=peer0.org2.example.com + - CORE_PEER_ADDRESS=peer0.org2.example.com:9051 + - CORE_PEER_LISTENADDRESS=0.0.0.0:9051 + - CORE_PEER_CHAINCODEADDRESS=peer0.org2.example.com:9052 + - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:9052 + - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:9051 + - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:10051 + - CORE_PEER_LOCALMSPID=Org2MSP + volumes: + - /var/run/:/host/var/run/ + - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp + - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls + - peer0.org2.example.com:/var/hyperledger/production + ports: + - 9051:9051 + + peer1.org2.example.com: + container_name: peer1.org2.example.com + extends: + file: peer-base.yaml + service: peer-base + environment: + - CORE_PEER_ID=peer1.org2.example.com + - CORE_PEER_ADDRESS=peer1.org2.example.com:10051 + - CORE_PEER_LISTENADDRESS=0.0.0.0:10051 + - CORE_PEER_CHAINCODEADDRESS=peer1.org2.example.com:10052 + - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:10052 + - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.example.com:10051 + - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:9051 + - CORE_PEER_LOCALMSPID=Org2MSP + volumes: + - /var/run/:/host/var/run/ + - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp:/etc/hyperledger/fabric/msp + - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls + - peer1.org2.example.com:/var/hyperledger/production + ports: + - 10051:10051 diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/base/peer-base.yaml b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/base/peer-base.yaml new file mode 100644 index 0000000..6f6dd3e --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/base/peer-base.yaml @@ -0,0 +1,50 @@ +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +version: '2' + +services: + peer-base: + image: hyperledger/fabric-peer:$IMAGE_TAG + environment: + - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock + # the following setting starts chaincode containers on the same + # bridge network as the peers + # https://docs.docker.com/compose/networking/ + - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_byfn + - FABRIC_LOGGING_SPEC=INFO + #- FABRIC_LOGGING_SPEC=DEBUG + - CORE_PEER_TLS_ENABLED=true + - CORE_PEER_GOSSIP_USELEADERELECTION=true + - CORE_PEER_GOSSIP_ORGLEADER=false + - CORE_PEER_PROFILE_ENABLED=true + - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt + - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key + - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt + working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer + command: peer node start + + orderer-base: + image: hyperledger/fabric-orderer:$IMAGE_TAG + environment: + - FABRIC_LOGGING_SPEC=INFO + - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 + - ORDERER_GENERAL_GENESISMETHOD=file + - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block + - ORDERER_GENERAL_LOCALMSPID=OrdererMSP + - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp + # enabled TLS + - ORDERER_GENERAL_TLS_ENABLED=true + - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key + - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt + - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] + - ORDERER_KAFKA_TOPIC_REPLICATIONFACTOR=1 + - ORDERER_KAFKA_VERBOSE=true + - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt + - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key + - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] + working_dir: /opt/gopath/src/github.com/hyperledger/fabric + command: orderer + diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/go/chaincode_example02.go b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/go/chaincode_example02.go new file mode 100644 index 0000000..5343806 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/go/chaincode_example02.go @@ -0,0 +1,199 @@ +/* +Copyright IBM Corp. 2016 All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +//WARNING - this chaincode's ID is hard-coded in chaincode_example04 to illustrate one way of +//calling chaincode from a chaincode. If this example is modified, chaincode_example04.go has +//to be modified as well with the new ID of chaincode_example02. +//chaincode_example05 show's how chaincode ID can be passed in as a parameter instead of +//hard-coding. + +import ( + "fmt" + "strconv" + + "github.com/hyperledger/fabric/core/chaincode/shim" + pb "github.com/hyperledger/fabric/protos/peer" +) + +// SimpleChaincode example simple Chaincode implementation +type SimpleChaincode struct { +} + +func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { + fmt.Println("ex02 Init") + _, args := stub.GetFunctionAndParameters() + var A, B string // Entities + var Aval, Bval int // Asset holdings + var err error + + if len(args) != 4 { + return shim.Error("Incorrect number of arguments. Expecting 4") + } + + // Initialize the chaincode + A = args[0] + Aval, err = strconv.Atoi(args[1]) + if err != nil { + return shim.Error("Expecting integer value for asset holding") + } + B = args[2] + Bval, err = strconv.Atoi(args[3]) + if err != nil { + return shim.Error("Expecting integer value for asset holding") + } + fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval) + + // Write the state to the ledger + err = stub.PutState(A, []byte(strconv.Itoa(Aval))) + if err != nil { + return shim.Error(err.Error()) + } + + err = stub.PutState(B, []byte(strconv.Itoa(Bval))) + if err != nil { + return shim.Error(err.Error()) + } + + return shim.Success(nil) +} + +func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { + fmt.Println("ex02 Invoke") + function, args := stub.GetFunctionAndParameters() + if function == "invoke" { + // Make payment of X units from A to B + return t.invoke(stub, args) + } else if function == "delete" { + // Deletes an entity from its state + return t.delete(stub, args) + } else if function == "query" { + // the old "Query" is now implemtned in invoke + return t.query(stub, args) + } + + return shim.Error("Invalid invoke function name. Expecting \"invoke\" \"delete\" \"query\"") +} + +// Transaction makes payment of X units from A to B +func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) pb.Response { + var A, B string // Entities + var Aval, Bval int // Asset holdings + var X int // Transaction value + var err error + + if len(args) != 3 { + return shim.Error("Incorrect number of arguments. Expecting 3") + } + + A = args[0] + B = args[1] + + // Get the state from the ledger + // TODO: will be nice to have a GetAllState call to ledger + Avalbytes, err := stub.GetState(A) + if err != nil { + return shim.Error("Failed to get state") + } + if Avalbytes == nil { + return shim.Error("Entity not found") + } + Aval, _ = strconv.Atoi(string(Avalbytes)) + + Bvalbytes, err := stub.GetState(B) + if err != nil { + return shim.Error("Failed to get state") + } + if Bvalbytes == nil { + return shim.Error("Entity not found") + } + Bval, _ = strconv.Atoi(string(Bvalbytes)) + + // Perform the execution + X, err = strconv.Atoi(args[2]) + if err != nil { + return shim.Error("Invalid transaction amount, expecting a integer value") + } + Aval = Aval - X + Bval = Bval + X + fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval) + + // Write the state back to the ledger + err = stub.PutState(A, []byte(strconv.Itoa(Aval))) + if err != nil { + return shim.Error(err.Error()) + } + + err = stub.PutState(B, []byte(strconv.Itoa(Bval))) + if err != nil { + return shim.Error(err.Error()) + } + + return shim.Success(nil) +} + +// Deletes an entity from state +func (t *SimpleChaincode) delete(stub shim.ChaincodeStubInterface, args []string) pb.Response { + if len(args) != 1 { + return shim.Error("Incorrect number of arguments. Expecting 1") + } + + A := args[0] + + // Delete the key from the state in ledger + err := stub.DelState(A) + if err != nil { + return shim.Error("Failed to delete state") + } + + return shim.Success(nil) +} + +// query callback representing the query of a chaincode +func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) pb.Response { + var A string // Entities + var err error + + if len(args) != 1 { + return shim.Error("Incorrect number of arguments. Expecting name of the person to query") + } + + A = args[0] + + // Get the state from the ledger + Avalbytes, err := stub.GetState(A) + if err != nil { + jsonResp := "{\"Error\":\"Failed to get state for " + A + "\"}" + return shim.Error(jsonResp) + } + + if Avalbytes == nil { + jsonResp := "{\"Error\":\"Nil amount for " + A + "\"}" + return shim.Error(jsonResp) + } + + jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}" + fmt.Printf("Query Response:%s\n", jsonResp) + return shim.Success(Avalbytes) +} + +func main() { + err := shim.Start(new(SimpleChaincode)) + if err != nil { + fmt.Printf("Error starting Simple chaincode: %s", err) + } +} diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/java/build.gradle b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/java/build.gradle new file mode 100644 index 0000000..5221272 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/java/build.gradle @@ -0,0 +1,34 @@ +/* + * Copyright IBM Corp. 2018 All Rights Reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ +plugins { + id 'com.github.johnrengelman.shadow' version '2.0.3' + id 'java' +} + +group 'org.hyperledger.fabric-chaincode-java' +version '1.0-SNAPSHOT' + +sourceCompatibility = 1.8 + +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.+' + testCompile group: 'junit', name: 'junit', version: '4.12' +} + +shadowJar { + baseName = 'chaincode' + version = null + classifier = null + + manifest { + attributes 'Main-Class': 'org.hyperledger.fabric.example.SimpleChaincode' + } +} diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/java/settings.gradle b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/java/settings.gradle new file mode 100644 index 0000000..9ce14a6 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/java/settings.gradle @@ -0,0 +1,7 @@ +/* + * Copyright IBM Corp. 2017 All Rights Reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ +rootProject.name = 'fabric-chaincode-example-gradle' + diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/java/src/main/java/org/hyperledger/fabric/example/SimpleChaincode.java b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/java/src/main/java/org/hyperledger/fabric/example/SimpleChaincode.java new file mode 100644 index 0000000..dd93a4e --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/java/src/main/java/org/hyperledger/fabric/example/SimpleChaincode.java @@ -0,0 +1,142 @@ +/* +Copyright IBM Corp., DTCC All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ +package org.hyperledger.fabric.example; + +import java.util.List; + +import com.google.protobuf.ByteString; +import io.netty.handler.ssl.OpenSsl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hyperledger.fabric.shim.ChaincodeBase; +import org.hyperledger.fabric.shim.ChaincodeStub; + +import static java.nio.charset.StandardCharsets.UTF_8; + +public class SimpleChaincode extends ChaincodeBase { + + private static Log _logger = LogFactory.getLog(SimpleChaincode.class); + + @Override + public Response init(ChaincodeStub stub) { + try { + _logger.info("Init java simple chaincode"); + String func = stub.getFunction(); + if (!func.equals("init")) { + return newErrorResponse("function other than init is not supported"); + } + List args = stub.getParameters(); + if (args.size() != 4) { + newErrorResponse("Incorrect number of arguments. Expecting 4"); + } + // Initialize the chaincode + String account1Key = args.get(0); + int account1Value = Integer.parseInt(args.get(1)); + String account2Key = args.get(2); + int account2Value = Integer.parseInt(args.get(3)); + + _logger.info(String.format("account %s, value = %s; account %s, value %s", account1Key, account1Value, account2Key, account2Value)); + stub.putStringState(account1Key, args.get(1)); + stub.putStringState(account2Key, args.get(3)); + + return newSuccessResponse(); + } catch (Throwable e) { + return newErrorResponse(e); + } + } + + @Override + public Response invoke(ChaincodeStub stub) { + try { + _logger.info("Invoke java simple chaincode"); + String func = stub.getFunction(); + List params = stub.getParameters(); + if (func.equals("invoke")) { + return invoke(stub, params); + } + if (func.equals("delete")) { + return delete(stub, params); + } + if (func.equals("query")) { + return query(stub, params); + } + return newErrorResponse("Invalid invoke function name. Expecting one of: [\"invoke\", \"delete\", \"query\"]"); + } catch (Throwable e) { + return newErrorResponse(e); + } + } + + private Response invoke(ChaincodeStub stub, List args) { + if (args.size() != 3) { + return newErrorResponse("Incorrect number of arguments. Expecting 3"); + } + String accountFromKey = args.get(0); + String accountToKey = args.get(1); + + String accountFromValueStr = stub.getStringState(accountFromKey); + if (accountFromValueStr == null) { + return newErrorResponse(String.format("Entity %s not found", accountFromKey)); + } + int accountFromValue = Integer.parseInt(accountFromValueStr); + + String accountToValueStr = stub.getStringState(accountToKey); + if (accountToValueStr == null) { + return newErrorResponse(String.format("Entity %s not found", accountToKey)); + } + int accountToValue = Integer.parseInt(accountToValueStr); + + int amount = Integer.parseInt(args.get(2)); + + if (amount > accountFromValue) { + return newErrorResponse(String.format("not enough money in account %s", accountFromKey)); + } + + accountFromValue -= amount; + accountToValue += amount; + + _logger.info(String.format("new value of A: %s", accountFromValue)); + _logger.info(String.format("new value of B: %s", accountToValue)); + + stub.putStringState(accountFromKey, Integer.toString(accountFromValue)); + stub.putStringState(accountToKey, Integer.toString(accountToValue)); + + _logger.info("Transfer complete"); + + return newSuccessResponse("invoke finished successfully", ByteString.copyFrom(accountFromKey + ": " + accountFromValue + " " + accountToKey + ": " + accountToValue, UTF_8).toByteArray()); + } + + // Deletes an entity from state + private Response delete(ChaincodeStub stub, List args) { + if (args.size() != 1) { + return newErrorResponse("Incorrect number of arguments. Expecting 1"); + } + String key = args.get(0); + // Delete the key from the state in ledger + stub.delState(key); + return newSuccessResponse(); + } + + // query callback representing the query of a chaincode + private Response query(ChaincodeStub stub, List args) { + if (args.size() != 1) { + return newErrorResponse("Incorrect number of arguments. Expecting name of the person to query"); + } + String key = args.get(0); + //byte[] stateBytes + String val = stub.getStringState(key); + if (val == null) { + return newErrorResponse(String.format("Error: state for %s is null", key)); + } + _logger.info(String.format("Query Response:\nName: %s, Amount: %s\n", key, val)); + return newSuccessResponse(val, ByteString.copyFrom(val, UTF_8).toByteArray()); + } + + public static void main(String[] args) { + System.out.println("OpenSSL avaliable: " + OpenSsl.isAvailable()); + new SimpleChaincode().start(args); + } + +} diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/node/chaincode_example02.js b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/node/chaincode_example02.js new file mode 100644 index 0000000..545092a --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/node/chaincode_example02.js @@ -0,0 +1,138 @@ +/* +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +*/ + +const shim = require('fabric-shim'); +const util = require('util'); + +var Chaincode = class { + + // Initialize the chaincode + async Init(stub) { + console.info('========= example02 Init ========='); + let ret = stub.getFunctionAndParameters(); + console.info(ret); + let args = ret.params; + // initialise only if 4 parameters passed. + if (args.length != 4) { + return shim.error('Incorrect number of arguments. Expecting 4'); + } + + let A = args[0]; + let B = args[2]; + let Aval = args[1]; + let Bval = args[3]; + + if (typeof parseInt(Aval) !== 'number' || typeof parseInt(Bval) !== 'number') { + return shim.error('Expecting integer value for asset holding'); + } + + try { + await stub.putState(A, Buffer.from(Aval)); + try { + await stub.putState(B, Buffer.from(Bval)); + return shim.success(); + } catch (err) { + return shim.error(err); + } + } catch (err) { + return shim.error(err); + } + } + + async Invoke(stub) { + let ret = stub.getFunctionAndParameters(); + console.info(ret); + let method = this[ret.fcn]; + if (!method) { + console.log('no method of name:' + ret.fcn + ' found'); + return shim.success(); + } + try { + let payload = await method(stub, ret.params); + return shim.success(payload); + } catch (err) { + console.log(err); + return shim.error(err); + } + } + + async invoke(stub, args) { + if (args.length != 3) { + throw new Error('Incorrect number of arguments. Expecting 3'); + } + + let A = args[0]; + let B = args[1]; + if (!A || !B) { + throw new Error('asset holding must not be empty'); + } + + // Get the state from the ledger + let Avalbytes = await stub.getState(A); + if (!Avalbytes) { + throw new Error('Failed to get state of asset holder A'); + } + let Aval = parseInt(Avalbytes.toString()); + + let Bvalbytes = await stub.getState(B); + if (!Bvalbytes) { + throw new Error('Failed to get state of asset holder B'); + } + + let Bval = parseInt(Bvalbytes.toString()); + // Perform the execution + let amount = parseInt(args[2]); + if (typeof amount !== 'number') { + throw new Error('Expecting integer value for amount to be transaferred'); + } + + Aval = Aval - amount; + Bval = Bval + amount; + console.info(util.format('Aval = %d, Bval = %d\n', Aval, Bval)); + + // Write the states back to the ledger + await stub.putState(A, Buffer.from(Aval.toString())); + await stub.putState(B, Buffer.from(Bval.toString())); + + } + + // Deletes an entity from state + async delete(stub, args) { + if (args.length != 1) { + throw new Error('Incorrect number of arguments. Expecting 1'); + } + + let A = args[0]; + + // Delete the key from the state in ledger + await stub.deleteState(A); + } + + // query callback representing the query of a chaincode + async query(stub, args) { + if (args.length != 1) { + throw new Error('Incorrect number of arguments. Expecting name of the person to query') + } + + let jsonResp = {}; + let A = args[0]; + + // Get the state from the ledger + let Avalbytes = await stub.getState(A); + if (!Avalbytes) { + jsonResp.error = 'Failed to get state for ' + A; + throw new Error(JSON.stringify(jsonResp)); + } + + jsonResp.name = A; + jsonResp.amount = Avalbytes.toString(); + console.info('Query Response:'); + console.info(jsonResp); + return Avalbytes; + } +}; + +shim.start(new Chaincode()); diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/node/package.json b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/node/package.json new file mode 100644 index 0000000..84e201d --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/chaincode_example02/node/package.json @@ -0,0 +1,15 @@ +{ + "name": "chaincode_example02", + "version": "1.0.0", + "description": "chaincode_example02 chaincode implemented in node.js", + "engines": { + "node": ">=8.4.0", + "npm": ">=5.3.0" + }, + "scripts": { "start" : "node chaincode_example02.js" }, + "engine-strict": true, + "license": "Apache-2.0", + "dependencies": { + "fabric-shim": "~1.4.0" + } +} diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/configtx.yaml b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/configtx.yaml new file mode 100644 index 0000000..29c54a8 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/configtx.yaml @@ -0,0 +1,411 @@ +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +--- +################################################################################ +# +# Section: Organizations +# +# - This section defines the different organizational identities which will +# be referenced later in the configuration. +# +################################################################################ +Organizations: + + # SampleOrg defines an MSP using the sampleconfig. It should never be used + # in production but may be used as a template for other definitions + - &OrdererOrg + # DefaultOrg defines the organization which is used in the sampleconfig + # of the fabric.git development environment + Name: OrdererOrg + + # ID to load the MSP definition as + ID: OrdererMSP + + # MSPDir is the filesystem path which contains the MSP configuration + MSPDir: crypto-config/ordererOrganizations/example.com/msp + + # Policies defines the set of policies at this level of the config tree + # For organization policies, their canonical path is usually + # /Channel/// + Policies: + Readers: + Type: Signature + Rule: "OR('OrdererMSP.member')" + Writers: + Type: Signature + Rule: "OR('OrdererMSP.member')" + Admins: + Type: Signature + Rule: "OR('OrdererMSP.admin')" + + - &Org1 + # DefaultOrg defines the organization which is used in the sampleconfig + # of the fabric.git development environment + Name: Org1MSP + + # ID to load the MSP definition as + ID: Org1MSP + + MSPDir: crypto-config/peerOrganizations/org1.example.com/msp + + # Policies defines the set of policies at this level of the config tree + # For organization policies, their canonical path is usually + # /Channel/// + Policies: + Readers: + Type: Signature + Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')" + Writers: + Type: Signature + Rule: "OR('Org1MSP.admin', 'Org1MSP.client')" + Admins: + Type: Signature + Rule: "OR('Org1MSP.admin')" + + # leave this flag set to true. + AnchorPeers: + # AnchorPeers defines the location of peers which can be used + # for cross org gossip communication. Note, this value is only + # encoded in the genesis block in the Application section context + - Host: peer0.org1.example.com + Port: 7051 + + - &Org2 + # DefaultOrg defines the organization which is used in the sampleconfig + # of the fabric.git development environment + Name: Org2MSP + + # ID to load the MSP definition as + ID: Org2MSP + + MSPDir: crypto-config/peerOrganizations/org2.example.com/msp + + # Policies defines the set of policies at this level of the config tree + # For organization policies, their canonical path is usually + # /Channel/// + Policies: + Readers: + Type: Signature + Rule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')" + Writers: + Type: Signature + Rule: "OR('Org2MSP.admin', 'Org2MSP.client')" + Admins: + Type: Signature + Rule: "OR('Org2MSP.admin')" + + AnchorPeers: + # AnchorPeers defines the location of peers which can be used + # for cross org gossip communication. Note, this value is only + # encoded in the genesis block in the Application section context + - Host: peer0.org2.example.com + Port: 9051 + +################################################################################ +# +# SECTION: Capabilities +# +# - This section defines the capabilities of fabric network. This is a new +# concept as of v1.1.0 and should not be utilized in mixed networks with +# v1.0.x peers and orderers. Capabilities define features which must be +# present in a fabric binary for that binary to safely participate in the +# fabric network. For instance, if a new MSP type is added, newer binaries +# might recognize and validate the signatures from this type, while older +# binaries without this support would be unable to validate those +# transactions. This could lead to different versions of the fabric binaries +# having different world states. Instead, defining a capability for a channel +# informs those binaries without this capability that they must cease +# processing transactions until they have been upgraded. For v1.0.x if any +# capabilities are defined (including a map with all capabilities turned off) +# then the v1.0.x peer will deliberately crash. +# +################################################################################ +Capabilities: + # Channel capabilities apply to both the orderers and the peers and must be + # supported by both. + # Set the value of the capability to true to require it. + Channel: &ChannelCapabilities + # V1.4.3 for Channel is a catchall flag for behavior which has been + # determined to be desired for all orderers and peers running at the v1.4.3 + # level, but which would be incompatible with orderers and peers from + # prior releases. + # Prior to enabling V1.4.3 channel capabilities, ensure that all + # orderers and peers on a channel are at v1.4.3 or later. + V1_4_3: true + # V1.3 for Channel enables the new non-backwards compatible + # features and fixes of fabric v1.3 + V1_3: false + # V1.1 for Channel enables the new non-backwards compatible + # features and fixes of fabric v1.1 + V1_1: false + + # Orderer capabilities apply only to the orderers, and may be safely + # used with prior release peers. + # Set the value of the capability to true to require it. + Orderer: &OrdererCapabilities + # V1.4.2 for Orderer is a catchall flag for behavior which has been + # determined to be desired for all orderers running at the v1.4.2 + # level, but which would be incompatible with orderers from prior releases. + # Prior to enabling V1.4.2 orderer capabilities, ensure that all + # orderers on a channel are at v1.4.2 or later. + V1_4_2: true + # V1.1 for Orderer enables the new non-backwards compatible + # features and fixes of fabric v1.1 + V1_1: false + + # Application capabilities apply only to the peer network, and may be safely + # used with prior release orderers. + # Set the value of the capability to true to require it. + Application: &ApplicationCapabilities + # V1.4.2 for Application enables the new non-backwards compatible + # features and fixes of fabric v1.4.2. + V1_4_2: true + # V1.3 for Application enables the new non-backwards compatible + # features and fixes of fabric v1.3. + V1_3: false + # V1.2 for Application enables the new non-backwards compatible + # features and fixes of fabric v1.2 (note, this need not be set if + # later version capabilities are set) + V1_2: false + # V1.1 for Application enables the new non-backwards compatible + # features and fixes of fabric v1.1 (note, this need not be set if + # later version capabilities are set). + V1_1: false + +################################################################################ +# +# SECTION: Application +# +# - This section defines the values to encode into a config transaction or +# genesis block for application related parameters +# +################################################################################ +Application: &ApplicationDefaults + + # Organizations is the list of orgs which are defined as participants on + # the application side of the network + Organizations: + + # Policies defines the set of policies at this level of the config tree + # For Application policies, their canonical path is + # /Channel/Application/ + Policies: + Readers: + Type: ImplicitMeta + Rule: "ANY Readers" + Writers: + Type: ImplicitMeta + Rule: "ANY Writers" + Admins: + Type: ImplicitMeta + Rule: "MAJORITY Admins" + + Capabilities: + <<: *ApplicationCapabilities +################################################################################ +# +# SECTION: Orderer +# +# - This section defines the values to encode into a config transaction or +# genesis block for orderer related parameters +# +################################################################################ +Orderer: &OrdererDefaults + + # Orderer Type: The orderer implementation to start + # Available types are "solo" and "kafka" + OrdererType: solo + + Addresses: + - orderer.example.com:7050 + + # Batch Timeout: The amount of time to wait before creating a batch + BatchTimeout: 2s + + # Batch Size: Controls the number of messages batched into a block + BatchSize: + + # Max Message Count: The maximum number of messages to permit in a batch + MaxMessageCount: 10 + + # Absolute Max Bytes: The absolute maximum number of bytes allowed for + # the serialized messages in a batch. + AbsoluteMaxBytes: 99 MB + + # Preferred Max Bytes: The preferred maximum number of bytes allowed for + # the serialized messages in a batch. A message larger than the preferred + # max bytes will result in a batch larger than preferred max bytes. + PreferredMaxBytes: 512 KB + + Kafka: + # Brokers: A list of Kafka brokers to which the orderer connects + # NOTE: Use IP:port notation + Brokers: + - 127.0.0.1:9092 + + # Organizations is the list of orgs which are defined as participants on + # the orderer side of the network + Organizations: + + # Policies defines the set of policies at this level of the config tree + # For Orderer policies, their canonical path is + # /Channel/Orderer/ + Policies: + Readers: + Type: ImplicitMeta + Rule: "ANY Readers" + Writers: + Type: ImplicitMeta + Rule: "ANY Writers" + Admins: + Type: ImplicitMeta + Rule: "MAJORITY Admins" + # BlockValidation specifies what signatures must be included in the block + # from the orderer for the peer to validate it. + BlockValidation: + Type: ImplicitMeta + Rule: "ANY Writers" + +################################################################################ +# +# CHANNEL +# +# This section defines the values to encode into a config transaction or +# genesis block for channel related parameters. +# +################################################################################ +Channel: &ChannelDefaults + # Policies defines the set of policies at this level of the config tree + # For Channel policies, their canonical path is + # /Channel/ + Policies: + # Who may invoke the 'Deliver' API + Readers: + Type: ImplicitMeta + Rule: "ANY Readers" + # Who may invoke the 'Broadcast' API + Writers: + Type: ImplicitMeta + Rule: "ANY Writers" + # By default, who may modify elements at this config level + Admins: + Type: ImplicitMeta + Rule: "MAJORITY Admins" + + # Capabilities describes the channel level capabilities, see the + # dedicated Capabilities section elsewhere in this file for a full + # description + Capabilities: + <<: *ChannelCapabilities + +################################################################################ +# +# Profile +# +# - Different configuration profiles may be encoded here to be specified +# as parameters to the configtxgen tool +# +################################################################################ +Profiles: + + TwoOrgsOrdererGenesis: + <<: *ChannelDefaults + Orderer: + <<: *OrdererDefaults + Organizations: + - *OrdererOrg + Capabilities: + <<: *OrdererCapabilities + Consortiums: + SampleConsortium: + Organizations: + - *Org1 + - *Org2 + TwoOrgsChannel: + Consortium: SampleConsortium + <<: *ChannelDefaults + Application: + <<: *ApplicationDefaults + Organizations: + - *Org1 + - *Org2 + Capabilities: + <<: *ApplicationCapabilities + + SampleDevModeKafka: + <<: *ChannelDefaults + Capabilities: + <<: *ChannelCapabilities + Orderer: + <<: *OrdererDefaults + OrdererType: kafka + Kafka: + Brokers: + - kafka.example.com:9092 + + Organizations: + - *OrdererOrg + Capabilities: + <<: *OrdererCapabilities + Application: + <<: *ApplicationDefaults + Organizations: + - <<: *OrdererOrg + Consortiums: + SampleConsortium: + Organizations: + - *Org1 + - *Org2 + + SampleMultiNodeEtcdRaft: + <<: *ChannelDefaults + Capabilities: + <<: *ChannelCapabilities + Orderer: + <<: *OrdererDefaults + OrdererType: etcdraft + EtcdRaft: + Consenters: + - Host: orderer.example.com + Port: 7050 + ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt + ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt + - Host: orderer2.example.com + Port: 7050 + ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt + ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt + - Host: orderer3.example.com + Port: 7050 + ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt + ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt + - Host: orderer4.example.com + Port: 7050 + ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt + ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt + - Host: orderer5.example.com + Port: 7050 + ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt + ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt + Addresses: + - orderer.example.com:7050 + - orderer2.example.com:7050 + - orderer3.example.com:7050 + - orderer4.example.com:7050 + - orderer5.example.com:7050 + + Organizations: + - *OrdererOrg + Capabilities: + <<: *OrdererCapabilities + Application: + <<: *ApplicationDefaults + Organizations: + - <<: *OrdererOrg + Consortiums: + SampleConsortium: + Organizations: + - *Org1 + - *Org2 diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/crypto-config.yaml b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/crypto-config.yaml new file mode 100644 index 0000000..e455904 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/crypto-config.yaml @@ -0,0 +1,89 @@ +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# --------------------------------------------------------------------------- +# "OrdererOrgs" - Definition of organizations managing orderer nodes +# --------------------------------------------------------------------------- +OrdererOrgs: + # --------------------------------------------------------------------------- + # Orderer + # --------------------------------------------------------------------------- + - Name: Orderer + Domain: example.com + EnableNodeOUs: true + # --------------------------------------------------------------------------- + # "Specs" - See PeerOrgs below for complete description + # --------------------------------------------------------------------------- + Specs: + - Hostname: orderer + - Hostname: orderer2 + - Hostname: orderer3 + - Hostname: orderer4 + - Hostname: orderer5 + +# --------------------------------------------------------------------------- +# "PeerOrgs" - Definition of organizations managing peer nodes +# --------------------------------------------------------------------------- +PeerOrgs: + # --------------------------------------------------------------------------- + # Org1 + # --------------------------------------------------------------------------- + - Name: Org1 + Domain: org1.example.com + EnableNodeOUs: true + # --------------------------------------------------------------------------- + # "Specs" + # --------------------------------------------------------------------------- + # Uncomment this section to enable the explicit definition of hosts in your + # configuration. Most users will want to use Template, below + # + # Specs is an array of Spec entries. Each Spec entry consists of two fields: + # - Hostname: (Required) The desired hostname, sans the domain. + # - CommonName: (Optional) Specifies the template or explicit override for + # the CN. By default, this is the template: + # + # "{{.Hostname}}.{{.Domain}}" + # + # which obtains its values from the Spec.Hostname and + # Org.Domain, respectively. + # --------------------------------------------------------------------------- + # Specs: + # - Hostname: foo # implicitly "foo.org1.example.com" + # CommonName: foo27.org5.example.com # overrides Hostname-based FQDN set above + # - Hostname: bar + # - Hostname: baz + # --------------------------------------------------------------------------- + # "Template" + # --------------------------------------------------------------------------- + # Allows for the definition of 1 or more hosts that are created sequentially + # from a template. By default, this looks like "peer%d" from 0 to Count-1. + # You may override the number of nodes (Count), the starting index (Start) + # or the template used to construct the name (Hostname). + # + # Note: Template and Specs are not mutually exclusive. You may define both + # sections and the aggregate nodes will be created for you. Take care with + # name collisions + # --------------------------------------------------------------------------- + Template: + Count: 2 + # Start: 5 + # Hostname: {{.Prefix}}{{.Index}} # default + # --------------------------------------------------------------------------- + # "Users" + # --------------------------------------------------------------------------- + # Count: The number of user accounts _in addition_ to Admin + # --------------------------------------------------------------------------- + Users: + Count: 1 + # --------------------------------------------------------------------------- + # Org2: See "Org1" for full specification + # --------------------------------------------------------------------------- + - Name: Org2 + Domain: org2.example.com + EnableNodeOUs: true + Template: + Count: 2 + Users: + Count: 1 diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/docker-compose-cli.yaml b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/docker-compose-cli.yaml new file mode 100644 index 0000000..a7aa3f4 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/docker-compose-cli.yaml @@ -0,0 +1,94 @@ +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +version: '2' + +volumes: + orderer.example.com: + peer0.org1.example.com: + peer1.org1.example.com: + peer0.org2.example.com: + peer1.org2.example.com: + +networks: + byfn: + +services: + + orderer.example.com: + extends: + file: base/docker-compose-base.yaml + service: orderer.example.com + container_name: orderer.example.com + networks: + - byfn + + peer0.org1.example.com: + container_name: peer0.org1.example.com + extends: + file: base/docker-compose-base.yaml + service: peer0.org1.example.com + networks: + - byfn + + peer1.org1.example.com: + container_name: peer1.org1.example.com + extends: + file: base/docker-compose-base.yaml + service: peer1.org1.example.com + networks: + - byfn + + peer0.org2.example.com: + container_name: peer0.org2.example.com + extends: + file: base/docker-compose-base.yaml + service: peer0.org2.example.com + networks: + - byfn + + peer1.org2.example.com: + container_name: peer1.org2.example.com + extends: + file: base/docker-compose-base.yaml + service: peer1.org2.example.com + networks: + - byfn + + cli: + container_name: cli + image: hyperledger/fabric-tools:$IMAGE_TAG + tty: true + stdin_open: true + environment: + - SYS_CHANNEL=$SYS_CHANNEL + - GOPATH=/opt/gopath + - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock + #- FABRIC_LOGGING_SPEC=DEBUG + - FABRIC_LOGGING_SPEC=INFO + - CORE_PEER_ID=cli + - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 + - CORE_PEER_LOCALMSPID=Org1MSP + - CORE_PEER_TLS_ENABLED=true + - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt + - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key + - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt + - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp + working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer + command: /bin/bash + volumes: + - /var/run/:/host/var/run/ + - ./../chaincode/:/opt/gopath/src/github.com/chaincode + - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ + - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/ + - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts + depends_on: + - orderer.example.com + - peer0.org1.example.com + - peer1.org1.example.com + - peer0.org2.example.com + - peer1.org2.example.com + networks: + - byfn diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/docker-compose-org3.yaml b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/docker-compose-org3.yaml new file mode 100644 index 0000000..2ee41e3 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/docker-compose-org3.yaml @@ -0,0 +1,97 @@ +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +version: '2' + +volumes: + peer0.org3.example.com: + peer1.org3.example.com: + +networks: + byfn: + +services: + + peer0.org3.example.com: + container_name: peer0.org3.example.com + extends: + file: base/peer-base.yaml + service: peer-base + environment: + - CORE_PEER_ID=peer0.org3.example.com + - CORE_PEER_ADDRESS=peer0.org3.example.com:11051 + - CORE_PEER_LISTENADDRESS=0.0.0.0:11051 + - CORE_PEER_CHAINCODEADDRESS=peer0.org3.example.com:11052 + - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:11052 + - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org3.example.com:12051 + - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org3.example.com:11051 + - CORE_PEER_LOCALMSPID=Org3MSP + volumes: + - /var/run/:/host/var/run/ + - ./org3-artifacts/crypto-config/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/msp:/etc/hyperledger/fabric/msp + - ./org3-artifacts/crypto-config/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls:/etc/hyperledger/fabric/tls + - peer0.org3.example.com:/var/hyperledger/production + ports: + - 11051:11051 + networks: + - byfn + + peer1.org3.example.com: + container_name: peer1.org3.example.com + extends: + file: base/peer-base.yaml + service: peer-base + environment: + - CORE_PEER_ID=peer1.org3.example.com + - CORE_PEER_ADDRESS=peer1.org3.example.com:12051 + - CORE_PEER_LISTENADDRESS=0.0.0.0:12051 + - CORE_PEER_CHAINCODEADDRESS=peer1.org3.example.com:12052 + - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:12052 + - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org3.example.com:11051 + - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org3.example.com:12051 + - CORE_PEER_LOCALMSPID=Org3MSP + volumes: + - /var/run/:/host/var/run/ + - ./org3-artifacts/crypto-config/peerOrganizations/org3.example.com/peers/peer1.org3.example.com/msp:/etc/hyperledger/fabric/msp + - ./org3-artifacts/crypto-config/peerOrganizations/org3.example.com/peers/peer1.org3.example.com/tls:/etc/hyperledger/fabric/tls + - peer1.org3.example.com:/var/hyperledger/production + ports: + - 12051:12051 + networks: + - byfn + + + Org3cli: + container_name: Org3cli + image: hyperledger/fabric-tools:$IMAGE_TAG + tty: true + stdin_open: true + environment: + - GOPATH=/opt/gopath + - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock + - FABRIC_LOGGING_SPEC=INFO + #- FABRIC_LOGGING_SPEC=DEBUG + - CORE_PEER_ID=Org3cli + - CORE_PEER_ADDRESS=peer0.org3.example.com:11051 + - CORE_PEER_LOCALMSPID=Org3MSP + - CORE_PEER_TLS_ENABLED=true + - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.crt + - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.key + - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt + - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp + working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer + command: /bin/bash + volumes: + - /var/run/:/host/var/run/ + - ./../chaincode/:/opt/gopath/src/github.com/chaincode + - ./org3-artifacts/crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ + - ./crypto-config/peerOrganizations/org1.example.com:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com + - ./crypto-config/peerOrganizations/org2.example.com:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com + - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/ + depends_on: + - peer0.org3.example.com + - peer1.org3.example.com + networks: + - byfn diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/down.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/down.sh new file mode 100644 index 0000000..ab7f2e7 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/down.sh @@ -0,0 +1,9 @@ +source scripts/1_envsetup.sh +docker-compose -f docker-compose-org3.yaml down -v +docker-compose -f docker-compose-cli.yaml down -v +docker rm $(docker ps -aq) +docker network prune -f +docker volume prune -f +docker ps -a +docker volume ls +docker network ls diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/network.png b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/network.png new file mode 100644 index 0000000..440f44a Binary files /dev/null and b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/network.png differ diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/org3-artifacts/configtx.yaml b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/org3-artifacts/configtx.yaml new file mode 100644 index 0000000..ab3c81a --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/org3-artifacts/configtx.yaml @@ -0,0 +1,31 @@ +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +--- +################################################################################ +# +# Section: Organizations +# +# - This section defines the different organizational identities which will +# be referenced later in the configuration. +# +################################################################################ +Organizations: + - &Org3 + # DefaultOrg defines the organization which is used in the sampleconfig + # of the fabric.git development environment + Name: Org3MSP + + # ID to load the MSP definition as + ID: Org3MSP + + MSPDir: crypto-config/peerOrganizations/org3.example.com/msp + + AnchorPeers: + # AnchorPeers defines the location of peers which can be used + # for cross org gossip communication. Note, this value is only + # encoded in the genesis block in the Application section context + - Host: peer0.org3.example.com + Port: 11051 diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/org3-artifacts/org3-crypto.yaml b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/org3-artifacts/org3-crypto.yaml new file mode 100644 index 0000000..4711620 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/org3-artifacts/org3-crypto.yaml @@ -0,0 +1,19 @@ +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# --------------------------------------------------------------------------- +# "PeerOrgs" - Definition of organizations managing peer nodes +# --------------------------------------------------------------------------- +PeerOrgs: + # --------------------------------------------------------------------------- + # Org3 + # --------------------------------------------------------------------------- + - Name: Org3 + Domain: org3.example.com + EnableNodeOUs: true + Template: + Count: 2 + Users: + Count: 1 diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/10_ccinstantiate.org2.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/10_ccinstantiate.org2.sh new file mode 100644 index 0000000..e0f9754 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/10_ccinstantiate.org2.sh @@ -0,0 +1,13 @@ +echo "Instantiating chaincode on peer0.org2..." +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org2MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer0.org2.example.com:9051 +export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem + +peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel2 -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')' diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/11_ccquery.org1.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/11_ccquery.org1.sh new file mode 100644 index 0000000..6958952 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/11_ccquery.org1.sh @@ -0,0 +1,13 @@ +echo "Querying chaincode on peer0.org1..." +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org1MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 +##===================== Querying on peer0.org1 on channel 'mychannel2'... ===================== +echo "Attempting to Query peer0.org1 ...3 secs" +peer chaincode query -C mychannel2 -n mycc -c '{"Args":["query","a"]}' diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/12_ccinvoketransfer.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/12_ccinvoketransfer.sh new file mode 100644 index 0000000..71d3e40 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/12_ccinvoketransfer.sh @@ -0,0 +1,31 @@ +echo "Sending invoke transaction on peer0.org1 peer0.org2..." +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org1MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org2MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer0.org2.example.com:9051 + + +export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +export PEER0_ORG1_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +export PEER0_ORG2_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt + +peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel2 -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles $PEER0_ORG1_CA --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles $PEER0_ORG2_CA -c '{"Args":["invoke","a","b","10"]}' + + + + +#peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel2 -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}' diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/13_ccquery.org2.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/13_ccquery.org2.sh new file mode 100644 index 0000000..cb7a16f --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/13_ccquery.org2.sh @@ -0,0 +1,13 @@ +echo Querying chaincode on peer1.org2... +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org2MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer1.org2.example.com:10051 +##===================== Querying on peer1.org2 on channel 'mychannel2'... ===================== +echo "Attempting to Query peer1.org2 ...3 secs" +peer chaincode query -C mychannel2 -n mycc -c '{"Args":["query","a"]}' diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/14_prereq_addorg.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/14_prereq_addorg.sh new file mode 100644 index 0000000..23b5d35 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/14_prereq_addorg.sh @@ -0,0 +1,20 @@ +cd org3-artifacts +export PATH=${PWD}/../bin:${PWD}:$PATH +export FABRIC_CFG_PATH=${PWD} +echo $PWD +pwd +sleep 10 +#echo "execute this script from org3-artifacts folder" +#rm -rf crypto-config +#cryptogen generate --config=./org3-crypto.yaml +sleep 10 +export FABRIC_CFG_PATH=$PWD && ../../bin/configtxgen -printOrg Org3MSP > ../channel-artifacts/org3.json +sleep 5 + +cd ../ && cp -r crypto-config/ordererOrganizations org3-artifacts/crypto-config/ +ls org3-artifacts +sleep 5 +ls org3-artifacts/crypto-config/ +#sudo apt-get -y update && sudo apt-get -y install jq + + diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/15_addorg_netup.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/15_addorg_netup.sh new file mode 100644 index 0000000..b0c4950 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/15_addorg_netup.sh @@ -0,0 +1,37 @@ +echo " Fetching the information from the channel and store to config_block.pb" + +export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +export CHANNEL_NAME=mychannel2 +peer channel fetch config config_block.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA + + +echo " Now converting the configuration to json and adding the new org" +configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config.json +jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./channel-artifacts/org3.json > modified_config.json +sleep 2 +echo "Converting back to protobuf file" +configtxlator proto_encode --input config.json --type common.Config --output config.pb +configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb + +configtxlator compute_update --channel_id $CHANNEL_NAME --original config.pb --updated modified_config.pb --output org3_update.pb +configtxlator proto_decode --input org3_update.pb --type common.ConfigUpdate | jq . > org3_update.json +sleep 2 +echo "Wrap in an envelope message and encode to protobuf" + +echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel2", "type":2}},"data":{"config_update":'$(cat org3_update.json)'}}}' | jq . > org3_update_in_envelope.json +configtxlator proto_encode --input org3_update_in_envelope.json --type common.Envelope --output org3_update_in_envelope.pb +sleep 2 +echo "sign and submit the config updates from the org1 and org2" + +peer channel signconfigtx -f org3_update_in_envelope.pb + +echo " Export the environment variables to sign as org2" +sleep 15 +export CORE_PEER_LOCALMSPID="Org2MSP" +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ADDRESS=peer0.org2.example.com:9051 +peer channel update -f org3_update_in_envelope.pb -c $CHANNEL_NAME -o orderer.example.com:7050 --tls --cafile $ORDERER_CA + +sleep 30 + diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/16_addorg_joinnet.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/16_addorg_joinnet.sh new file mode 100644 index 0000000..87dc5c3 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/16_addorg_joinnet.sh @@ -0,0 +1,11 @@ +echo "bringing up the org3 containers" +docker-compose -f docker-compose-org3.yaml up -d +sleep 20 +export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +export CHANNEL_NAME=mychannel2 +sleep 20 +echo "joining to channel" +docker exec Org3cli peer channel fetch 0 mychannel2.block -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA + +docker exec Org3cli peer channel join -b mychannel2.block + diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/17_addorg_ccins_qry.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/17_addorg_ccins_qry.sh new file mode 100644 index 0000000..f6e4818 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/17_addorg_ccins_qry.sh @@ -0,0 +1,13 @@ +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt +export CORE_PEER_ADDRESS=peer0.org3.example.com:11051 + +peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/ +peer chaincode query -C mychannel2 -n mycc -c '{"Args":["query","a"]}' + + + +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer1.org3.example.com/tls/ca.crt +export CORE_PEER_ADDRESS=peer1.org3.example.com:12051 + +peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/ + diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/1_envsetup.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/1_envsetup.sh new file mode 100644 index 0000000..e75bd48 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/1_envsetup.sh @@ -0,0 +1,7 @@ +export PATH=${PWD}/../bin:${PWD}:$PATH +export FABRIC_CFG_PATH=${PWD} + +export SYS_CHANNEL="mychannel" +export CHANNEL_NAME=mychannel2 +export IMAGE_TAG=latest +export COMPOSE_PROJECT_NAME=newnet diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/1a_firsttimeonly.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/1a_firsttimeonly.sh new file mode 100644 index 0000000..917335d --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/1a_firsttimeonly.sh @@ -0,0 +1,7 @@ +cryptogen generate --config=./crypto-config.yaml +configtxgen -profile TwoOrgsOrdererGenesis -channelID $SYS_CHANNEL -outputBlock ./channel-artifacts/genesis.block + +configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME +configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP +configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP + diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/2_chanlCrt.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/2_chanlCrt.sh new file mode 100644 index 0000000..a829364 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/2_chanlCrt.sh @@ -0,0 +1,6 @@ +export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +export CHANNEL_NAME=mychannel2 +export CORE_PEER_TLS_ENABLED=true + +docker exec cli peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_TLS_ENABLED --cafile $ORDERER_CA + diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/2a_peer0.org1_chljoin.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/2a_peer0.org1_chljoin.sh new file mode 100644 index 0000000..b3d1938 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/2a_peer0.org1_chljoin.sh @@ -0,0 +1,13 @@ +set -x +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org1MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 +CHANNEL_NAME=mychannel2 +peer channel join -b $CHANNEL_NAME.block + diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/3_peer1.org1_chljoin.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/3_peer1.org1_chljoin.sh new file mode 100644 index 0000000..d1cbaa3 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/3_peer1.org1_chljoin.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key + +export CORE_PEER_LOCALMSPID=Org1MSP + +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock + +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt + +export CORE_PEER_TLS_ENABLED=true + +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +export CORE_PEER_ID=cli +set -x +CORE_PEER_ADDRESS=peer1.org1.example.com:8051 +echo $CORE_PEER_ADDRESS +echo $CORE_PEER_LOCALMSPID + +CHANNEL_NAME=mychannel2 +peer channel join -b $CHANNEL_NAME.block diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/4_peer0.org2_chljoin.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/4_peer0.org2_chljoin.sh new file mode 100644 index 0000000..d911105 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/4_peer0.org2_chljoin.sh @@ -0,0 +1,12 @@ +set -x +CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +CORE_PEER_LOCALMSPID=Org2MSP +CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +CORE_PEER_TLS_ENABLED=true +CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +CORE_PEER_ID=cli +CORE_PEER_ADDRESS=peer0.org2.example.com:9051 +CHANNEL_NAME=mychannel2 +peer channel join -b $CHANNEL_NAME.block diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/5_peer1.org2_chljoin.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/5_peer1.org2_chljoin.sh new file mode 100644 index 0000000..cf8b68c --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/5_peer1.org2_chljoin.sh @@ -0,0 +1,12 @@ +set -x +CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +CORE_PEER_LOCALMSPID=Org2MSP +CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +CORE_PEER_TLS_ENABLED=true +CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +CORE_PEER_ID=cli +CORE_PEER_ADDRESS=peer1.org2.example.com:10051 +CHANNEL_NAME=mychannel2 +peer channel join -b $CHANNEL_NAME.block diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/6_anchorpeerorg1.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/6_anchorpeerorg1.sh new file mode 100644 index 0000000..b4530fd --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/6_anchorpeerorg1.sh @@ -0,0 +1,15 @@ +set -x +CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +CORE_PEER_LOCALMSPID=Org1MSP +CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +CORE_PEER_TLS_ENABLED=true +CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +CORE_PEER_ID=cli +CORE_PEER_ADDRESS=peer0.org1.example.com:7051 + +ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +CHANNEL_NAME=mychannel2 +peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org1MSPanchors.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA + diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/7_anchorpeerorg2.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/7_anchorpeerorg2.sh new file mode 100644 index 0000000..9148692 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/7_anchorpeerorg2.sh @@ -0,0 +1,13 @@ +set -x +CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +CORE_PEER_LOCALMSPID=Org2MSP +CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +CORE_PEER_TLS_ENABLED=true +CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +CORE_PEER_ID=cli +CORE_PEER_ADDRESS=peer0.org2.example.com:9051 +ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem +CHANNEL_NAME=mychannel2 +peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org2MSPanchors.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/8_ccinstallpeer0.org1.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/8_ccinstallpeer0.org1.sh new file mode 100644 index 0000000..0c19153 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/8_ccinstallpeer0.org1.sh @@ -0,0 +1,25 @@ +echo "Installing chaincode on peer0.org1..." +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org1MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 +peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/ + + +echo "Installing chaincode on peer1.org1..." +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org1MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer1.org1.example.com:8051 +peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/ + diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/9_ccinstallpeer0.org2.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/9_ccinstallpeer0.org2.sh new file mode 100644 index 0000000..71269f5 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/9_ccinstallpeer0.org2.sh @@ -0,0 +1,23 @@ +echo "Install chaincode on peer0.org2..." +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org2MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer0.org2.example.com:9051 +peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/ + +echo "Installing chaincode on peer1.org2..." +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt +export CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key +export CORE_PEER_LOCALMSPID=Org2MSP +export CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock +export CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt +export CORE_PEER_TLS_ENABLED=true +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ID=cli +export CORE_PEER_ADDRESS=peer1.org2.example.com:10051 +peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/ diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/explr_keyupdate.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/explr_keyupdate.sh new file mode 100644 index 0000000..568d6a9 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/scripts/explr_keyupdate.sh @@ -0,0 +1,13 @@ +#cp first-network.json.org first-network.json.var +echo " move to exploerer directory and run tnis" + +export HOMEPATH=$FABRIC_CFG_PATH +echo +sed "s|{HOMEPATH}|$HOMEPATH|g" app/platform/fabric/connection-profile/first-network.json.var >app/platform/fabric/connection-profile/first-network.json1 + + +export ORG1_MSPKEY=$(cd $HOMEPATH/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore && ls *_sk) + +sed "s|{ORG1_MSPKEY}|$ORG1_MSPKEY|g" app/platform/fabric/connection-profile/first-network.json1 >app/platform/fabric/connection-profile/first-network.json + +rm -rf wallet/* diff --git a/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/start.sh b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/start.sh new file mode 100644 index 0000000..8f046e1 --- /dev/null +++ b/ACTIVE/Fabric-Samples-BYFN-EYFN-Explained/start.sh @@ -0,0 +1,51 @@ +echo " ##### Copy the Chaincode_exampl02 folder to path/to/fabric_samples/chaincode #####" +echo " ##### Note: Its important to take above step for install the chaincode contract ##### " + +source scripts/1_envsetup.sh +## firsttime script ignored here +docker-compose -f docker-compose-cli.yaml up -d +docker ps +sleep 15 +./scripts/2_chanlCrt.sh +sleep 3 +docker exec cli sh ./scripts/2a_peer0.org1_chljoin.sh +sleep 1 +docker exec cli sh ./scripts/3_peer1.org1_chljoin.sh +sleep 1 +docker exec cli sh ./scripts/4_peer0.org2_chljoin.sh +sleep 1 +docker exec cli sh ./scripts/5_peer1.org2_chljoin.sh +sleep 1 + +docker exec cli sh ./scripts/6_anchorpeerorg1.sh +sleep 2 +docker exec cli sh ./scripts/7_anchorpeerorg2.sh +sleep 2 + +docker exec cli sh ./scripts/8_ccinstallpeer0.org1.sh +sleep 2 +docker exec cli sh ./scripts/9_ccinstallpeer0.org2.sh +sleep 2 +docker exec cli sh ./scripts/10_ccinstantiate.org2.sh +sleep 2 +docker exec cli sh ./scripts/11_ccquery.org1.sh +sleep 1 + +docker exec cli sh ./scripts/12_ccinvoketransfer.sh +sleep 3 +docker exec cli sh ./scripts/13_ccquery.org2.sh + +echo " ++++++++ Adding New Org now +++++++++ " +sleep 10 + + +./scripts/14_prereq_addorg.sh +sleep 10 +docker exec cli sh ./scripts/15_addorg_netup.sh +sleep 15 +./scripts/16_addorg_joinnet.sh +sleep 5 +docker exec Org3cli sh ./scripts/17_addorg_ccins_qry.sh + +echo " ##### Tested the first network -explained #### " +