From ae342ef96bfba60344873e589e32360e6251f6f4 Mon Sep 17 00:00:00 2001 From: Baohua Yang Date: Fri, 5 Jan 2018 12:47:35 +0800 Subject: [PATCH] Update chaincode name more speficicly --- hyperledger_fabric/v1.0.2/Makefile | 25 ++- hyperledger_fabric/v1.0.2/base-dev.yaml | 4 +- hyperledger_fabric/v1.0.2/base-kafka.yaml | 2 +- hyperledger_fabric/v1.0.2/base-solo.yaml | 6 +- .../chaincode_example02.go | 199 ------------------ hyperledger_fabric/v1.0.2/scripts/func.sh | 3 +- .../v1.0.2/scripts/initialize_peer0.sh | 2 +- .../v1.0.2/scripts/test_cc_install.sh | 8 +- .../v1.0.2/scripts/test_cc_instantiate.sh | 4 +- .../v1.0.2/scripts/test_cc_invoke_query.sh | 14 +- .../v1.0.2/scripts/test_cc_peer0.sh | 6 +- .../v1.0.2/scripts/test_cc_upgrade.sh | 14 +- .../v1.0.2/scripts/test_lscc.sh | 12 +- .../v1.0.2/scripts/variables.sh | 17 +- .../new_businesschannel.tx.json | 113 ++++++++++ .../chaincode_example02.go | 199 ------------------ 16 files changed, 173 insertions(+), 455 deletions(-) delete mode 100644 hyperledger_fabric/v1.0.2/kafka/examples/chaincode/go/chaincode_example02/chaincode_example02.go delete mode 100644 hyperledger_fabric/v1.0.2/solo/examples/chaincode/go/chaincode_example02/chaincode_example02.go diff --git a/hyperledger_fabric/v1.0.2/Makefile b/hyperledger_fabric/v1.0.2/Makefile index f6adfc21..5daaac60 100644 --- a/hyperledger_fabric/v1.0.2/Makefile +++ b/hyperledger_fabric/v1.0.2/Makefile @@ -4,7 +4,7 @@ HLF_MODE ?= solo HLF_VERSION ?= 1.0.2 -CODE_BUILD_WAIT=40 # time to wait to build peer/orderer from local code +CODE_BUILD_WAIT=30 # time to wait to build peer/orderer from local code NETWORK_INIT_WAIT=2 # time to wait the fabric network finish initialization COMPOSE_FILE ?= "docker-compose-2orgs-4peers-solo.yaml" @@ -39,24 +39,30 @@ ready: # create/join channel, install/instantiate cc make gen_config # Will ignore if local config path exists make start + if [ "$(HLF_MODE)" = "dev" ]; then \ + sleep ${CODE_BUILD_WAIT}; \ + else \ + sleep ${NETWORK_INIT_WAIT}; \ + fi + make test_channel_create make test_channel_join - make update_anchors + #make update_anchors make test_cc_install make test_cc_instantiate - make test_cc_invoke_query + #make test_cc_invoke_query - make test_lscc # test lscc operations - make test_qscc # test qscc operations + #make test_lscc # test lscc operations + #make test_qscc # test qscc operations #make test_fetch_blocks # fetch block files #make test_config_update #make test_channel_update - make logs_save - make test_fetch_blocks # fetch block files again - make test_configtxlator + #make logs_save + #make test_fetch_blocks # fetch block files again + #make test_configtxlator @echo "Now the fabric network is ready to play" @echo "run 'make cli' to enter into the fabric-cli container." @@ -174,9 +180,6 @@ orderer: # enter the orderer container peer: # enter the peer container docker exec -it peer0.org1.example.com bash -dev_compile: # rebuild the peer - docker exec -it peer0.org1.example.com bash /tmp/peer_build.sh - ps: # show existing docker images docker ps -a diff --git a/hyperledger_fabric/v1.0.2/base-dev.yaml b/hyperledger_fabric/v1.0.2/base-dev.yaml index 61f42009..c9346a70 100644 --- a/hyperledger_fabric/v1.0.2/base-dev.yaml +++ b/hyperledger_fabric/v1.0.2/base-dev.yaml @@ -88,10 +88,10 @@ services: #- ./solo/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml #- ./solo/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml #- ./solo/crypto-config:/etc/hyperledger/fabric/crypto-config - #- ./solo/examples:/opt/gopath/src/github.com/hyperledger/fabric/examples + #- ./examples:/opt/gopath/src/github.com/hyperledger/fabric/examples # kafka mode configuration - ./kafka/channel-artifacts:/tmp/channel-artifacts - ./kafka/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml - ./kafka/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml - ./kafka/crypto-config:/etc/hyperledger/fabric/crypto-config - - ./kafka/examples:/opt/gopath/src/github.com/hyperledger/fabric/examples + - ./examples:/opt/gopath/src/github.com/hyperledger/fabric/examples diff --git a/hyperledger_fabric/v1.0.2/base-kafka.yaml b/hyperledger_fabric/v1.0.2/base-kafka.yaml index 2258cb0b..c5f79062 100644 --- a/hyperledger_fabric/v1.0.2/base-kafka.yaml +++ b/hyperledger_fabric/v1.0.2/base-kafka.yaml @@ -87,7 +87,7 @@ services: - ./kafka/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml - ./kafka/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml - ./kafka/crypto-config:/etc/hyperledger/fabric/crypto-config - - ./kafka/examples:/opt/gopath/src/examples + - ./examples:/opt/gopath/src/examples ## following are peer nodes ## diff --git a/hyperledger_fabric/v1.0.2/base-solo.yaml b/hyperledger_fabric/v1.0.2/base-solo.yaml index cb7e3933..b3a10d48 100644 --- a/hyperledger_fabric/v1.0.2/base-solo.yaml +++ b/hyperledger_fabric/v1.0.2/base-solo.yaml @@ -199,8 +199,8 @@ services: - ./solo/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml - ./solo/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml - ./solo/crypto-config:/etc/hyperledger/fabric/crypto-config - - ./solo/examples:/opt/gopath/src/examples - #- ./solo/examples:/opt/gopath/src/github.com/hyperledger/fabric/examples + - ./examples:/opt/gopath/src/examples + #- ./examples:/opt/gopath/src/github.com/hyperledger/fabric/examples event-listener: extends: @@ -221,6 +221,6 @@ services: - ./solo/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml - ./solo/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml - ./solo/crypto-config:/etc/hyperledger/fabric/crypto-config - - ./solo/examples:/opt/gopath/src/github.com/hyperledger/fabric/examples + - ./examples:/opt/gopath/src/github.com/hyperledger/fabric/examples command: bash -c 'while true; do sleep 1; block-listener -events-address=peer0.org1.example.com:7053 -events-mspdir=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/ -events-mspid=Org1MSP; done' #command: bash -c 'while true; do sleep 20170504; done' diff --git a/hyperledger_fabric/v1.0.2/kafka/examples/chaincode/go/chaincode_example02/chaincode_example02.go b/hyperledger_fabric/v1.0.2/kafka/examples/chaincode/go/chaincode_example02/chaincode_example02.go deleted file mode 100644 index 53438066..00000000 --- a/hyperledger_fabric/v1.0.2/kafka/examples/chaincode/go/chaincode_example02/chaincode_example02.go +++ /dev/null @@ -1,199 +0,0 @@ -/* -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) - } -} diff --git a/hyperledger_fabric/v1.0.2/scripts/func.sh b/hyperledger_fabric/v1.0.2/scripts/func.sh index 439e8ca4..e8dde995 100644 --- a/hyperledger_fabric/v1.0.2/scripts/func.sh +++ b/hyperledger_fabric/v1.0.2/scripts/func.sh @@ -440,6 +440,7 @@ chaincodeQuery () { # Start chaincode with dev mode +# TODO: use variables instead of hard-coded value chaincodeStartDev () { local peer=$1 local version=$2 @@ -448,7 +449,7 @@ chaincodeStartDev () { setEnvs 1 0 CORE_CHAINCODE_LOGLEVEL=debug \ CORE_PEER_ADDRESS=peer${peer}.org1.example.com:7052 \ - CORE_CHAINCODE_ID_NAME=mycc:${version} \ + CORE_CHAINCODE_ID_NAME=${CC_02_NAME}:${version} \ nohup ./scripts/chaincode_example02 > chaincode_dev.log & res=$? cat log.txt diff --git a/hyperledger_fabric/v1.0.2/scripts/initialize_peer0.sh b/hyperledger_fabric/v1.0.2/scripts/initialize_peer0.sh index b16afcbb..d8732224 100644 --- a/hyperledger_fabric/v1.0.2/scripts/initialize_peer0.sh +++ b/hyperledger_fabric/v1.0.2/scripts/initialize_peer0.sh @@ -25,7 +25,7 @@ channelUpdate ${APP_CHANNEL} 1 0 Org1MSPanchors.tx ## Install chaincode on all peers echo_b "Installing chaincode on peer0..." -chaincodeInstall 0 ${CC_INIT_ARGS} +chaincodeInstall 0 ${CC_02_INIT_ARGS} # Instantiate chaincode on all peers # Instantiate can only be executed once on any node diff --git a/hyperledger_fabric/v1.0.2/scripts/test_cc_install.sh b/hyperledger_fabric/v1.0.2/scripts/test_cc_install.sh index b349b3dc..bd3a1d6b 100644 --- a/hyperledger_fabric/v1.0.2/scripts/test_cc_install.sh +++ b/hyperledger_fabric/v1.0.2/scripts/test_cc_install.sh @@ -9,9 +9,9 @@ fi ## Install chaincode on all peers echo_b "Installing chaincode on all 4 peers..." -chaincodeInstall 1 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH} -chaincodeInstall 1 1 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH} -chaincodeInstall 2 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH} -chaincodeInstall 2 1 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH} +chaincodeInstall 1 0 ${CC_02_NAME} ${CC_INIT_VERSION} ${CC_02_PATH} +chaincodeInstall 1 1 ${CC_02_NAME} ${CC_INIT_VERSION} ${CC_02_PATH} +chaincodeInstall 2 0 ${CC_02_NAME} ${CC_INIT_VERSION} ${CC_02_PATH} +chaincodeInstall 2 1 ${CC_02_NAME} ${CC_INIT_VERSION} ${CC_02_PATH} echo_g "=== Install chaincode done ===" \ No newline at end of file diff --git a/hyperledger_fabric/v1.0.2/scripts/test_cc_instantiate.sh b/hyperledger_fabric/v1.0.2/scripts/test_cc_instantiate.sh index 8a3ab109..9497b69a 100644 --- a/hyperledger_fabric/v1.0.2/scripts/test_cc_instantiate.sh +++ b/hyperledger_fabric/v1.0.2/scripts/test_cc_instantiate.sh @@ -10,7 +10,7 @@ fi # Instantiate chaincode on all peers # Instantiate can only be executed once on any node echo_b "Instantiating chaincode on channel ${APP_CHANNEL} (once for each channel is enough, we make it concurrent here)..." -chaincodeInstantiate "${APP_CHANNEL}" 1 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_INIT_ARGS} -chaincodeInstantiate "${APP_CHANNEL}" 2 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_INIT_ARGS} +chaincodeInstantiate "${APP_CHANNEL}" 1 0 ${CC_02_NAME} ${CC_INIT_VERSION} ${CC_02_INIT_ARGS} +chaincodeInstantiate "${APP_CHANNEL}" 2 0 ${CC_02_NAME} ${CC_INIT_VERSION} ${CC_02_INIT_ARGS} echo_g "=== Instantiate chaincode done ===" diff --git a/hyperledger_fabric/v1.0.2/scripts/test_cc_invoke_query.sh b/hyperledger_fabric/v1.0.2/scripts/test_cc_invoke_query.sh index 7b4187ac..6da08f35 100644 --- a/hyperledger_fabric/v1.0.2/scripts/test_cc_invoke_query.sh +++ b/hyperledger_fabric/v1.0.2/scripts/test_cc_invoke_query.sh @@ -9,24 +9,24 @@ fi #Query on chaincode on Peer0/Org1 echo_b "Querying chaincode on peer org2/peer0..." -chaincodeQuery ${APP_CHANNEL} 2 1 ${CC_NAME} ${CC_QUERY_ARGS} 100 +chaincodeQuery ${APP_CHANNEL} 2 1 ${CC_02_NAME} ${CC_02_QUERY_ARGS} 100 #Invoke on chaincode on Peer0/Org1 echo_b "Sending invoke transaction (transfer 10) on org1/peer0..." -chaincodeInvoke ${APP_CHANNEL} 1 0 ${CC_NAME} ${CC_INVOKE_ARGS} +chaincodeInvoke ${APP_CHANNEL} 1 0 ${CC_02_NAME} ${CC_02_INVOKE_ARGS} #Query on chaincode on Peer1/Org2, check if the result is 90 echo_b "Querying chaincode on peer 1 and 3..." -chaincodeQuery ${APP_CHANNEL} 1 1 ${CC_NAME} ${CC_QUERY_ARGS} 90 -chaincodeQuery ${APP_CHANNEL} 2 1 ${CC_NAME} ${CC_QUERY_ARGS} 90 +chaincodeQuery ${APP_CHANNEL} 1 1 ${CC_02_NAME} ${CC_02_QUERY_ARGS} 90 +chaincodeQuery ${APP_CHANNEL} 2 1 ${CC_02_NAME} ${CC_02_QUERY_ARGS} 90 #Invoke on chaincode on Peer1/Org2 echo_b "Sending invoke transaction on org2/peer3..." -chaincodeInvoke ${APP_CHANNEL} 2 1 ${CC_NAME} ${CC_INVOKE_ARGS} +chaincodeInvoke ${APP_CHANNEL} 2 1 ${CC_02_NAME} ${CC_02_INVOKE_ARGS} #Query on chaincode on Peer1/Org2, check if the result is 80 echo_b "Querying chaincode on all 4peers..." -chaincodeQuery ${APP_CHANNEL} 1 0 ${CC_NAME} ${CC_QUERY_ARGS} 80 -chaincodeQuery ${APP_CHANNEL} 2 0 ${CC_NAME} ${CC_QUERY_ARGS} 80 +chaincodeQuery ${APP_CHANNEL} 1 0 ${CC_02_NAME} ${CC_02_QUERY_ARGS} 80 +chaincodeQuery ${APP_CHANNEL} 2 0 ${CC_02_NAME} ${CC_02_QUERY_ARGS} 80 echo_g "=== All GOOD, chaincode invoke/query completed ===" diff --git a/hyperledger_fabric/v1.0.2/scripts/test_cc_peer0.sh b/hyperledger_fabric/v1.0.2/scripts/test_cc_peer0.sh index 33e99467..517917b5 100644 --- a/hyperledger_fabric/v1.0.2/scripts/test_cc_peer0.sh +++ b/hyperledger_fabric/v1.0.2/scripts/test_cc_peer0.sh @@ -10,17 +10,17 @@ fi echo_b "Channel name: "${APP_CHANNEL} echo_b "Query the existing value of a" -chaincodeQuery ${APP_CHANNEL} 0 ${CC_NAME} ${CC_QUERY_ARGS} 100 +chaincodeQuery ${APP_CHANNEL} 0 ${CC_02_NAME} ${CC_02_QUERY_ARGS} 100 sleep 1 echo_b "Invoke a transaction to transfer 10 from a to b" -chaincodeInvoke ${APP_CHANNEL} 0 ${CC_NAME} ${CC_INVOKE_ARGS} +chaincodeInvoke ${APP_CHANNEL} 0 ${CC_02_NAME} ${CC_02_INVOKE_ARGS} sleep 1 echo_b "Check if the result of a is 90" -chaincodeQuery ${APP_CHANNEL} 0 ${CC_NAME} ${CC_QUERY_ARGS} 90 +chaincodeQuery ${APP_CHANNEL} 0 ${CC_02_NAME} ${CC_02_QUERY_ARGS} 90 echo echo_g "All GOOD, MVE Test completed" diff --git a/hyperledger_fabric/v1.0.2/scripts/test_cc_upgrade.sh b/hyperledger_fabric/v1.0.2/scripts/test_cc_upgrade.sh index 03b9a0e0..4b04203d 100644 --- a/hyperledger_fabric/v1.0.2/scripts/test_cc_upgrade.sh +++ b/hyperledger_fabric/v1.0.2/scripts/test_cc_upgrade.sh @@ -9,16 +9,16 @@ fi #Upgrade to new version echo_b "Upgrade chaincode to new version..." -chaincodeInstall 1 0 "${CC_NAME}" "${CC_UPGRADE_VERSION}" "${CC_PATH}" -chaincodeInstall 1 1 "${CC_NAME}" "${CC_UPGRADE_VERSION}" "${CC_PATH}" -chaincodeInstall 2 0 "${CC_NAME}" "${CC_UPGRADE_VERSION}" "${CC_PATH}" -chaincodeInstall 2 1 "${CC_NAME}" "${CC_UPGRADE_VERSION}" "${CC_PATH}" +chaincodeInstall 1 0 "${CC_02_NAME}" "${CC_UPGRADE_VERSION}" "${CC_02_PATH}" +chaincodeInstall 1 1 "${CC_02_NAME}" "${CC_UPGRADE_VERSION}" "${CC_02_PATH}" +chaincodeInstall 2 0 "${CC_02_NAME}" "${CC_UPGRADE_VERSION}" "${CC_02_PATH}" +chaincodeInstall 2 1 "${CC_02_NAME}" "${CC_UPGRADE_VERSION}" "${CC_02_PATH}" # Upgrade on one peer of the channel will update all -chaincodeUpgrade ${APP_CHANNEL} 1 0 "${CC_NAME}" "${CC_UPGRADE_VERSION}" "${CC_UPGRADE_ARGS}" +chaincodeUpgrade ${APP_CHANNEL} 1 0 "${CC_02_NAME}" "${CC_UPGRADE_VERSION}" "${CC_02_UPGRADE_ARGS}" # Query new value, should refresh through all peers in the channel -chaincodeQuery ${APP_CHANNEL} 1 0 "${CC_NAME}" "${CC_QUERY_ARGS}" 100 -chaincodeQuery ${APP_CHANNEL} 2 1 "${CC_NAME}" "${CC_QUERY_ARGS}" 100 +chaincodeQuery ${APP_CHANNEL} 1 0 "${CC_02_NAME}" "${CC_02_QUERY_ARGS}" 100 +chaincodeQuery ${APP_CHANNEL} 2 1 "${CC_02_NAME}" "${CC_02_QUERY_ARGS}" 100 echo_g "=== All GOOD, chaincode Upgrade completed ===" diff --git a/hyperledger_fabric/v1.0.2/scripts/test_lscc.sh b/hyperledger_fabric/v1.0.2/scripts/test_lscc.sh index 26466d6a..e32bfb7a 100644 --- a/hyperledger_fabric/v1.0.2/scripts/test_lscc.sh +++ b/hyperledger_fabric/v1.0.2/scripts/test_lscc.sh @@ -20,13 +20,13 @@ peer=0 #--cafile ${ORDERER_TLS_CA} \ echo_b "LSCC Get id" -chaincodeQuery "${APP_CHANNEL}" $org $peer lscc '{"Args":["getid","'${APP_CHANNEL}'", "'$CC_NAME'"]}' +chaincodeQuery "${APP_CHANNEL}" $org $peer lscc '{"Args":["getid","'${APP_CHANNEL}'", "'$CC_02_NAME'"]}' echo_b "LSCC Get cc ChaincodeDeploymentSpec" -chaincodeQuery "${APP_CHANNEL}" $org $peer lscc '{"Args":["getdepspec","'${APP_CHANNEL}'", "'$CC_NAME'"]}' +chaincodeQuery "${APP_CHANNEL}" $org $peer lscc '{"Args":["getdepspec","'${APP_CHANNEL}'", "'$CC_02_NAME'"]}' echo_b "LSCC Get cc bytes" -chaincodeQuery "${APP_CHANNEL}" $org $peer lscc '{"Args":["getccdata","'${APP_CHANNEL}'", "'$CC_NAME'"]}' +chaincodeQuery "${APP_CHANNEL}" $org $peer lscc '{"Args":["getccdata","'${APP_CHANNEL}'", "'$CC_02_NAME'"]}' echo_b "LSCC Get all chaincodes installed on the channel" chaincodeQuery "${APP_CHANNEL}" $org $peer lscc '{"Args":["getinstalledchaincodes"]}' @@ -38,17 +38,17 @@ chaincodeQuery "${APP_CHANNEL}" $org $peer lscc '{"Args":["getchaincodes"]}' #peer chaincode query \ # -C "${APP_CHANNEL}" \ # -n lscc \ -# -c '{"Args":["getid","'${APP_CHANNEL}'", "'$CC_NAME'"]}' +# -c '{"Args":["getid","'${APP_CHANNEL}'", "'$CC_02_NAME'"]}' #peer chaincode query \ # -C "${APP_CHANNEL}" \ # -n lscc \ -# -c '{"Args":["getdepspec","'${APP_CHANNEL}'", "'$CC_NAME'"]}' +# -c '{"Args":["getdepspec","'${APP_CHANNEL}'", "'$CC_02_NAME'"]}' #peer chaincode query \ # -C "${APP_CHANNEL}" \ # -n lscc \ -# -c '{"Args":["getccdata","'${APP_CHANNEL}'", "'$CC_NAME'"]}' +# -c '{"Args":["getccdata","'${APP_CHANNEL}'", "'$CC_02_NAME'"]}' #peer chaincode query \ # -C "${APP_CHANNEL}" \ diff --git a/hyperledger_fabric/v1.0.2/scripts/variables.sh b/hyperledger_fabric/v1.0.2/scripts/variables.sh index 99b15a02..369bc61d 100644 --- a/hyperledger_fabric/v1.0.2/scripts/variables.sh +++ b/hyperledger_fabric/v1.0.2/scripts/variables.sh @@ -40,22 +40,21 @@ ORG2_PEER0_URL="peer0.org2.example.com:7051" ORG2_PEER1_URL="peer1.org2.example.com:7051" # Chaincode related -CC_NAME="mycc" -#CC_PATH="github.com/hyperledger/fabric/examples/chaincode/go/foodchain" -CC_PATH="examples/chaincode/go/chaincode_example02" +CC_02_NAME="exp02" +CC_02_PATH="examples/chaincode/go/chaincode_example02" CC_INIT_VERSION=1.0 CC_UPGRADE_VERSION=1.1 -CC_INIT_ARGS='{"Args":["init","a","100","b","200"]}' -CC_UPGRADE_ARGS='{"Args":["upgrade","a","100","b","200"]}' -CC_INVOKE_ARGS='{"Args":["invoke","a","b","10"]}' -CC_QUERY_ARGS='{"Args":["query","a"]}' +CC_02_INIT_ARGS='{"Args":["init","a","100","b","200"]}' +CC_02_UPGRADE_ARGS='{"Args":["upgrade","a","100","b","200"]}' +CC_02_INVOKE_ARGS='{"Args":["invoke","a","b","10"]}' +CC_02_QUERY_ARGS='{"Args":["query","a"]}' # TLS config CORE_PEER_TLS_ENABLED="true" # Generate configs -GEN_IMG=yeasy/hyperledger-fabric:1.0.2 # working dir is `/go/src/github.com/hyperledger/fabric` +GEN_IMG=yeasy/hyperledger-fabric:latest # working dir is `/go/src/github.com/hyperledger/fabric` GEN_CONTAINER=generator FABRIC_CFG_PATH=/etc/hyperledger/fabric CHANNEL_ARTIFACTS=channel-artifacts @@ -67,7 +66,7 @@ UPDATE_ANCHOR_ORG1_TX=Org1MSPanchors.tx UPDATE_ANCHOR_ORG2_TX=Org2MSPanchors.tx # CONFIGTXLATOR -CTL_IMG=yeasy/hyperledger-fabric:1.0.2 +CTL_IMG=yeasy/hyperledger-fabric:latest CTL_CONTAINER=configtxlator CTL_BASE_URL=http://127.0.0.1:7059 CTL_ENCODE_URL=${CTL_BASE_URL}/protolator/encode diff --git a/hyperledger_fabric/v1.0.2/solo/channel-artifacts/new_businesschannel.tx.json b/hyperledger_fabric/v1.0.2/solo/channel-artifacts/new_businesschannel.tx.json index e69de29b..bb669a4b 100644 --- a/hyperledger_fabric/v1.0.2/solo/channel-artifacts/new_businesschannel.tx.json +++ b/hyperledger_fabric/v1.0.2/solo/channel-artifacts/new_businesschannel.tx.json @@ -0,0 +1,113 @@ +{ + "payload": { + "data": { + "config_update": { + "channel_id": "businesschannel", + "read_set": { + "groups": { + "Application": { + "groups": { + "Org1MSP": { + "mod_policy": "", + "version": "0" + }, + "Org2MSP": { + "mod_policy": "", + "version": "0" + } + }, + "mod_policy": "", + "version": "0" + } + }, + "mod_policy": "", + "values": { + "Consortium": { + "mod_policy": "", + "value": { + "name": "SampleConsortium" + }, + "version": "0" + } + }, + "version": "0" + }, + "type": 0, + "write_set": { + "groups": { + "Application": { + "groups": { + "Org1MSP": { + "mod_policy": "", + "version": "0" + }, + "Org2MSP": { + "mod_policy": "", + "version": "0" + } + }, + "mod_policy": "Admins", + "policies": { + "Admins": { + "mod_policy": "Admins", + "policy": { + "type": 3, + "value": { + "rule": "MAJORITY", + "sub_policy": "Admins" + } + }, + "version": "0" + }, + "Readers": { + "mod_policy": "Admins", + "policy": { + "type": 3, + "value": { + "rule": "ANY", + "sub_policy": "Readers" + } + }, + "version": "0" + }, + "Writers": { + "mod_policy": "Admins", + "policy": { + "type": 3, + "value": { + "rule": "ANY", + "sub_policy": "Writers" + } + }, + "version": "0" + } + }, + "version": "1" + } + }, + "mod_policy": "", + "values": { + "Consortium": { + "mod_policy": "", + "value": { + "name": "SampleConsortium" + }, + "version": "0" + } + }, + "version": "0" + } + } + }, + "header": { + "channel_header": { + "channel_id": "businesschannel", + "epoch": "0", + "timestamp": "2018-01-03T13:09:56.000Z", + "tx_id": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "type": 2, + "version": 0 + } + } + } +} diff --git a/hyperledger_fabric/v1.0.2/solo/examples/chaincode/go/chaincode_example02/chaincode_example02.go b/hyperledger_fabric/v1.0.2/solo/examples/chaincode/go/chaincode_example02/chaincode_example02.go deleted file mode 100644 index 53438066..00000000 --- a/hyperledger_fabric/v1.0.2/solo/examples/chaincode/go/chaincode_example02/chaincode_example02.go +++ /dev/null @@ -1,199 +0,0 @@ -/* -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) - } -}