fabric2.0-Alpha FabToken示例

下载镜像一定要是2.0.0-alpha版本的。
可用如下方式:

curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.0.0-alpha 2.0.0-alpha 0.4.15

详见https://hyperledger-fabric.readthedocs.io/en/latest/install.html

wang@wang:~/go/src/github.com/hyperledger/fabric/scripts$ curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.0.0-alpha 2.0.0-alpha 0.4.15
wang@wang:~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network$ ./byfn.sh generate
Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] 
proceeding ...
/home/wang/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/../bin/cryptogen

##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
+ cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com
+ res=0
+ set +x

/home/wang/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/../bin/configtxgen
##########################################################
#########  Generating Orderer Genesis block ##############
##########################################################
CONSENSUS_TYPE=solo
+ '[' solo == solo ']'
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2019-06-14 10:34:24.027 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-06-14 10:34:24.177 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2019-06-14 10:34:24.177 CST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /home/wang/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-06-14 10:34:24.306 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2019-06-14 10:34:24.306 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /home/wang/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-06-14 10:34:24.308 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2019-06-14 10:34:24.309 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block
+ res=0
+ set +x

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
2019-06-14 10:34:24.362 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-06-14 10:34:24.474 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/wang/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-06-14 10:34:24.586 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-06-14 10:34:24.586 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/wang/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-06-14 10:34:24.586 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2019-06-14 10:34:24.589 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 006 Writing new channel tx
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org1MSP   ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2019-06-14 10:34:24.641 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-06-14 10:34:24.755 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/wang/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-06-14 10:34:24.877 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-06-14 10:34:24.877 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/wang/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-06-14 10:34:24.877 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-06-14 10:34:24.880 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org2MSP   ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
2019-06-14 10:34:24.927 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-06-14 10:34:25.044 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/wang/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-06-14 10:34:25.175 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-06-14 10:34:25.176 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/wang/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-06-14 10:34:25.176 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-06-14 10:34:25.190 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x

在crppto-config目录下添加三个文件,文件名和内容如下:

wang@wang:~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/crypto-config$ cat configorg1.json 
{
  "ChannelID":"",
  "MSPInfo":{
    "MSPConfigPath":"",
    "MSPID":"Org1MSP",
    "MSPType":"bccsp"
  },
  "Orderer":{
    "Address":"orderer.example.com:7050",
    "ConnectionTimeout":0,
    "TLSEnabled":true,
    "TLSRootCertFile":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem",
    "ServerNameOverride":""
  },
  "CommitterPeer":{
    "Address":"peer0.org1.example.com:7051",
    "ConnectionTimeout":0,
    "TLSEnabled":true,
    "TLSRootCertFile":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt",
    "ServerNameOverride":""
  },
  "ProverPeer":{
    "Address":"peer0.org1.example.com:7051",
    "ConnectionTimeout":0,
    "TLSEnabled":true,
    "TLSRootCertFile":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt",
    "ServerNameOverride":""
  }
}
wang@wang:~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/crypto-config$ cat configorg2.json 
{
  "ChannelID":"",
  "MSPInfo":{
    "MSPConfigPath":"",
    "MSPID":"Org2MSP",
    "MSPType":"bccsp"
  },
  "Orderer":{
    "Address":"orderer.example.com:7050",
    "ConnectionTimeout":0,
    "TLSEnabled":true,
    "TLSRootCertFile":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem",
    "ServerNameOverride":""
  },
  "CommitterPeer":{
    "Address":"peer0.org2.example.com:9051",
    "ConnectionTimeout":0,
    "TLSEnabled":true,
    "TLSRootCertFile":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt",
    "ServerNameOverride":""
  },
  "ProverPeer":{
    "Address":"peer0.org2.example.com:9051",
    "ConnectionTimeout":0,
    "TLSEnabled":true,
    "TLSRootCertFile":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt",
    "ServerNameOverride":""
  }
}
wang@wang:~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/crypto-config$ cat shares.json 
[
    {
    "recipient":"Org2MSP:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp",
    "quantity":"50"
    }
]

wang@wang:~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network$ ./byfn.sh up
Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] 
proceeding ...
LOCAL_VERSION=2.0.0
DOCKER_IMAGE_VERSION=2.0.0-alpha
=================== WARNING ===================
  Local fabric binaries and docker images are  
  out of  sync. This may cause problems.       
===============================================
Creating network "net_byfn" with the default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating volume "net_peer1.org2.example.com" with default driver
Creating volume "net_peer1.org1.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_orderer.example.com" with default driver
Creating peer0.org2.example.com
Creating peer0.org1.example.com
Creating orderer.example.com
Creating peer1.org1.example.com
Creating peer1.org2.example.com
Creating cli
CONTAINER ID        IMAGE                               COMMAND             CREATED             STATUS                  PORTS                                NAMES
dee877e372c5        hyperledger/fabric-tools:latest     "/bin/bash"         2 seconds ago       Up Less than a second                                        cli
9559697beb8d        hyperledger/fabric-peer:latest      "peer node start"   5 seconds ago       Up 1 second             7051/tcp, 0.0.0.0:10051->10051/tcp   peer1.org2.example.com
6e728c2ad12a        hyperledger/fabric-orderer:latest   "orderer"           5 seconds ago       Up 3 seconds            0.0.0.0:7050->7050/tcp               orderer.example.com
e367d9ae4596        hyperledger/fabric-peer:latest      "peer node start"   5 seconds ago       Up 1 second             7051/tcp, 0.0.0.0:8051->8051/tcp     peer1.org1.example.com
4c11010f72f3        hyperledger/fabric-peer:latest      "peer node start"   5 seconds ago       Up 3 seconds            0.0.0.0:7051->7051/tcp               peer0.org1.example.com
1d7a7ddffa67        hyperledger/fabric-peer:latest      "peer node start"   5 seconds ago       Up 1 second             7051/tcp, 0.0.0.0:9051->9051/tcp     peer0.org2.example.com

 ____    _____      _      ____    _____ 
/ ___|  |_   _|    / \    |  _ \  |_   _|
\___ \    | |     / _ \   | |_) |   | |  
 ___) |   | |    / ___ \  |  _ <    | |  
|____/    |_|   /_/   \_\ |_| \_\   |_|  

Build your first network (BYFN) end-to-end test

Channel name : mychannel
Creating channel...
+ peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --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
+ res=0
+ set +x
+ peer channel join -b mychannel.block
2019-06-14 02:38:14.331 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-06-14 02:38:14.467 UTC [cli.common] readBlock -> INFO 002 Received block: 0
===================== Channel 'mychannel' created ===================== 

Having all peers join the channel...
+ res=0
+ set +x
2019-06-14 02:38:14.634 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-06-14 02:38:14.829 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org1 joined channel 'mychannel' ===================== 

+ peer channel join -b mychannel.block
+ res=0
+ set +x
2019-06-14 02:38:18.011 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-06-14 02:38:18.084 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org1 joined channel 'mychannel' ===================== 

+ peer channel join -b mychannel.block
+ res=0
+ set +x
2019-06-14 02:38:21.225 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-06-14 02:38:21.318 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org2 joined channel 'mychannel' ===================== 

+ peer channel join -b mychannel.block
+ res=0
+ set +x
2019-06-14 02:38:24.421 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-06-14 02:38:24.580 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org2 joined channel 'mychannel' ===================== 

Updating anchor peers for org1...
+ peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --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
+ res=0
+ set +x
2019-06-14 02:38:27.708 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-06-14 02:38:27.733 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org1MSP' on channel 'mychannel' ===================== 

Updating anchor peers for org2...
+ peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --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
+ res=0
+ set +x
2019-06-14 02:38:30.848 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-06-14 02:38:30.864 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org2MSP' on channel 'mychannel' ===================== 

+ peer lifecycle chaincode package mycc.tar.gz --path github.com/hyperledger/fabric-samples/chaincode/abstore/go/ --lang golang --label mycc_1
+ res=0
+ set +x
===================== Chaincode is packaged on peer0.org1 ===================== 

Installing chaincode on peer0.org1...
+ peer lifecycle chaincode install mycc.tar.gz
+ res=0
+ set +x
2019-06-14 02:38:35.504 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nGmycc_1:1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca\022\006mycc_1" > 
2019-06-14 02:38:35.504 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc_1:1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca
===================== Chaincode is installed on peer0.org1 ===================== 

Install chaincode on peer0.org2...
+ peer lifecycle chaincode install mycc.tar.gz
+ res=0
+ set +x
2019-06-14 02:38:35.652 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nGmycc_1:1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca\022\006mycc_1" > 
2019-06-14 02:38:35.652 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc_1:1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca
===================== Chaincode is installed on peer0.org2 ===================== 

+ peer lifecycle chaincode queryinstalled
+ res=0
+ set +x
Installed chaincodes on peer:
Package ID: mycc_1:1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca, Label: mycc_1
PackageID is mycc_1:1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca
===================== Query installed successful on peer0.org1 on channel ===================== 

+ peer lifecycle chaincode approveformyorg --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 --channelID mychannel --name mycc --version 1 --init-required --package-id mycc_1:1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca --sequence 1 --waitForEvent
+ set +x
2019-06-14 02:38:35.882 UTC [cli.lifecycle.chaincode] setOrdererClient -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
2019-06-14 02:38:38.000 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [1c6724474101538907bcc57859103c696352c58ab5050027de4e45b18715ff89] committed with status (VALID) at 
===================== Chaincode definition approved on peer0.org1 on channel 'mychannel' ===================== 

===================== Querying approval status on peer0.org1 on channel 'mychannel'... ===================== 
Attempting to Query approval status on peer0.org1 ...3 secs
+ peer lifecycle chaincode queryapprovalstatus --channelID mychannel --name mycc --version 1 --sequence 1 --init-required
+ res=0
+ set +x

{
	"Approved": {
		"Org1MSP": true,
		"Org2MSP": false
	}
}
===================== Query approval status successful on peer0.org1 on channel 'mychannel' ===================== 
===================== Querying approval status on peer0.org2 on channel 'mychannel'... ===================== 
Attempting to Query approval status on peer0.org2 ...3 secs
+ peer lifecycle chaincode queryapprovalstatus --channelID mychannel --name mycc --version 1 --sequence 1 --init-required
+ res=0
+ set +x

{
	"Approved": {
		"Org1MSP": true,
		"Org2MSP": false
	}
}
===================== Query approval status successful on peer0.org2 on channel 'mychannel' ===================== 
+ peer lifecycle chaincode approveformyorg --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 --channelID mychannel --name mycc --version 1 --init-required --package-id mycc_1:1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca --sequence 1 --waitForEvent
+ set +x
2019-06-14 02:38:44.431 UTC [cli.lifecycle.chaincode] setOrdererClient -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
2019-06-14 02:38:46.509 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [bc2b7c70a12b0ea098755be5a7d3a9e91c74cac86c540860a35572936bb8c853] committed with status (VALID) at 
===================== Chaincode definition approved on peer0.org2 on channel 'mychannel' ===================== 

===================== Querying approval status on peer0.org1 on channel 'mychannel'... ===================== 
Attempting to Query approval status on peer0.org1 ...3 secs
+ peer lifecycle chaincode queryapprovalstatus --channelID mychannel --name mycc --version 1 --sequence 1 --init-required
+ res=0
+ set +x

{
	"Approved": {
		"Org1MSP": true,
		"Org2MSP": true
	}
}
===================== Query approval status successful on peer0.org1 on channel 'mychannel' ===================== 
===================== Querying approval status on peer0.org2 on channel 'mychannel'... ===================== 
+ peer lifecycle chaincode queryapprovalstatus --channelID mychannel --name mycc --version 1 --sequence 1 --init-required
Attempting to Query approval status on peer0.org2 ...3 secs
+ res=0
+ set +x

{
	"Approved": {
		"Org1MSP": true,
		"Org2MSP": true
	}
}
===================== Query approval status successful on peer0.org2 on channel 'mychannel' ===================== 
+ peer lifecycle chaincode commit -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 --channelID mychannel --name 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 --version 1 --sequence 1 --init-required
+ res=0
+ set +x
2019-06-14 02:38:55.000 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [fc6c46f386d8417e1f0ac1adb372705dcde1294978bbb9527adec0633a4f2810] committed with status (VALID) at peer0.org1.example.com:7051
2019-06-14 02:38:55.006 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [fc6c46f386d8417e1f0ac1adb372705dcde1294978bbb9527adec0633a4f2810] committed with status (VALID) at peer0.org2.example.com:9051
===================== Chaincode definition committed on channel 'mychannel' ===================== 

===================== Querying chaincode definition on peer0.org1 on channel 'mychannel'... ===================== 
Attempting to Query committed status on peer0.org1 ...3 secs
+ peer lifecycle chaincode querycommitted --channelID mychannel --name mycc
+ res=0
+ set +x

Committed chaincode definition for chaincode 'mycc' on channel 'mychannel':
Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc
===================== Query chaincode definition successful on peer0.org1 on channel 'mychannel' ===================== 
===================== Querying chaincode definition on peer0.org2 on channel 'mychannel'... ===================== 
Attempting to Query committed status on peer0.org2 ...3 secs
+ peer lifecycle chaincode querycommitted --channelID mychannel --name mycc
+ res=0
+ set +x

Committed chaincode definition for chaincode 'mycc' on channel 'mychannel':
Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc
===================== Query chaincode definition successful on peer0.org2 on channel 'mychannel' ===================== 
+ 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 mychannel -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 --isInit -c '{"Args":["Init","a","100","b","100"]}'
+ res=0
+ set +x
2019-06-14 02:39:46.080 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' ===================== 

Querying chaincode on peer0.org1...
===================== Querying on peer0.org1 on channel 'mychannel'... ===================== 
Attempting to Query peer0.org1 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x

100
===================== Query successful on peer0.org1 on channel 'mychannel' ===================== 
Sending invoke transaction on peer0.org1 peer0.org2...
+ 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 mychannel -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"]}'
+ res=0
+ set +x
2019-06-14 02:39:49.469 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' ===================== 

Querying chaincode on peer0.org1...
===================== Querying on peer0.org1 on channel 'mychannel'... ===================== 
Attempting to Query peer0.org1 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x

90
===================== Query successful on peer0.org1 on channel 'mychannel' ===================== 
Installing chaincode on peer1.org2...
+ peer lifecycle chaincode install mycc.tar.gz
+ res=0
+ set +x
2019-06-14 02:39:52.696 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nGmycc_1:1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca\022\006mycc_1" > 
2019-06-14 02:39:52.696 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc_1:1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca
===================== Chaincode is installed on peer1.org2 ===================== 

Querying chaincode on peer1.org2...
===================== Querying on peer1.org2 on channel 'mychannel'... ===================== 
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
Attempting to Query peer1.org2 ...3 secs
+ res=0
+ set +x

90
===================== Query successful on peer1.org2 on channel 'mychannel' ===================== 

========= All GOOD, BYFN execution completed =========== 


 _____   _   _   ____   
| ____| | \ | | |  _ \  
|  _|   |  \| | | | | | 
| |___  | |\  | | |_| | 
|_____| |_| \_| |____/  
wang@wang:~$ docker ps
CONTAINER ID        IMAGE                                                                                                                                                                 COMMAND                  CREATED             STATUS              PORTS                                NAMES
bbb5164dbb7f        dev-peer1.org2.example.com-mycc_1-1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca-1222d5a6635a9fe59ad1321e9753056bef76513553c287afe7ab9321176e5b65   "chaincode -peer.add…"   10 seconds ago      Up 8 seconds                                             dev-peer1.org2.example.com-mycc_1-1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca
922d37a97f37        dev-peer0.org2.example.com-mycc_1-1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca-c50a49050fd4b7d05c4bb3204402bf8a17a3a66974c17e8cee8d6e143e50897d   "chaincode -peer.add…"   36 seconds ago      Up 35 seconds                                            dev-peer0.org2.example.com-mycc_1-1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca
4fe2da11cc02        dev-peer0.org1.example.com-mycc_1-1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca-fca5e874ffcc1d19426c72370a690c69807a303abf6c23b788bb5f98a2e82d34   "chaincode -peer.add…"   55 seconds ago      Up 53 seconds                                            dev-peer0.org1.example.com-mycc_1-1a5cee241429a822f8b7282a9d196217e54efcc49e122d8675dfca2e20ef82ca
dee877e372c5        hyperledger/fabric-tools:latest                                                                                                                                       "/bin/bash"              2 minutes ago       Up 2 minutes                                             cli
9559697beb8d        hyperledger/fabric-peer:latest                                                                                                                                        "peer node start"        2 minutes ago       Up 2 minutes        7051/tcp, 0.0.0.0:10051->10051/tcp   peer1.org2.example.com
6e728c2ad12a        hyperledger/fabric-orderer:latest                                                                                                                                     "orderer"                2 minutes ago       Up 2 minutes        0.0.0.0:7050->7050/tcp               orderer.example.com
e367d9ae4596        hyperledger/fabric-peer:latest                                                                                                                                        "peer node start"        2 minutes ago       Up 2 minutes        7051/tcp, 0.0.0.0:8051->8051/tcp     peer1.org1.example.com
4c11010f72f3        hyperledger/fabric-peer:latest                                                                                                                                        "peer node start"        2 minutes ago       Up 2 minutes        0.0.0.0:7051->7051/tcp               peer0.org1.example.com
1d7a7ddffa67        hyperledger/fabric-peer:latest                                                                                                                                        "peer node start"        2 minutes ago       Up 2 minutes        7051/tcp, 0.0.0.0:9051->9051/tcp     peer0.org2.example.com
wang@wang:~$ docker exec -it cli bash
bash-4.4# ls
channel-artifacts  log.txt            mychannel.block
crypto             mycc.tar.gz        scripts
bash-4.4# which token
/usr/local/bin/token

//以org1 admin的身份发行100个coins,user1org1则是coin的拥有者
bash-4.4# token issue --config /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg1.json --mspPath /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp --channel mychannel --type BYFNcoins --quantity 100 --recipient Org1MSP:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
Orderer Status [SUCCESS]
Committed [true]

查看发行的tokens:
tokenid即产生token的tx_id。
token类型:BYFNcoins
token数量:100

bash-4.4# token list --config /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg1.json --mspPath /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp --channel mychannel
{"tx_id":"12ebd44208c7864445c26113c9cd8521854dcf9a02fdc441650822e594664f24"}
[BYFNcoins,100]

transfer coins:
user1org1给user1org2 50个coins,50这个数量来自shares文件。
注意下面的tx_id一项来自上面的tx_id,用tokenIDs falg进行transfer。

bash-4.4# token transfer --config /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg1.json --mspPath /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp --channel mychannel --tokenIDs '[{"tx_id":"12ebd44208c7864445c26113c9cd8521854dcf9a02fdc441650822e594664f24"}]' --shares /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/shares.json
Orderer Status [SUCCESS]
Committed [true]

看下user1org1还剩多少coins:

bash-4.4# token list --config /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg1.json --mspPath /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp --channel mychannel
{"tx_id":"f3b597e30d7b7949c029a5fc4d3eec164e6897b127620250a9e889dba5df7629","index":1}
[BYFNcoins,50]

看下user1org2有多少coins:

bash-4.4# token list --config /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg2.json --mspPath /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp --channel mychannel
{"tx_id":"f3b597e30d7b7949c029a5fc4d3eec164e6897b127620250a9e889dba5df7629"}
[BYFNcoins,50]

从user1org2赎回25个coins,下面的tx_id来自上面:

bash-4.4# token redeem --config /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg2.json --mspPath /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp --channel mychannel  --tokenIDs '[{"tx_id":"f3b597e30d7b7949c029a5fc4d3eec164e6897b127620250a9e889dba5df7629"}]' --quantity 25
Orderer Status [SUCCESS]
Committed [true]

查看user1org2还剩多少coins:

bash-4.4# token list --config /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg2.json --mspPath /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp --channel mychannel
{"tx_id":"befa5705f3aab00efeb9deb935a2bb1e01c6dd8d1b7843e9902043a2ac0c3eaf","index":1}
[BYFNcoins,25]

查看user1org1有多少coins:

bash-4.4# token list --config /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg1.json --mspPath /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp --channel mychannel
{"tx_id":"f3b597e30d7b7949c029a5fc4d3eec164e6897b127620250a9e889dba5df7629","index":1}
[BYFNcoins,50]

从user1org1赎回20个coins:

bash-4.4# token redeem --config /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg1.json --mspPath /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp --channel mychannel  --tokenIDs '[{"tx_id":"f3b597e30d7b7949c029a5fc4d3eec164e6897b127620250a9e889dba5df7629","index":1}]' --quantity 20
Orderer Status [SUCCESS]
Committed [true]

查看user1org1还剩多少:

bash-4.4# token list --config /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg1.json --mspPath /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp --channel mychannel
{"tx_id":"098122db6e9193464570ee122c37f20491b61c202edae396992e1bcb25cf9528","index":1}
[BYFNcoins,30]

查看user1org2有没变化:

bash-4.4# token list --config /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg2.json --mspPath /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp --channel mychannel
{"tx_id":"befa5705f3aab00efeb9deb935a2bb1e01c6dd8d1b7843e9902043a2ac0c3eaf","index":1}
[BYFNcoins,25]

以org2的身份从user1org1赎回10个:

bash-4.4# token redeem --config /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg2.json --mspPath /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp --channel mychannel  --tokenIDs '[{"tx_id":"098122db6e9193464570ee122c37f20491b61c202edae396992e1bcb25cf9528","index":1}]' --quantity 10
error from prover: input TokenId (098122db6e9193464570ee122c37f20491b61c202edae396992e1bcb25cf9528, 1) does not exist or not owned by the user

https://hyperledger-fabric.readthedocs.io/en/latest/token/FabToken.html#fabtoken-example

猜你喜欢

转载自blog.csdn.net/u010931295/article/details/91876310