Update chaincode name more speficicly
parent
adb7753e6f
commit
ae342ef96b
|
@ -4,7 +4,7 @@
|
||||||
HLF_MODE ?= solo
|
HLF_MODE ?= solo
|
||||||
HLF_VERSION ?= 1.0.2
|
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
|
NETWORK_INIT_WAIT=2 # time to wait the fabric network finish initialization
|
||||||
|
|
||||||
COMPOSE_FILE ?= "docker-compose-2orgs-4peers-solo.yaml"
|
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 gen_config # Will ignore if local config path exists
|
||||||
make start
|
make start
|
||||||
|
|
||||||
|
if [ "$(HLF_MODE)" = "dev" ]; then \
|
||||||
|
sleep ${CODE_BUILD_WAIT}; \
|
||||||
|
else \
|
||||||
|
sleep ${NETWORK_INIT_WAIT}; \
|
||||||
|
fi
|
||||||
|
|
||||||
make test_channel_create
|
make test_channel_create
|
||||||
make test_channel_join
|
make test_channel_join
|
||||||
make update_anchors
|
#make update_anchors
|
||||||
|
|
||||||
make test_cc_install
|
make test_cc_install
|
||||||
make test_cc_instantiate
|
make test_cc_instantiate
|
||||||
make test_cc_invoke_query
|
#make test_cc_invoke_query
|
||||||
|
|
||||||
make test_lscc # test lscc operations
|
#make test_lscc # test lscc operations
|
||||||
make test_qscc # test qscc operations
|
#make test_qscc # test qscc operations
|
||||||
|
|
||||||
#make test_fetch_blocks # fetch block files
|
#make test_fetch_blocks # fetch block files
|
||||||
#make test_config_update
|
#make test_config_update
|
||||||
#make test_channel_update
|
#make test_channel_update
|
||||||
|
|
||||||
make logs_save
|
#make logs_save
|
||||||
make test_fetch_blocks # fetch block files again
|
#make test_fetch_blocks # fetch block files again
|
||||||
make test_configtxlator
|
#make test_configtxlator
|
||||||
|
|
||||||
@echo "Now the fabric network is ready to play"
|
@echo "Now the fabric network is ready to play"
|
||||||
@echo "run 'make cli' to enter into the fabric-cli container."
|
@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
|
peer: # enter the peer container
|
||||||
docker exec -it peer0.org1.example.com bash
|
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
|
ps: # show existing docker images
|
||||||
docker ps -a
|
docker ps -a
|
||||||
|
|
||||||
|
|
|
@ -88,10 +88,10 @@ services:
|
||||||
#- ./solo/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml
|
#- ./solo/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml
|
||||||
#- ./solo/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml
|
#- ./solo/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml
|
||||||
#- ./solo/crypto-config:/etc/hyperledger/fabric/crypto-config
|
#- ./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 mode configuration
|
||||||
- ./kafka/channel-artifacts:/tmp/channel-artifacts
|
- ./kafka/channel-artifacts:/tmp/channel-artifacts
|
||||||
- ./kafka/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml
|
- ./kafka/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml
|
||||||
- ./kafka/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml
|
- ./kafka/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml
|
||||||
- ./kafka/crypto-config:/etc/hyperledger/fabric/crypto-config
|
- ./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
|
||||||
|
|
|
@ -87,7 +87,7 @@ services:
|
||||||
- ./kafka/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml
|
- ./kafka/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml
|
||||||
- ./kafka/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml
|
- ./kafka/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml
|
||||||
- ./kafka/crypto-config:/etc/hyperledger/fabric/crypto-config
|
- ./kafka/crypto-config:/etc/hyperledger/fabric/crypto-config
|
||||||
- ./kafka/examples:/opt/gopath/src/examples
|
- ./examples:/opt/gopath/src/examples
|
||||||
|
|
||||||
## following are peer nodes ##
|
## following are peer nodes ##
|
||||||
|
|
||||||
|
|
|
@ -199,8 +199,8 @@ services:
|
||||||
- ./solo/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml
|
- ./solo/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml
|
||||||
- ./solo/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml
|
- ./solo/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml
|
||||||
- ./solo/crypto-config:/etc/hyperledger/fabric/crypto-config
|
- ./solo/crypto-config:/etc/hyperledger/fabric/crypto-config
|
||||||
- ./solo/examples:/opt/gopath/src/examples
|
- ./examples:/opt/gopath/src/examples
|
||||||
#- ./solo/examples:/opt/gopath/src/github.com/hyperledger/fabric/examples
|
#- ./examples:/opt/gopath/src/github.com/hyperledger/fabric/examples
|
||||||
|
|
||||||
event-listener:
|
event-listener:
|
||||||
extends:
|
extends:
|
||||||
|
@ -221,6 +221,6 @@ services:
|
||||||
- ./solo/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml
|
- ./solo/configtx.yaml:/etc/hyperledger/fabric/configtx.yaml
|
||||||
- ./solo/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml
|
- ./solo/crypto-config.yaml:/etc/hyperledger/fabric/crypto-config.yaml
|
||||||
- ./solo/crypto-config:/etc/hyperledger/fabric/crypto-config
|
- ./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 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'
|
#command: bash -c 'while true; do sleep 20170504; done'
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -440,6 +440,7 @@ chaincodeQuery () {
|
||||||
|
|
||||||
|
|
||||||
# Start chaincode with dev mode
|
# Start chaincode with dev mode
|
||||||
|
# TODO: use variables instead of hard-coded value
|
||||||
chaincodeStartDev () {
|
chaincodeStartDev () {
|
||||||
local peer=$1
|
local peer=$1
|
||||||
local version=$2
|
local version=$2
|
||||||
|
@ -448,7 +449,7 @@ chaincodeStartDev () {
|
||||||
setEnvs 1 0
|
setEnvs 1 0
|
||||||
CORE_CHAINCODE_LOGLEVEL=debug \
|
CORE_CHAINCODE_LOGLEVEL=debug \
|
||||||
CORE_PEER_ADDRESS=peer${peer}.org1.example.com:7052 \
|
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 &
|
nohup ./scripts/chaincode_example02 > chaincode_dev.log &
|
||||||
res=$?
|
res=$?
|
||||||
cat log.txt
|
cat log.txt
|
||||||
|
|
|
@ -25,7 +25,7 @@ channelUpdate ${APP_CHANNEL} 1 0 Org1MSPanchors.tx
|
||||||
|
|
||||||
## Install chaincode on all peers
|
## Install chaincode on all peers
|
||||||
echo_b "Installing chaincode on peer0..."
|
echo_b "Installing chaincode on peer0..."
|
||||||
chaincodeInstall 0 ${CC_INIT_ARGS}
|
chaincodeInstall 0 ${CC_02_INIT_ARGS}
|
||||||
|
|
||||||
# Instantiate chaincode on all peers
|
# Instantiate chaincode on all peers
|
||||||
# Instantiate can only be executed once on any node
|
# Instantiate can only be executed once on any node
|
||||||
|
|
|
@ -9,9 +9,9 @@ fi
|
||||||
|
|
||||||
## Install chaincode on all peers
|
## Install chaincode on all peers
|
||||||
echo_b "Installing chaincode on all 4 peers..."
|
echo_b "Installing chaincode on all 4 peers..."
|
||||||
chaincodeInstall 1 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
|
chaincodeInstall 1 0 ${CC_02_NAME} ${CC_INIT_VERSION} ${CC_02_PATH}
|
||||||
chaincodeInstall 1 1 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
|
chaincodeInstall 1 1 ${CC_02_NAME} ${CC_INIT_VERSION} ${CC_02_PATH}
|
||||||
chaincodeInstall 2 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
|
chaincodeInstall 2 0 ${CC_02_NAME} ${CC_INIT_VERSION} ${CC_02_PATH}
|
||||||
chaincodeInstall 2 1 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
|
chaincodeInstall 2 1 ${CC_02_NAME} ${CC_INIT_VERSION} ${CC_02_PATH}
|
||||||
|
|
||||||
echo_g "=== Install chaincode done ==="
|
echo_g "=== Install chaincode done ==="
|
|
@ -10,7 +10,7 @@ fi
|
||||||
# Instantiate chaincode on all peers
|
# Instantiate chaincode on all peers
|
||||||
# Instantiate can only be executed once on any node
|
# 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)..."
|
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}" 1 0 ${CC_02_NAME} ${CC_INIT_VERSION} ${CC_02_INIT_ARGS}
|
||||||
chaincodeInstantiate "${APP_CHANNEL}" 2 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_INIT_ARGS}
|
chaincodeInstantiate "${APP_CHANNEL}" 2 0 ${CC_02_NAME} ${CC_INIT_VERSION} ${CC_02_INIT_ARGS}
|
||||||
|
|
||||||
echo_g "=== Instantiate chaincode done ==="
|
echo_g "=== Instantiate chaincode done ==="
|
||||||
|
|
|
@ -9,24 +9,24 @@ fi
|
||||||
|
|
||||||
#Query on chaincode on Peer0/Org1
|
#Query on chaincode on Peer0/Org1
|
||||||
echo_b "Querying chaincode on peer org2/peer0..."
|
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
|
#Invoke on chaincode on Peer0/Org1
|
||||||
echo_b "Sending invoke transaction (transfer 10) on org1/peer0..."
|
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
|
#Query on chaincode on Peer1/Org2, check if the result is 90
|
||||||
echo_b "Querying chaincode on peer 1 and 3..."
|
echo_b "Querying chaincode on peer 1 and 3..."
|
||||||
chaincodeQuery ${APP_CHANNEL} 1 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_NAME} ${CC_QUERY_ARGS} 90
|
chaincodeQuery ${APP_CHANNEL} 2 1 ${CC_02_NAME} ${CC_02_QUERY_ARGS} 90
|
||||||
|
|
||||||
#Invoke on chaincode on Peer1/Org2
|
#Invoke on chaincode on Peer1/Org2
|
||||||
echo_b "Sending invoke transaction on org2/peer3..."
|
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
|
#Query on chaincode on Peer1/Org2, check if the result is 80
|
||||||
echo_b "Querying chaincode on all 4peers..."
|
echo_b "Querying chaincode on all 4peers..."
|
||||||
chaincodeQuery ${APP_CHANNEL} 1 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_NAME} ${CC_QUERY_ARGS} 80
|
chaincodeQuery ${APP_CHANNEL} 2 0 ${CC_02_NAME} ${CC_02_QUERY_ARGS} 80
|
||||||
|
|
||||||
echo_g "=== All GOOD, chaincode invoke/query completed ==="
|
echo_g "=== All GOOD, chaincode invoke/query completed ==="
|
||||||
|
|
|
@ -10,17 +10,17 @@ fi
|
||||||
echo_b "Channel name: "${APP_CHANNEL}
|
echo_b "Channel name: "${APP_CHANNEL}
|
||||||
|
|
||||||
echo_b "Query the existing value of a"
|
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
|
sleep 1
|
||||||
|
|
||||||
echo_b "Invoke a transaction to transfer 10 from a to b"
|
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
|
sleep 1
|
||||||
|
|
||||||
echo_b "Check if the result of a is 90"
|
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
|
||||||
echo_g "All GOOD, MVE Test completed"
|
echo_g "All GOOD, MVE Test completed"
|
||||||
|
|
|
@ -9,16 +9,16 @@ fi
|
||||||
|
|
||||||
#Upgrade to new version
|
#Upgrade to new version
|
||||||
echo_b "Upgrade chaincode to new version..."
|
echo_b "Upgrade chaincode to new version..."
|
||||||
chaincodeInstall 1 0 "${CC_NAME}" "${CC_UPGRADE_VERSION}" "${CC_PATH}"
|
chaincodeInstall 1 0 "${CC_02_NAME}" "${CC_UPGRADE_VERSION}" "${CC_02_PATH}"
|
||||||
chaincodeInstall 1 1 "${CC_NAME}" "${CC_UPGRADE_VERSION}" "${CC_PATH}"
|
chaincodeInstall 1 1 "${CC_02_NAME}" "${CC_UPGRADE_VERSION}" "${CC_02_PATH}"
|
||||||
chaincodeInstall 2 0 "${CC_NAME}" "${CC_UPGRADE_VERSION}" "${CC_PATH}"
|
chaincodeInstall 2 0 "${CC_02_NAME}" "${CC_UPGRADE_VERSION}" "${CC_02_PATH}"
|
||||||
chaincodeInstall 2 1 "${CC_NAME}" "${CC_UPGRADE_VERSION}" "${CC_PATH}"
|
chaincodeInstall 2 1 "${CC_02_NAME}" "${CC_UPGRADE_VERSION}" "${CC_02_PATH}"
|
||||||
|
|
||||||
# Upgrade on one peer of the channel will update all
|
# 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
|
# 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} 1 0 "${CC_02_NAME}" "${CC_02_QUERY_ARGS}" 100
|
||||||
chaincodeQuery ${APP_CHANNEL} 2 1 "${CC_NAME}" "${CC_QUERY_ARGS}" 100
|
chaincodeQuery ${APP_CHANNEL} 2 1 "${CC_02_NAME}" "${CC_02_QUERY_ARGS}" 100
|
||||||
|
|
||||||
echo_g "=== All GOOD, chaincode Upgrade completed ==="
|
echo_g "=== All GOOD, chaincode Upgrade completed ==="
|
||||||
|
|
|
@ -20,13 +20,13 @@ peer=0
|
||||||
#--cafile ${ORDERER_TLS_CA} \
|
#--cafile ${ORDERER_TLS_CA} \
|
||||||
|
|
||||||
echo_b "LSCC Get id"
|
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"
|
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"
|
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"
|
echo_b "LSCC Get all chaincodes installed on the channel"
|
||||||
chaincodeQuery "${APP_CHANNEL}" $org $peer lscc '{"Args":["getinstalledchaincodes"]}'
|
chaincodeQuery "${APP_CHANNEL}" $org $peer lscc '{"Args":["getinstalledchaincodes"]}'
|
||||||
|
@ -38,17 +38,17 @@ chaincodeQuery "${APP_CHANNEL}" $org $peer lscc '{"Args":["getchaincodes"]}'
|
||||||
#peer chaincode query \
|
#peer chaincode query \
|
||||||
# -C "${APP_CHANNEL}" \
|
# -C "${APP_CHANNEL}" \
|
||||||
# -n lscc \
|
# -n lscc \
|
||||||
# -c '{"Args":["getid","'${APP_CHANNEL}'", "'$CC_NAME'"]}'
|
# -c '{"Args":["getid","'${APP_CHANNEL}'", "'$CC_02_NAME'"]}'
|
||||||
|
|
||||||
#peer chaincode query \
|
#peer chaincode query \
|
||||||
# -C "${APP_CHANNEL}" \
|
# -C "${APP_CHANNEL}" \
|
||||||
# -n lscc \
|
# -n lscc \
|
||||||
# -c '{"Args":["getdepspec","'${APP_CHANNEL}'", "'$CC_NAME'"]}'
|
# -c '{"Args":["getdepspec","'${APP_CHANNEL}'", "'$CC_02_NAME'"]}'
|
||||||
|
|
||||||
#peer chaincode query \
|
#peer chaincode query \
|
||||||
# -C "${APP_CHANNEL}" \
|
# -C "${APP_CHANNEL}" \
|
||||||
# -n lscc \
|
# -n lscc \
|
||||||
# -c '{"Args":["getccdata","'${APP_CHANNEL}'", "'$CC_NAME'"]}'
|
# -c '{"Args":["getccdata","'${APP_CHANNEL}'", "'$CC_02_NAME'"]}'
|
||||||
|
|
||||||
#peer chaincode query \
|
#peer chaincode query \
|
||||||
# -C "${APP_CHANNEL}" \
|
# -C "${APP_CHANNEL}" \
|
||||||
|
|
|
@ -40,22 +40,21 @@ ORG2_PEER0_URL="peer0.org2.example.com:7051"
|
||||||
ORG2_PEER1_URL="peer1.org2.example.com:7051"
|
ORG2_PEER1_URL="peer1.org2.example.com:7051"
|
||||||
|
|
||||||
# Chaincode related
|
# Chaincode related
|
||||||
CC_NAME="mycc"
|
CC_02_NAME="exp02"
|
||||||
#CC_PATH="github.com/hyperledger/fabric/examples/chaincode/go/foodchain"
|
CC_02_PATH="examples/chaincode/go/chaincode_example02"
|
||||||
CC_PATH="examples/chaincode/go/chaincode_example02"
|
|
||||||
CC_INIT_VERSION=1.0
|
CC_INIT_VERSION=1.0
|
||||||
CC_UPGRADE_VERSION=1.1
|
CC_UPGRADE_VERSION=1.1
|
||||||
|
|
||||||
CC_INIT_ARGS='{"Args":["init","a","100","b","200"]}'
|
CC_02_INIT_ARGS='{"Args":["init","a","100","b","200"]}'
|
||||||
CC_UPGRADE_ARGS='{"Args":["upgrade","a","100","b","200"]}'
|
CC_02_UPGRADE_ARGS='{"Args":["upgrade","a","100","b","200"]}'
|
||||||
CC_INVOKE_ARGS='{"Args":["invoke","a","b","10"]}'
|
CC_02_INVOKE_ARGS='{"Args":["invoke","a","b","10"]}'
|
||||||
CC_QUERY_ARGS='{"Args":["query","a"]}'
|
CC_02_QUERY_ARGS='{"Args":["query","a"]}'
|
||||||
|
|
||||||
# TLS config
|
# TLS config
|
||||||
CORE_PEER_TLS_ENABLED="true"
|
CORE_PEER_TLS_ENABLED="true"
|
||||||
|
|
||||||
# Generate configs
|
# 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
|
GEN_CONTAINER=generator
|
||||||
FABRIC_CFG_PATH=/etc/hyperledger/fabric
|
FABRIC_CFG_PATH=/etc/hyperledger/fabric
|
||||||
CHANNEL_ARTIFACTS=channel-artifacts
|
CHANNEL_ARTIFACTS=channel-artifacts
|
||||||
|
@ -67,7 +66,7 @@ UPDATE_ANCHOR_ORG1_TX=Org1MSPanchors.tx
|
||||||
UPDATE_ANCHOR_ORG2_TX=Org2MSPanchors.tx
|
UPDATE_ANCHOR_ORG2_TX=Org2MSPanchors.tx
|
||||||
|
|
||||||
# CONFIGTXLATOR
|
# CONFIGTXLATOR
|
||||||
CTL_IMG=yeasy/hyperledger-fabric:1.0.2
|
CTL_IMG=yeasy/hyperledger-fabric:latest
|
||||||
CTL_CONTAINER=configtxlator
|
CTL_CONTAINER=configtxlator
|
||||||
CTL_BASE_URL=http://127.0.0.1:7059
|
CTL_BASE_URL=http://127.0.0.1:7059
|
||||||
CTL_ENCODE_URL=${CTL_BASE_URL}/protolator/encode
|
CTL_ENCODE_URL=${CTL_BASE_URL}/protolator/encode
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue