Home | 简体中文 | 繁体中文 | 杂文 | 知乎专栏 | Github | OSChina 博客 | 云社区 | 云栖社区 | Facebook | Linkedin | 视频教程 | 打赏(Donations) | About
知乎专栏多维度架构微信号 netkiller-ebook | QQ群:128659835 请注明“读者”

第 26 章 Chaincode 链码(智能合约)

目录

26.1. 链码开发与测试
26.1.1. Docker 开发环境
26.1.2. chaincode 代码
26.1.3. 启动容器部署chaincode
26.1.4. 手工测试
26.1.5. 代码测试
26.1.6. 在宿主主机上编译合约
26.1.7. 链码升级
26.2. Chaincode 结构
26.2.1. 包
26.2.2. 导入库
26.2.3. 定义类
26.2.4. Init 方法
26.2.5. Query
26.2.6. Invoke
26.2.7. func main()
26.3. shim.ChaincodeStubInterface 接口
26.3.1. State 数据库曾,删,查 操作
26.3.1.1. PutState(key, value)写入区块
26.3.1.2. GetState(key) 读取区块
26.3.1.3. DelState(key) 删除区块
26.3.1.4. 修改数据
26.3.1.5. GetStateByRange(startKey, endKey) 范围查找
26.3.1.6. GetQueryResult(query string) CouchDB 查询
26.3.1.7. stub.GetHistoryForKey
26.3.1.8. shim.HistoryQueryIteratorInterface 接口
26.3.2. 复合键
26.3.2.1. 创建复合键
26.3.2.2. 分解复合键
26.3.3. stub.SetEvent(key, value) 事件
26.3.4. 调用其他链码
26.3.5. stub.GetCreator() 获得证书资料
26.4. 链码案例
26.4.1. 模仿以太坊 ERC20 规范的 Hyperledger Fabric 实现 Token 通证
26.4.2. 万能的通用合约

26.1. 链码开发与测试

26.1.1. Docker 开发环境

环境安装

安装 fabric-samples

			
git clone https://github.com/hyperledger/fabric-samples.git
cd fabric-samples
			
			
			
[root@localhost ~]# cd fabric-samples/chaincode-docker-devmode/
[root@localhost chaincode-docker-devmode]# mkdir chaincode
[root@localhost chaincode-docker-devmode]# cp docker-compose-simple.yaml docker-compose.yaml
[root@localhost chaincode-docker-devmode]# sed -i "s|./../chaincode|./chaincode|g" docker-compose.yaml
			
			

chaincode 目录是开发目录

清理镜像和容器

		
docker rm -f $(docker ps -q -a)
docker rmi -f $(docker images -q)
		
			

安装所需镜像

		
[root@localhost chaincode-docker-devmode]# curl -s https://raw.githubusercontent.com/oscm/shell/master/blockchain/hyperledger/fabric/1.1.0/all-in-one.sh | bash		

[root@localhost chaincode-docker-devmode]# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
hyperledger/fabric-tools     latest              6a8993b718c8        2 months ago        1.33GB
hyperledger/fabric-tools     x86_64-1.1.0        6a8993b718c8        2 months ago        1.33GB
hyperledger/fabric-couchdb   latest              9a58db2d2723        2 months ago        1.5GB
hyperledger/fabric-couchdb   x86_64-1.1.0        9a58db2d2723        2 months ago        1.5GB
hyperledger/fabric-orderer   latest              368c78b6f03b        2 months ago        151MB
hyperledger/fabric-orderer   x86_64-1.1.0        368c78b6f03b        2 months ago        151MB
hyperledger/fabric-peer      latest              c2ab022f0bdb        2 months ago        154MB
hyperledger/fabric-peer      x86_64-1.1.0        c2ab022f0bdb        2 months ago        154MB
hyperledger/fabric-ccenv     latest              33feadb8f7a6        2 months ago        1.28GB
hyperledger/fabric-ccenv     x86_64-1.1.0        33feadb8f7a6        2 months ago        1.28GB
hyperledger/fabric-ca        latest              002c9089e464        2 months ago        238MB
hyperledger/fabric-ca        x86_64-1.1.0        002c9089e464        2 months ago        238MB		
		
			

26.1.2. chaincode 代码

		
[root@localhost chaincode-docker-devmode]# cat chaincode/chaincode_example02.go 
/*
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)
	}
}
		
			

26.1.3. 启动容器部署chaincode

		
[root@localhost chaincode-docker-devmode]# docker-compose up -d
		
			

进入容器

		
[root@localhost ~]# docker exec -it chaincode bash
root@78d23b3b2b37:/opt/gopath/src/chaincode# 		
		
			

编译并部署chaincode

		
root@78d23b3b2b37:/opt/gopath/src/chaincode# ls
chaincode_example02.go
root@78d23b3b2b37:/opt/gopath/src/chaincode# go build chaincode_example02.go 
root@78d23b3b2b37:/opt/gopath/src/chaincode# 		
		
			

进入 chaincode 容器启动 chaincode 程序。

		
[root@localhost ~]# docker exec -it chaincode bash
root@78d23b3b2b37:/opt/gopath/src/chaincode# ls
chaincode_example02.go
root@78d23b3b2b37:/opt/gopath/src/chaincode# go build chaincode_example02.go 
root@78d23b3b2b37:/opt/gopath/src/chaincode# CORE_PEER_ADDRESS=peer:7051 CORE_CHAINCODE_ID_NAME=chaincode_example02:1.0 ./chaincode_example02 
2018-02-17 04:07:31.156 UTC [shim] SetupChaincodeLogging -> INFO 001 Chaincode log level not provided; defaulting to: INFO
2018-02-17 04:07:31.156 UTC [shim] SetupChaincodeLogging -> INFO 002 Chaincode (build level: ) starting up ...		
		
			

CORE_CHAINCODE_ID_NAME=chaincode_example02:1.0 记住这里的配置,下面会用到

26.1.4. 手工测试

进入 cli 容器

		
[root@localhost ~]# docker exec -it cli bash
root@33dcacfb6f81:/opt/gopath/src/chaincodedev#		
		
			
		
root@33dcacfb6f81:/opt/gopath/src/chaincodedev# peer chaincode install -v 1.0 -n chaincode_example02 -p chaincodedev/chaincode	
2018-02-17 04:46:23.871 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-02-17 04:46:23.871 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-02-17 04:46:23.872 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-02-17 04:46:23.872 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-02-17 04:46:23.986 UTC [golang-platform] getCodeFromFS -> DEBU 005 getCodeFromFS chaincodedev/chaincode
2018-02-17 04:46:24.280 UTC [golang-platform] func1 -> DEBU 006 Discarding GOROOT package fmt
2018-02-17 04:46:24.281 UTC [golang-platform] func1 -> DEBU 007 Discarding provided package github.com/hyperledger/fabric/core/chaincode/shim
2018-02-17 04:46:24.281 UTC [golang-platform] func1 -> DEBU 008 Discarding provided package github.com/hyperledger/fabric/protos/peer
2018-02-17 04:46:24.281 UTC [golang-platform] func1 -> DEBU 009 Discarding GOROOT package strconv
2018-02-17 04:46:24.281 UTC [golang-platform] GetDeploymentPayload -> DEBU 00a done
2018-02-17 04:46:24.287 UTC [msp/identity] Sign -> DEBU 00b Sign: plaintext: 0AA4080A5C08031A0C08A0E79ED40510...0F19FF0E0000FFFFBA10C104001C0000 
2018-02-17 04:46:24.287 UTC [msp/identity] Sign -> DEBU 00c Sign: digest: BE51F2BBE156552DDF4CCBA3E01F890921FB965463683B0B636DAC53BAF2E7C4 
2018-02-17 04:46:24.299 UTC [chaincodeCmd] install -> DEBU 00d Installed remotely response:<status:200 payload:"OK" > 
2018-02-17 04:46:24.299 UTC [main] main -> INFO 00e Exiting.....		
		
			
		
root@33dcacfb6f81:/opt/gopath/src/chaincodedev# peer chaincode instantiate -C myc -n chaincode_example02 -v 1.0 -c '{"Args":["init","a","100","b","200"]}'  
2018-02-17 04:52:42.395 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-02-17 04:52:42.396 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-02-17 04:52:42.396 UTC [msp/identity] Sign -> DEBU 003 Sign: plaintext: 0AA4080A5C08011A0C089AEA9ED40510...436F6E666967426C6F636B0A036D7963 
2018-02-17 04:52:42.396 UTC [msp/identity] Sign -> DEBU 004 Sign: digest: B2BE9C220FB3313901DBAAE578F428FB98B950ACB5E7519DBC5150D2D21562CB 
2018-02-17 04:52:42.413 UTC [common/config] NewStandardValues -> DEBU 005 Initializing protos for *config.ChannelProtos
2018-02-17 04:52:42.414 UTC [common/config] initializeProtosStruct -> DEBU 006 Processing field: HashingAlgorithm
2018-02-17 04:52:42.414 UTC [common/config] initializeProtosStruct -> DEBU 007 Processing field: BlockDataHashingStructure
2018-02-17 04:52:42.414 UTC [common/config] initializeProtosStruct -> DEBU 008 Processing field: OrdererAddresses
2018-02-17 04:52:42.414 UTC [common/config] initializeProtosStruct -> DEBU 009 Processing field: Consortium
2018-02-17 04:52:42.415 UTC [common/configtx] addToMap -> DEBU 00a Adding to config map: [Groups] /Channel
2018-02-17 04:52:42.415 UTC [common/configtx] addToMap -> DEBU 00b Adding to config map: [Groups] /Channel/Orderer
2018-02-17 04:52:42.415 UTC [common/configtx] addToMap -> DEBU 00c Adding to config map: [Groups] /Channel/Orderer/SampleOrg
2018-02-17 04:52:42.415 UTC [common/configtx] addToMap -> DEBU 00d Adding to config map: [Values] /Channel/Orderer/SampleOrg/MSP
2018-02-17 04:52:42.415 UTC [common/configtx] addToMap -> DEBU 00e Adding to config map: [Policy] /Channel/Orderer/SampleOrg/Admins
2018-02-17 04:52:42.416 UTC [common/configtx] addToMap -> DEBU 00f Adding to config map: [Policy] /Channel/Orderer/SampleOrg/Readers
2018-02-17 04:52:42.416 UTC [common/configtx] addToMap -> DEBU 010 Adding to config map: [Policy] /Channel/Orderer/SampleOrg/Writers
2018-02-17 04:52:42.416 UTC [common/configtx] addToMap -> DEBU 011 Adding to config map: [Values] /Channel/Orderer/BatchSize
2018-02-17 04:52:42.416 UTC [common/configtx] addToMap -> DEBU 012 Adding to config map: [Values] /Channel/Orderer/BatchTimeout
2018-02-17 04:52:42.416 UTC [common/configtx] addToMap -> DEBU 013 Adding to config map: [Values] /Channel/Orderer/ChannelRestrictions
2018-02-17 04:52:42.417 UTC [common/configtx] addToMap -> DEBU 014 Adding to config map: [Values] /Channel/Orderer/ConsensusType
2018-02-17 04:52:42.418 UTC [common/configtx] addToMap -> DEBU 015 Adding to config map: [Policy] /Channel/Orderer/Admins
2018-02-17 04:52:42.419 UTC [common/configtx] addToMap -> DEBU 016 Adding to config map: [Policy] /Channel/Orderer/BlockValidation
2018-02-17 04:52:42.419 UTC [common/configtx] addToMap -> DEBU 017 Adding to config map: [Policy] /Channel/Orderer/Readers
2018-02-17 04:52:42.419 UTC [common/configtx] addToMap -> DEBU 018 Adding to config map: [Policy] /Channel/Orderer/Writers
2018-02-17 04:52:42.419 UTC [common/configtx] addToMap -> DEBU 019 Adding to config map: [Groups] /Channel/Application
2018-02-17 04:52:42.420 UTC [common/configtx] addToMap -> DEBU 01a Adding to config map: [Groups] /Channel/Application/SampleOrg
2018-02-17 04:52:42.420 UTC [common/configtx] addToMap -> DEBU 01b Adding to config map: [Values] /Channel/Application/SampleOrg/MSP
2018-02-17 04:52:42.422 UTC [common/configtx] addToMap -> DEBU 01c Adding to config map: [Policy] /Channel/Application/SampleOrg/Readers
2018-02-17 04:52:42.422 UTC [common/configtx] addToMap -> DEBU 01d Adding to config map: [Policy] /Channel/Application/SampleOrg/Writers
2018-02-17 04:52:42.422 UTC [common/configtx] addToMap -> DEBU 01e Adding to config map: [Policy] /Channel/Application/SampleOrg/Admins
2018-02-17 04:52:42.422 UTC [common/configtx] addToMap -> DEBU 01f Adding to config map: [Policy] /Channel/Application/Writers
2018-02-17 04:52:42.423 UTC [common/configtx] addToMap -> DEBU 020 Adding to config map: [Policy] /Channel/Application/Readers
2018-02-17 04:52:42.423 UTC [common/configtx] addToMap -> DEBU 021 Adding to config map: [Policy] /Channel/Application/Admins
2018-02-17 04:52:42.423 UTC [common/configtx] addToMap -> DEBU 022 Adding to config map: [Values] /Channel/Consortium
2018-02-17 04:52:42.423 UTC [common/configtx] addToMap -> DEBU 023 Adding to config map: [Values] /Channel/OrdererAddresses
2018-02-17 04:52:42.423 UTC [common/configtx] addToMap -> DEBU 024 Adding to config map: [Values] /Channel/HashingAlgorithm
2018-02-17 04:52:42.424 UTC [common/configtx] addToMap -> DEBU 025 Adding to config map: [Values] /Channel/BlockDataHashingStructure
2018-02-17 04:52:42.424 UTC [common/configtx] addToMap -> DEBU 026 Adding to config map: [Policy] /Channel/Readers
2018-02-17 04:52:42.424 UTC [common/configtx] addToMap -> DEBU 027 Adding to config map: [Policy] /Channel/Writers
2018-02-17 04:52:42.424 UTC [common/configtx] addToMap -> DEBU 028 Adding to config map: [Policy] /Channel/Admins
2018-02-17 04:52:42.424 UTC [common/configtx] processConfig -> DEBU 029 Beginning new config for channel myc
2018-02-17 04:52:42.425 UTC [common/config] NewStandardValues -> DEBU 02a Initializing protos for *config.ChannelProtos
2018-02-17 04:52:42.425 UTC [common/config] initializeProtosStruct -> DEBU 02b Processing field: HashingAlgorithm
2018-02-17 04:52:42.425 UTC [common/config] initializeProtosStruct -> DEBU 02c Processing field: BlockDataHashingStructure
2018-02-17 04:52:42.425 UTC [common/config] initializeProtosStruct -> DEBU 02d Processing field: OrdererAddresses
2018-02-17 04:52:42.425 UTC [common/config] initializeProtosStruct -> DEBU 02e Processing field: Consortium
2018-02-17 04:52:42.425 UTC [policies] ProposePolicy -> DEBU 02f Proposed new policy Readers for Channel
2018-02-17 04:52:42.425 UTC [policies] ProposePolicy -> DEBU 030 Proposed new policy Writers for Channel
2018-02-17 04:52:42.426 UTC [policies] ProposePolicy -> DEBU 031 Proposed new policy Admins for Channel
2018-02-17 04:52:42.426 UTC [common/config] NewStandardValues -> DEBU 032 Initializing protos for *config.OrdererProtos
2018-02-17 04:52:42.426 UTC [common/config] initializeProtosStruct -> DEBU 033 Processing field: ConsensusType
2018-02-17 04:52:42.426 UTC [common/config] initializeProtosStruct -> DEBU 034 Processing field: BatchSize
2018-02-17 04:52:42.426 UTC [common/config] initializeProtosStruct -> DEBU 035 Processing field: BatchTimeout
2018-02-17 04:52:42.426 UTC [common/config] initializeProtosStruct -> DEBU 036 Processing field: KafkaBrokers
2018-02-17 04:52:42.426 UTC [common/config] initializeProtosStruct -> DEBU 037 Processing field: ChannelRestrictions
2018-02-17 04:52:42.426 UTC [policies] ProposePolicy -> DEBU 038 Proposed new policy Readers for Orderer
2018-02-17 04:52:42.426 UTC [policies] ProposePolicy -> DEBU 039 Proposed new policy Writers for Orderer
2018-02-17 04:52:42.426 UTC [policies] ProposePolicy -> DEBU 03a Proposed new policy Admins for Orderer
2018-02-17 04:52:42.426 UTC [policies] ProposePolicy -> DEBU 03b Proposed new policy BlockValidation for Orderer
2018-02-17 04:52:42.426 UTC [common/config] NewStandardValues -> DEBU 03c Initializing protos for *config.OrganizationProtos
2018-02-17 04:52:42.426 UTC [common/config] initializeProtosStruct -> DEBU 03d Processing field: MSP
2018-02-17 04:52:42.427 UTC [policies] ProposePolicy -> DEBU 03e Proposed new policy Admins for SampleOrg
2018-02-17 04:52:42.427 UTC [policies] ProposePolicy -> DEBU 03f Proposed new policy Readers for SampleOrg
2018-02-17 04:52:42.427 UTC [policies] ProposePolicy -> DEBU 040 Proposed new policy Writers for SampleOrg
2018-02-17 04:52:42.427 UTC [common/config] NewStandardValues -> DEBU 041 Initializing protos for *struct {}
2018-02-17 04:52:42.427 UTC [policies] ProposePolicy -> DEBU 042 Proposed new policy Admins for Application
2018-02-17 04:52:42.427 UTC [policies] ProposePolicy -> DEBU 043 Proposed new policy Writers for Application
2018-02-17 04:52:42.427 UTC [policies] ProposePolicy -> DEBU 044 Proposed new policy Readers for Application
2018-02-17 04:52:42.427 UTC [common/config] NewStandardValues -> DEBU 045 Initializing protos for *config.OrganizationProtos
2018-02-17 04:52:42.427 UTC [common/config] initializeProtosStruct -> DEBU 046 Processing field: MSP
2018-02-17 04:52:42.427 UTC [common/config] NewStandardValues -> DEBU 047 Initializing protos for *config.ApplicationOrgProtos
2018-02-17 04:52:42.427 UTC [common/config] initializeProtosStruct -> DEBU 048 Processing field: AnchorPeers
2018-02-17 04:52:42.427 UTC [common/config] NewStandardValues -> DEBU 049 Initializing protos for *config.OrganizationProtos
2018-02-17 04:52:42.428 UTC [common/config] initializeProtosStruct -> DEBU 04a Processing field: MSP
2018-02-17 04:52:42.428 UTC [policies] ProposePolicy -> DEBU 04b Proposed new policy Readers for SampleOrg
2018-02-17 04:52:42.428 UTC [policies] ProposePolicy -> DEBU 04c Proposed new policy Writers for SampleOrg
2018-02-17 04:52:42.428 UTC [policies] ProposePolicy -> DEBU 04d Proposed new policy Admins for SampleOrg
2018-02-17 04:52:42.428 UTC [common/config] validateMSP -> DEBU 04e Setting up MSP for org SampleOrg
2018-02-17 04:52:42.428 UTC [msp] NewBccspMsp -> DEBU 04f Creating BCCSP-based MSP instance
2018-02-17 04:52:42.428 UTC [msp] Setup -> DEBU 050 Setting up MSP instance DEFAULT
2018-02-17 04:52:42.429 UTC [msp/identity] newIdentity -> DEBU 051 Creating identity instance for ID -----BEGIN CERTIFICATE-----
MIICYjCCAgmgAwIBAgIUB3CTDOU47sUC5K4kn/Caqnh114YwCgYIKoZIzj0EAwIw
fzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
biBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK
BgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMTYxMDEyMTkzMTAw
WhcNMjExMDExMTkzMTAwWjB/MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv
cm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEfMB0GA1UEChMWSW50ZXJuZXQg
V2lkZ2V0cywgSW5jLjEMMAoGA1UECxMDV1dXMRQwEgYDVQQDEwtleGFtcGxlLmNv
bTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABKIH5b2JaSmqiQXHyqC+cmknICcF
i5AddVjsQizDV6uZ4v6s+PWiJyzfA/rTtMvYAPq/yeEHpBUB1j053mxnpMujYzBh
MA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBQXZ0I9
qp6CP8TFHZ9bw5nRtZxIEDAfBgNVHSMEGDAWgBQXZ0I9qp6CP8TFHZ9bw5nRtZxI
EDAKBggqhkjOPQQDAgNHADBEAiAHp5Rbp9Em1G/UmKn8WsCbqDfWecVbZPQj3RK4
oG5kQQIgQAe4OOKYhJdh3f7URaKfGTf492/nmRmtK+ySKjpHSrU=
-----END CERTIFICATE-----
2018-02-17 04:52:42.430 UTC [msp/identity] newIdentity -> DEBU 052 Creating identity instance for ID -----BEGIN CERTIFICATE-----
MIICjDCCAjKgAwIBAgIUBEVwsSx0TmqdbzNwleNBBzoIT0wwCgYIKoZIzj0EAwIw
fzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
biBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK
BgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMTYxMTExMTcwNzAw
WhcNMTcxMTExMTcwNzAwWjBjMQswCQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGgg
Q2Fyb2xpbmExEDAOBgNVBAcTB1JhbGVpZ2gxGzAZBgNVBAoTEkh5cGVybGVkZ2Vy
IEZhYnJpYzEMMAoGA1UECxMDQ09QMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE
HBuKsAO43hs4JGpFfiGMkB/xsILTsOvmN2WmwpsPHZNL6w8HWe3xCPQtdG/XJJvZ
+C756KEsUBM3yw5PTfku8qOBpzCBpDAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYw
FAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFOFC
dcUZ4es3ltiCgAVDoyLfVpPIMB8GA1UdIwQYMBaAFBdnQj2qnoI/xMUdn1vDmdG1
nEgQMCUGA1UdEQQeMByCCm15aG9zdC5jb22CDnd3dy5teWhvc3QuY29tMAoGCCqG
SM49BAMCA0gAMEUCIDf9Hbl4xn3z4EwNKmilM9lX2Fq4jWpAaRVB97OmVEeyAiEA
25aDPQHGGq2AvhKT0wvt08cX1GTGCIbfmuLpMwKQj38=
-----END CERTIFICATE-----
2018-02-17 04:52:42.432 UTC [msp/identity] newIdentity -> DEBU 053 Creating identity instance for ID -----BEGIN CERTIFICATE-----
MIICjDCCAjKgAwIBAgIUBEVwsSx0TmqdbzNwleNBBzoIT0wwCgYIKoZIzj0EAwIw
fzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
biBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK
BgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMTYxMTExMTcwNzAw
WhcNMTcxMTExMTcwNzAwWjBjMQswCQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGgg
Q2Fyb2xpbmExEDAOBgNVBAcTB1JhbGVpZ2gxGzAZBgNVBAoTEkh5cGVybGVkZ2Vy
IEZhYnJpYzEMMAoGA1UECxMDQ09QMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE
HBuKsAO43hs4JGpFfiGMkB/xsILTsOvmN2WmwpsPHZNL6w8HWe3xCPQtdG/XJJvZ
+C756KEsUBM3yw5PTfku8qOBpzCBpDAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYw
FAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFOFC
dcUZ4es3ltiCgAVDoyLfVpPIMB8GA1UdIwQYMBaAFBdnQj2qnoI/xMUdn1vDmdG1
nEgQMCUGA1UdEQQeMByCCm15aG9zdC5jb22CDnd3dy5teWhvc3QuY29tMAoGCCqG
SM49BAMCA0gAMEUCIDf9Hbl4xn3z4EwNKmilM9lX2Fq4jWpAaRVB97OmVEeyAiEA
25aDPQHGGq2AvhKT0wvt08cX1GTGCIbfmuLpMwKQj38=
-----END CERTIFICATE-----
2018-02-17 04:52:42.435 UTC [msp] Validate -> DEBU 054 MSP DEFAULT validating identity
2018-02-17 04:52:42.435 UTC [msp] getCertificationChain -> DEBU 055 MSP DEFAULT getting certification chain
2018-02-17 04:52:42.436 UTC [common/config] Validate -> DEBU 056 Anchor peers for org SampleOrg are 
2018-02-17 04:52:42.436 UTC [common/config] validateMSP -> DEBU 057 Setting up MSP for org SampleOrg
2018-02-17 04:52:42.436 UTC [msp] NewBccspMsp -> DEBU 058 Creating BCCSP-based MSP instance
2018-02-17 04:52:42.436 UTC [msp] Setup -> DEBU 059 Setting up MSP instance DEFAULT
2018-02-17 04:52:42.437 UTC [msp/identity] newIdentity -> DEBU 05a Creating identity instance for ID -----BEGIN CERTIFICATE-----
MIICYjCCAgmgAwIBAgIUB3CTDOU47sUC5K4kn/Caqnh114YwCgYIKoZIzj0EAwIw
fzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
biBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK
BgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMTYxMDEyMTkzMTAw
WhcNMjExMDExMTkzMTAwWjB/MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv
cm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEfMB0GA1UEChMWSW50ZXJuZXQg
V2lkZ2V0cywgSW5jLjEMMAoGA1UECxMDV1dXMRQwEgYDVQQDEwtleGFtcGxlLmNv
bTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABKIH5b2JaSmqiQXHyqC+cmknICcF
i5AddVjsQizDV6uZ4v6s+PWiJyzfA/rTtMvYAPq/yeEHpBUB1j053mxnpMujYzBh
MA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBQXZ0I9
qp6CP8TFHZ9bw5nRtZxIEDAfBgNVHSMEGDAWgBQXZ0I9qp6CP8TFHZ9bw5nRtZxI
EDAKBggqhkjOPQQDAgNHADBEAiAHp5Rbp9Em1G/UmKn8WsCbqDfWecVbZPQj3RK4
oG5kQQIgQAe4OOKYhJdh3f7URaKfGTf492/nmRmtK+ySKjpHSrU=
-----END CERTIFICATE-----
2018-02-17 04:52:42.438 UTC [msp/identity] newIdentity -> DEBU 05b Creating identity instance for ID -----BEGIN CERTIFICATE-----
MIICjDCCAjKgAwIBAgIUBEVwsSx0TmqdbzNwleNBBzoIT0wwCgYIKoZIzj0EAwIw
fzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
biBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK
BgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMTYxMTExMTcwNzAw
WhcNMTcxMTExMTcwNzAwWjBjMQswCQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGgg
Q2Fyb2xpbmExEDAOBgNVBAcTB1JhbGVpZ2gxGzAZBgNVBAoTEkh5cGVybGVkZ2Vy
IEZhYnJpYzEMMAoGA1UECxMDQ09QMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE
HBuKsAO43hs4JGpFfiGMkB/xsILTsOvmN2WmwpsPHZNL6w8HWe3xCPQtdG/XJJvZ
+C756KEsUBM3yw5PTfku8qOBpzCBpDAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYw
FAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFOFC
dcUZ4es3ltiCgAVDoyLfVpPIMB8GA1UdIwQYMBaAFBdnQj2qnoI/xMUdn1vDmdG1
nEgQMCUGA1UdEQQeMByCCm15aG9zdC5jb22CDnd3dy5teWhvc3QuY29tMAoGCCqG
SM49BAMCA0gAMEUCIDf9Hbl4xn3z4EwNKmilM9lX2Fq4jWpAaRVB97OmVEeyAiEA
25aDPQHGGq2AvhKT0wvt08cX1GTGCIbfmuLpMwKQj38=
-----END CERTIFICATE-----
2018-02-17 04:52:42.439 UTC [msp/identity] newIdentity -> DEBU 05c Creating identity instance for ID -----BEGIN CERTIFICATE-----
MIICjDCCAjKgAwIBAgIUBEVwsSx0TmqdbzNwleNBBzoIT0wwCgYIKoZIzj0EAwIw
fzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
biBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK
BgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMTYxMTExMTcwNzAw
WhcNMTcxMTExMTcwNzAwWjBjMQswCQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGgg
Q2Fyb2xpbmExEDAOBgNVBAcTB1JhbGVpZ2gxGzAZBgNVBAoTEkh5cGVybGVkZ2Vy
IEZhYnJpYzEMMAoGA1UECxMDQ09QMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE
HBuKsAO43hs4JGpFfiGMkB/xsILTsOvmN2WmwpsPHZNL6w8HWe3xCPQtdG/XJJvZ
+C756KEsUBM3yw5PTfku8qOBpzCBpDAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYw
FAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFOFC
dcUZ4es3ltiCgAVDoyLfVpPIMB8GA1UdIwQYMBaAFBdnQj2qnoI/xMUdn1vDmdG1
nEgQMCUGA1UdEQQeMByCCm15aG9zdC5jb22CDnd3dy5teWhvc3QuY29tMAoGCCqG
SM49BAMCA0gAMEUCIDf9Hbl4xn3z4EwNKmilM9lX2Fq4jWpAaRVB97OmVEeyAiEA
25aDPQHGGq2AvhKT0wvt08cX1GTGCIbfmuLpMwKQj38=
-----END CERTIFICATE-----
2018-02-17 04:52:42.442 UTC [msp] Validate -> DEBU 05d MSP DEFAULT validating identity
2018-02-17 04:52:42.443 UTC [msp] getCertificationChain -> DEBU 05e MSP DEFAULT getting certification chain
2018-02-17 04:52:42.444 UTC [msp] Setup -> DEBU 05f Setting up the MSP manager (1 msps)
2018-02-17 04:52:42.444 UTC [msp] Setup -> DEBU 060 MSP manager setup complete, setup 1 msps
2018-02-17 04:52:42.444 UTC [policies] GetPolicy -> DEBU 061 Returning policy Admins for evaluation
2018-02-17 04:52:42.445 UTC [policies] CommitProposals -> DEBU 062 In commit adding relative sub-policy SampleOrg/Admins to Orderer
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 063 Returning policy Readers for evaluation
2018-02-17 04:52:42.445 UTC [policies] CommitProposals -> DEBU 064 In commit adding relative sub-policy SampleOrg/Readers to Orderer
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 065 Returning policy Writers for evaluation
2018-02-17 04:52:42.445 UTC [policies] CommitProposals -> DEBU 066 In commit adding relative sub-policy SampleOrg/Writers to Orderer
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 067 Returning policy Readers for evaluation
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 068 Returning policy Writers for evaluation
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 069 Returning policy Admins for evaluation
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 06a Returning policy Writers for evaluation
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 06b Returning policy Writers for evaluation
2018-02-17 04:52:42.445 UTC [policies] CommitProposals -> DEBU 06c In commit adding relative sub-policy SampleOrg/Writers to Application
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 06d Returning policy Admins for evaluation
2018-02-17 04:52:42.445 UTC [policies] CommitProposals -> DEBU 06e In commit adding relative sub-policy SampleOrg/Admins to Application
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 06f Returning policy Readers for evaluation
2018-02-17 04:52:42.445 UTC [policies] CommitProposals -> DEBU 070 In commit adding relative sub-policy SampleOrg/Readers to Application
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 071 Returning policy Admins for evaluation
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 072 Returning policy Writers for evaluation
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 073 Returning policy Readers for evaluation
2018-02-17 04:52:42.445 UTC [policies] GetPolicy -> DEBU 074 Returning policy SampleOrg/Writers for evaluation
2018-02-17 04:52:42.445 UTC [policies] CommitProposals -> DEBU 075 In commit adding relative sub-policy Orderer/SampleOrg/Writers to Channel
2018-02-17 04:52:42.446 UTC [policies] GetPolicy -> DEBU 076 Returning policy Readers for evaluation
2018-02-17 04:52:42.446 UTC [policies] CommitProposals -> DEBU 077 In commit adding relative sub-policy Orderer/Readers to Channel
2018-02-17 04:52:42.446 UTC [policies] GetPolicy -> DEBU 078 Returning policy Writers for evaluation
2018-02-17 04:52:42.446 UTC [policies] CommitProposals -> DEBU 079 In commit adding relative sub-policy Orderer/Writers to Channel
2018-02-17 04:52:42.446 UTC [policies] GetPolicy -> DEBU 07a Returning policy Admins for evaluation
2018-02-17 04:52:42.446 UTC [policies] CommitProposals -> DEBU 07b In commit adding relative sub-policy Orderer/Admins to Channel
2018-02-17 04:52:42.446 UTC [policies] GetPolicy -> DEBU 07c Returning policy BlockValidation for evaluation
2018-02-17 04:52:42.446 UTC [policies] CommitProposals -> DEBU 07d In commit adding relative sub-policy Orderer/BlockValidation to Channel
2018-02-17 04:52:42.446 UTC [policies] GetPolicy -> DEBU 07e Returning policy SampleOrg/Admins for evaluation
2018-02-17 04:52:42.446 UTC [policies] CommitProposals -> DEBU 07f In commit adding relative sub-policy Orderer/SampleOrg/Admins to Channel
2018-02-17 04:52:42.446 UTC [policies] GetPolicy -> DEBU 080 Returning policy SampleOrg/Readers for evaluation
2018-02-17 04:52:42.446 UTC [policies] CommitProposals -> DEBU 081 In commit adding relative sub-policy Orderer/SampleOrg/Readers to Channel
2018-02-17 04:52:42.446 UTC [policies] GetPolicy -> DEBU 082 Returning policy Admins for evaluation
2018-02-17 04:52:42.446 UTC [policies] CommitProposals -> DEBU 083 In commit adding relative sub-policy Application/Admins to Channel
2018-02-17 04:52:42.446 UTC [policies] GetPolicy -> DEBU 084 Returning policy Writers for evaluation
2018-02-17 04:52:42.446 UTC [policies] CommitProposals -> DEBU 085 In commit adding relative sub-policy Application/Writers to Channel
2018-02-17 04:52:42.446 UTC [policies] GetPolicy -> DEBU 086 Returning policy Readers for evaluation
2018-02-17 04:52:42.446 UTC [policies] CommitProposals -> DEBU 087 In commit adding relative sub-policy Application/Readers to Channel
2018-02-17 04:52:42.446 UTC [policies] GetPolicy -> DEBU 088 Returning policy SampleOrg/Writers for evaluation
2018-02-17 04:52:42.446 UTC [policies] CommitProposals -> DEBU 089 In commit adding relative sub-policy Application/SampleOrg/Writers to Channel
2018-02-17 04:52:42.446 UTC [policies] GetPolicy -> DEBU 08a Returning policy SampleOrg/Admins for evaluation
2018-02-17 04:52:42.447 UTC [policies] CommitProposals -> DEBU 08b In commit adding relative sub-policy Application/SampleOrg/Admins to Channel
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 08c Returning policy SampleOrg/Readers for evaluation
2018-02-17 04:52:42.447 UTC [policies] CommitProposals -> DEBU 08d In commit adding relative sub-policy Application/SampleOrg/Readers to Channel
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 08e Returning policy Readers for evaluation
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 08f Returning policy Readers for evaluation
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 090 Returning policy Writers for evaluation
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 091 Returning policy Writers for evaluation
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 092 Returning policy Admins for evaluation
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 093 Returning policy Admins for evaluation
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 094 Returning policy Readers for evaluation
2018-02-17 04:52:42.447 UTC [policies] CommitProposals -> DEBU 095 As expected, current configuration has policy '/Channel/Readers'
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 096 Returning policy Writers for evaluation
2018-02-17 04:52:42.447 UTC [policies] CommitProposals -> DEBU 097 As expected, current configuration has policy '/Channel/Writers'
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 098 Returning policy Application/Readers for evaluation
2018-02-17 04:52:42.447 UTC [policies] CommitProposals -> DEBU 099 As expected, current configuration has policy '/Channel/Application/Readers'
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 09a Returning policy Application/Writers for evaluation
2018-02-17 04:52:42.447 UTC [policies] CommitProposals -> DEBU 09b As expected, current configuration has policy '/Channel/Application/Writers'
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 09c Returning policy Application/Admins for evaluation
2018-02-17 04:52:42.447 UTC [policies] CommitProposals -> DEBU 09d As expected, current configuration has policy '/Channel/Application/Admins'
2018-02-17 04:52:42.447 UTC [policies] GetPolicy -> DEBU 09e Returning policy Orderer/BlockValidation for evaluation
2018-02-17 04:52:42.447 UTC [policies] CommitProposals -> DEBU 09f As expected, current configuration has policy '/Channel/Orderer/BlockValidation'
2018-02-17 04:52:42.448 UTC [chaincodeCmd] InitCmdFactory -> INFO 0a0 Get chain(myc) orderer endpoint: orderer:7050
2018-02-17 04:52:42.450 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 0a1 Using default escc
2018-02-17 04:52:42.450 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 0a2 Using default vscc
2018-02-17 04:52:42.450 UTC [msp/identity] Sign -> DEBU 0a3 Sign: plaintext: 0AA9080A6108031A0C089AEA9ED40510...30300A000A04657363630A0476736363 
2018-02-17 04:52:42.451 UTC [msp/identity] Sign -> DEBU 0a4 Sign: digest: 53C69F4D3E17BDC5F77DED0D002584A4ED9CE44A89C49F6CABBB03DED7E49A68 
2018-02-17 04:52:42.477 UTC [msp/identity] Sign -> DEBU 0a5 Sign: plaintext: 0AA9080A6108031A0C089AEA9ED40510...8E2320C661BDAC91644166CF7155568D 
2018-02-17 04:52:42.477 UTC [msp/identity] Sign -> DEBU 0a6 Sign: digest: 17F14535D40E75D42A20AAD7A3BA9C93796FCB89AA50F80ADCDFAC77BECA0F65 
2018-02-17 04:52:42.483 UTC [main] main -> INFO 0a7 Exiting.....
		
			

查看 a,b 两个账号的余额

		
peer chaincode query -C myc -n chaincode_example02 -c '{"Args":["query","a"]}'
peer chaincode query -C myc -n chaincode_example02 -c '{"Args":["query","b"]}'		
		
			

a 向 b 转账 50

		
peer chaincode invoke -C myc -n chaincode_example02 -c '{"Args":["invoke","a","b","50"]}'
peer chaincode query -C myc -n chaincode_example02 -c '{"Args":["query","a"]}'
peer chaincode query -C myc -n chaincode_example02 -c '{"Args":["query","b"]}'
		
			

这是再查看 a, b 两个掌控的余额应该是 a: 50 , B: 250

		
root@33dcacfb6f81:/opt/gopath/src/chaincodedev# peer chaincode query -C myc -n chaincode_example02 -c '{"Args":["query","a"]}'
2018-02-17 04:56:46.870 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-02-17 04:56:46.870 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-02-17 04:56:46.870 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-02-17 04:56:46.870 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-02-17 04:56:46.871 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0AB8080A7008031A0C088EEC9ED40510...6C6530321A0A0A0571756572790A0161 
2018-02-17 04:56:46.871 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 1F0EB0AD273AE083C5673CE73877AE3F09324BDCB6968E2477D3F947B37EF4C5 
Query Result: 50
2018-02-17 04:56:46.903 UTC [main] main -> INFO 007 Exiting.....				
		
root@33dcacfb6f81:/opt/gopath/src/chaincodedev# peer chaincode query -C myc -n chaincode_example02 -c '{"Args":["query","b"]}'
2018-02-17 04:55:29.791 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-02-17 04:55:29.792 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-02-17 04:55:29.792 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-02-17 04:55:29.792 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-02-17 04:55:29.793 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0AB8080A7008031A0C08C1EB9ED40510...6C6530321A0A0A0571756572790A0162 
2018-02-17 04:55:29.793 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 36BED07CE9664E26478A993392B2869F10533506CA9BD5F0A9D48D02EDB1F1D0 
Query Result: 250
2018-02-17 04:55:29.823 UTC [main] main -> INFO 007 Exiting.....
		
			

chaincode 终端也会显示下面内容。

		
root@78d23b3b2b37:/opt/gopath/src/chaincode# CORE_PEER_ADDRESS=peer:7051 CORE_CHAINCODE_ID_NAME=chaincode_example02:1.0 ./chaincode_example02 
2018-02-17 04:51:25.481 UTC [shim] SetupChaincodeLogging -> INFO 001 Chaincode log level not provided; defaulting to: INFO
2018-02-17 04:51:25.482 UTC [shim] SetupChaincodeLogging -> INFO 002 Chaincode (build level: ) starting up ...
ex02 Init
Aval = 100, Bval = 200
ex02 Invoke
Query Response:{"Name":"a","Amount":"100"}
ex02 Invoke
Query Response:{"Name":"b","Amount":"200"}
ex02 Invoke
Aval = 50, Bval = 250
ex02 Invoke
Query Response:{"Name":"b","Amount":"250"}
ex02 Invoke
Query Response:{"Name":"a","Amount":"50"}		
		
			

26.1.5. 代码测试

			
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package example02

import (
	"fmt"
	"testing"

	"github.com/hyperledger/fabric/core/chaincode/shim"
)

func checkInit(t *testing.T, stub *shim.MockStub, args [][]byte) {
	res := stub.MockInit("1", args)
	if res.Status != shim.OK {
		fmt.Println("Init failed", string(res.Message))
		t.FailNow()
	}
}

func checkState(t *testing.T, stub *shim.MockStub, name string, value string) {
	bytes := stub.State[name]
	if bytes == nil {
		fmt.Println("State", name, "failed to get value")
		t.FailNow()
	}
	if string(bytes) != value {
		fmt.Println("State value", name, "was not", value, "as expected")
		t.FailNow()
	}
}

func checkQuery(t *testing.T, stub *shim.MockStub, name string, value string) {
	res := stub.MockInvoke("1", [][]byte{[]byte("query"), []byte(name)})
	if res.Status != shim.OK {
		fmt.Println("Query", name, "failed", string(res.Message))
		t.FailNow()
	}
	if res.Payload == nil {
		fmt.Println("Query", name, "failed to get value")
		t.FailNow()
	}
	if string(res.Payload) != value {
		fmt.Println("Query value", name, "was not", value, "as expected")
		t.FailNow()
	}
}

func checkInvoke(t *testing.T, stub *shim.MockStub, args [][]byte) {
	res := stub.MockInvoke("1", args)
	if res.Status != shim.OK {
		fmt.Println("Invoke", args, "failed", string(res.Message))
		t.FailNow()
	}
}

func TestExample02_Init(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex02", scc)

	// Init A=123 B=234
	checkInit(t, stub, [][]byte{[]byte("init"), []byte("A"), []byte("123"), []byte("B"), []byte("234")})

	checkState(t, stub, "A", "123")
	checkState(t, stub, "B", "234")
}

func TestExample02_Query(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex02", scc)

	// Init A=345 B=456
	checkInit(t, stub, [][]byte{[]byte("init"), []byte("A"), []byte("345"), []byte("B"), []byte("456")})

	// Query A
	checkQuery(t, stub, "A", "345")

	// Query B
	checkQuery(t, stub, "B", "456")
}

func TestExample02_Invoke(t *testing.T) {
	scc := new(SimpleChaincode)
	stub := shim.NewMockStub("ex02", scc)

	// Init A=567 B=678
	checkInit(t, stub, [][]byte{[]byte("init"), []byte("A"), []byte("567"), []byte("B"), []byte("678")})

	// Invoke A->B for 123
	checkInvoke(t, stub, [][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("123")})
	checkQuery(t, stub, "A", "444")
	checkQuery(t, stub, "B", "801")

	// Invoke B->A for 234
	checkInvoke(t, stub, [][]byte{[]byte("invoke"), []byte("B"), []byte("A"), []byte("234")})
	checkQuery(t, stub, "A", "678")
	checkQuery(t, stub, "B", "567")
	checkQuery(t, stub, "A", "678")
	checkQuery(t, stub, "B", "567")
}			
			
			

26.1.6. 在宿主主机上编译合约

编译 chaincode 可以在 docker 容器中进行,也可以在 docker 外面进行。方法如下:

安装依赖的库文件

			
yum install libtool-ltdl-devel
go get github.com/hyperledger/fabric		
			
			

编译合约文件

			
[root@localhost ~]# cd ~/netkiller/chaincode/chaincode_example02/
[root@localhost chaincode_example02]#

[root@localhost chaincode_example02]# go build chaincode_example02.go 

[root@localhost chaincode_example02]# ls
chaincode_example02  chaincode_example02.go  chaincode_example02_test.go 
			
			
[提示]提示

由于 docker 容器中没有 vim/nano 命令,无法编译 .go 文件,所以在宿主主机编译更为方便。

26.1.7. 链码升级

已经实例化的链码如果需要更新,可以通过 upgrade 升级。

		
peer chaincode upgrade -o orderer.example.com:7050 -C mychannel -n token4 -v 1.1 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
		
			

操作演示

		
[root@localhost token]# docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode upgrade -o orderer.example.com:7050 -C mychannel -n token4 -v 1.1 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
2018-03-21 05:45:57.825 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-03-21 05:45:57.825 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-03-21 05:45:57.827 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-03-21 05:45:57.828 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-03-21 05:45:57.829 UTC [chaincodeCmd] upgrade -> DEBU 005 Get upgrade proposal for chaincode <name:"token4" version:"1.1" >
2018-03-21 05:45:57.829 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0A91070A6708031A0C0895E3C7D50510...324D53500A04657363630A0476736363 
2018-03-21 05:45:57.830 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: D74025895DC08535F47FACF5AB3BE1ECFBCC30BA569E60C3DD45655BF5B89F89 
2018-03-21 05:46:43.134 UTC [chaincodeCmd] upgrade -> DEBU 008 endorse upgrade proposal, get response <status:200 message:"OK" payload:"\n\006token4\022\0031.1\032\004escc\"\004vscc*(\022\014\022\n\010\001\022\002\010\000\022\002\010\001\032\013\022\t\n\007Org1MSP\032\013\022\t\n\007Org2MSP2D\n \260\010<\325\376\335\274W\266N\236N\221\241NP\257&\330\220\232\355\022OB\334cE\021\374\343\222\022 r\2150\010R\nQ=\3135\314\312\334\312f\373\363\2646*hUT\362\227<Q\356*\007\204f: \362\366k\2363\033\314\177\226v\020\\KT\216\376\032\347\252\034L\274\224G+\003GE\2673G\222B\031\022\010\022\006\010\001\022\002\010\000\032\r\022\013\n\007Org1MSP\020\001" >
2018-03-21 05:46:43.166 UTC [msp/identity] Sign -> DEBU 009 Sign: plaintext: 0A91070A6708031A0C0895E3C7D50510...B547273E6CEACD8482A8F632F2681093 
2018-03-21 05:46:43.167 UTC [msp/identity] Sign -> DEBU 00a Sign: digest: D2F66B1F91AE4A6C138672975FBFC3D5D2A551419F74950B4129F5D4CA8B244D 
2018-03-21 05:46:43.167 UTC [chaincodeCmd] upgrade -> DEBU 00b Get Signed envelope
2018-03-21 05:46:43.167 UTC [chaincodeCmd] chaincodeUpgrade -> DEBU 00c Send signed envelope to orderer
2018-03-21 05:46:43.179 UTC [main] main -> INFO 00d Exiting.....