2. 체인코드 수정하기
페이지 정보
작성자 관리자 댓글 0건 조회 2,493회 작성일 19-11-14 12:18본문
터미널1. docker 이미지 재시작
[Ctrl+C]를 클릭하여 종료한다.
peer | 2019-03-20 09:33:40.640 UTC [msp.identity] Sign -> DEBU dc9c Sign: digest: D18B553283AFC791A71A1AB3F379E85F4599DAAE3CE5B43F6A912E5BFD23E73D
^CGracefully stopping... (press Ctrl+C again to force)
Stopping chaincode ... done
Stopping cli ... done
Stopping peer ... done
Stopping orderer ... done
root@leelab:~/hyperledger/fabric-samples/chaincode-docker-devmode# docker-compose -f docker-compose-simple.yaml down
Removing chaincode ... done
Removing cli ... done
Removing peer ... done
Removing orderer ... done
Removing network chaincodedockerdevmode_default
root@leelab:~/hyperledger/fabric-samples/chaincode-docker-devmode#
root@leelab:~/hyperledger/fabric-samples/chaincode-docker-devmode# docker-compose -f docker-compose-simple.yaml up
터미널3. 체인코드 수정
docker 이미지에서 빠져나온다.
root@38811b1c6e63:/opt/gopath/src/chaincodedev# exit
exit
root@client:~/hyperledger/fabric-samples/chaincode-docker-devmode# cd ../chaincode/chaincode_example02/go
root@client:~/hyperledger/fabric-samples/chaincode/chaincode_example02/go#
root@client:~/hyperledger/fabric-samples/chaincode/chaincode_example02/go# vi chaincode_example02.go
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)
} else if function == "reg" {
// reg
return t.reg(stub, args)
}
return shim.Error("Invalid invoke function name. Expecting \"invoke\" \"delete\" \"query\"")
}
// reg
func (t *SimpleChaincode) reg(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var A string // Entities
var Aval int // Asset holdings
var err error
if len(args) != 2 {
return shim.Error("Incorrect number of arguments. Expecting 2")
}
A = args[0]
Aval, err = strconv.Atoi(args[1])
if err != nil {
return shim.Error("Expecting integer value for asset holding")
}
fmt.Printf("New value = %d\n", Aval)
// Write the state back to the ledger
err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
if err != nil {
return shim.Error(err.Error())
}
return shim.Success(nil)
}
터미널2. 체인코드 빌드 및 시작
현재 실행된 체인코드를 중지한다. (Ctrl+C)키를 누른다.
ex02 Init
Aval = 100, Bval = 200
ex02 Invoke
Aval = 90, Bval = 210
ex02 Invoke
Query Response:{"Name":"a","Amount":"90"}
^C
root@415af2cc7fec:/opt/gopath/src/chaincode# cd chaincode_example02/go
root@415af2cc7fec:/opt/gopath/src/chaincode/chaincode_example02/go# go build -o chaincode_example02
root@ccd6d17781d6:/opt/gopath/src/chaincode/chaincode_example02/go# CORE_PEER_ADDRESS=peer:7052 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode_example02
2019-11-14 02:50:53.890 UTC [shim] setupChaincodeLogging -> INFO 001 Chaincode log level not provided; defaulting to: INFO
2019-11-14 02:50:53.894 UTC [shim] setupChaincodeLogging -> INFO 002 Chaincode (build level: ) starting up ...
2019-11-14 02:50:53.895 UTC [bccsp] initBCCSP -> DEBU 001 Initialize BCCSP [SW]
2019-11-14 02:50:53.895 UTC [grpc] DialContext -> DEBU 002 parsed scheme: ""
2019-11-14 02:50:53.895 UTC [grpc] DialContext -> DEBU 003 scheme "" not registered, fallback to default scheme
2019-11-14 02:50:53.896 UTC [grpc] watcher -> DEBU 004 ccResolverWrapper: sending new addresses to cc: [{peer:7052 0 <nil>}]
2019-11-14 02:50:53.896 UTC [grpc] switchBalancer -> DEBU 005 ClientConn switching balancer to "pick_first"
2019-11-14 02:50:53.896 UTC [grpc] HandleSubConnStateChange -> DEBU 006 pickfirstBalancer: HandleSubConnStateChange: 0xc00035a2a0, CONNECTING
2019-11-14 02:50:53.935 UTC [grpc] HandleSubConnStateChange -> DEBU 007 pickfirstBalancer: HandleSubConnStateChange: 0xc00035a2a0, READY
터미널3. chaincode 사용
[root@leelab chaincode-docker-devmode]# docker exec -it cli bash
root@f75979e099b9:/opt/gopath/src/chaincodedev#
# peer chaincode install -p chaincodedev/chaincode/chaincode_example02/go -n mycc -v 0
# peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -C myc
초기값 a=100, b=200
# peer chaincode invoke -n mycc -c '{"Args":["reg","c","1000"]}' -C myc
2019-03-20 12:42:17.753 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 0a7 Chaincode invoke successful. result: status:200
root@7183c9147d90:/opt/gopath/src/chaincodedev#
터미널2의 로그를 확인한다.
ex02 Init
Aval = 100, Bval = 200
ex02 Invoke
New value = 1000
댓글목록
등록된 댓글이 없습니다.