Hyperledger Fabric Chaincode 开发

本文节选自《Netkiller Blockchain 手札》

 

Netkiller Blockchain 手札

本文作者最近在找工作,有意向致电 13113668890

Mr. Neo Chan, 陈景峯(BG7NYT)


中国广东省深圳市龙华新区民治街道溪山美地
518131
+86 13113668890

<netkiller@msn.com>

文档始创于2014-06-23

版权 © 2018 Netkiller(Neo Chan). All rights reserved.

 

版权声明

转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。

Hyperledger Fabric Chaincode 开发
http://www.netkiller.cn
http://netkiller.github.io
http://netkiller.sourceforge.net
Hyperledger Fabric Chaincode 开发
微信订阅号 netkiller-ebook (微信扫描二维码)
QQ:13721218 请注明“读者”
QQ群:128659835 请注明“读者”

第 6 章 Chaincode 开发

目录

6.1. 开发环境

6.2. chaincode 代码

6.3. 启动容器部署chaincode

6.4. 测试

6.1. 开发环境

[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/1.0.5/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.0.5        6a8993b718c8        2 months ago        1.33GB
hyperledger/fabric-couchdb   latest              9a58db2d2723        2 months ago        1.5GB
hyperledger/fabric-couchdb   x86_64-1.0.5        9a58db2d2723        2 months ago        1.5GB
hyperledger/fabric-orderer   latest              368c78b6f03b        2 months ago        151MB
hyperledger/fabric-orderer   x86_64-1.0.5        368c78b6f03b        2 months ago        151MB
hyperledger/fabric-peer      latest              c2ab022f0bdb        2 months ago        154MB
hyperledger/fabric-peer      x86_64-1.0.5        c2ab022f0bdb        2 months ago        154MB
hyperledger/fabric-ccenv     latest              33feadb8f7a6        2 months ago        1.28GB
hyperledger/fabric-ccenv     x86_64-1.0.5        33feadb8f7a6        2 months ago        1.28GB
hyperledger/fabric-ca        latest              002c9089e464        2 months ago        238MB
hyperledger/fabric-ca        x86_64-1.0.5        002c9089e464        2 months ago        238MB

6.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)
	}
}

6.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 记住这里的配置,下面会用到

6.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"}
上一篇:从零学React Native之05混合开发


下一篇:(码友推荐)2018-09-20 .NET及相关开发资讯速递