-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathManualStepsChannelChaincode.txt
More file actions
115 lines (60 loc) · 6.26 KB
/
ManualStepsChannelChaincode.txt
File metadata and controls
115 lines (60 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
******************************************************************
# With TLS
# Example Chaincode: chaincode_example02 (With proper execution order)
###1 Create configuration for channel "orgchannel"
cd /home/ubuntu/master_thesis/inventory/blockchain/fabric-config
export FABRIC_CFG_PATH=/home/ubuntu/master_thesis/inventory/blockchain/fabric-config
./bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID orgchannel
./bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID orgchannel -asOrg Org1MSP
./bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID orgchannel -asOrg Org2MSP
sudo cp -r ./channel-artifacts /opt/share/
###2 Download chaincode_example02 and place in shared storage /opt/share/channel-artifacts/chaincode_example02/:
sudo mkdir /opt/share/channel-artifacts/chaincode_example02; sudo wget https://raw.githubusercontent.com/hyperledger/fabric-samples/v1.2.1/chaincode/chaincode_example02/go/chaincode_example02.go -O /opt/share/channel-artifacts/chaincode_example02/chaincode_example02.go
###3 Create and join a Channel on all peers
# SSH into CLI pod of Org1. Get the pod name by "kubectl --all-namespaces get pods" command
kubectl exec -it cli-5569ccc668-5tbdk -c cli bash --namespace=org1
# Org1 CLI: Join peer0 and peer1 of Org1 in channel
export CORE_PEER_ADDRESS=peer0.org1:7051; export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1/peers/peer0.org1/tls/ca.crt
peer channel create -o orderer0.orgorderer1:7050 -c orgchannel -f ./channel-artifacts/channel.tx --tls true --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/orgorderer1/orderers/orderer0.orgorderer1/msp/tlscacerts/tlsca.orgorderer1-cert.pem
cp orgchannel.block ./channel-artifacts/
peer channel join -b ./channel-artifacts/orgchannel.block
export CORE_PEER_ADDRESS=peer1.org1:7051; export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1/peers/peer1.org1/tls/ca.crt
peer channel join -b ./channel-artifacts/orgchannel.block
export CORE_PEER_ADDRESS=peer0.org1:7051; export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1/peers/peer0.org1/tls/ca.crt
peer channel update -o orderer0.orgorderer1:7050 -c orgchannel -f ./channel-artifacts/Org1MSPanchors.tx --tls true --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/orgorderer1/orderers/orderer0.orgorderer1/msp/tlscacerts/tlsca.orgorderer1-cert.pem
-------------------------------------------------------------------------------------------------------
# SSH into CLI pod of Org2. Get the pod name by "kubectl --all-namespaces get pods" command
kubectl exec -it cli-754fd8bd58-d8nzn bash --namespace=org2
# Org2 CLI: Join peer0 and peer1 of Org2 in channel
export CORE_PEER_ADDRESS=peer0.org2:7051; export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org2/peers/peer0.org2/tls/ca.crt
peer channel join -b ./channel-artifacts/orgchannel.block
export CORE_PEER_ADDRESS=peer1.org2:7051; export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org2/peers/peer1.org2/tls/ca.crt
peer channel join -b ./channel-artifacts/orgchannel.block
export CORE_PEER_ADDRESS=peer0.org2:7051; export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org2/peers/peer0.org2/tls/ca.crt
peer channel update -o orderer0.orgorderer1:7050 -c orgchannel -f ./channel-artifacts/Org2MSPanchors.tx --tls true --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/orgorderer1/orderers/orderer0.orgorderer1/msp/tlscacerts/tlsca.orgorderer1-cert.pem
###4 Install Chaincode
# Org1 CLI: Install chain code on peer0 of Org1
export CORE_PEER_ADDRESS=peer0.org1:7051; export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1/peers/peer0.org1/tls/ca.crt
peer chaincode install -n orgcc -v 1.0 -p github.com/hyperledger/fabric/peer/channel-artifacts/chaincode_example02/
-------------------------------------------------------------------------------------------------------
# Org2 CLI: Install chain code on peer0 of Org2
export CORE_PEER_ADDRESS=peer0.org2:7051; export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org2/peers/peer0.org2/tls/ca.crt
peer chaincode install -n orgcc -v 1.0 -p github.com/hyperledger/fabric/peer/channel-artifacts/chaincode_example02/
###5 Execute Chaincode
# Org1 CLI: Instantiate and execute chaincode on Peer0 of Org1
## Instantiate chaincode on Peer0 of Org1. 'a' has $100 and 'b' has $200 in their accounts
export CORE_PEER_ADDRESS=peer0.org1:7051
peer chaincode instantiate -o orderer0.orgorderer1:7050 --tls true --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/orgorderer1/orderers/orderer0.orgorderer1/msp/tlscacerts/tlsca.orgorderer1-cert.pem -C "orgchannel" -n orgcc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.member','Org2MSP.member')"
## Invoke Transaction: Transfer $10 from 'a' to 'b'
peer chaincode invoke -o orderer0.orgorderer1:7050 --logging-level DEBUG --tls true --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/orgorderer1/orderers/orderer0.orgorderer1/msp/tlscacerts/tlsca.orgorderer1-cert.pem -C "orgchannel" -n orgcc --peerAddresses peer0.org1:7051 --tlsRootCertFiles /etc/hyperledger/fabric/crypto-config/peerOrganizations/org1/peers/peer0.org1/tls/ca.crt --peerAddresses peer0.org2:7051 --tlsRootCertFiles /etc/hyperledger/fabric/crypto-config/peerOrganizations/org2/peers/peer0.org2/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'
## Query value of 'a'
peer chaincode query -C "orgchannel" -n orgcc -c '{"Args":["query","a"]}'
## Query value of 'b'
peer chaincode query -C "orgchannel" -n orgcc -c '{"Args":["query","b"]}'
-------------------------------------------------------------------------------------------------------
# Org2 CLI: Query chaincode on Peer0 of Org2
export CORE_PEER_ADDRESS=peer0.org2:7051
## Query value of 'a'
peer chaincode query -C "orgchannel" -n orgcc -c '{"Args":["query","a"]}'
## Query value of 'b'
peer chaincode query -C "orgchannel" -n orgcc -c '{"Args":["query","b"]}'