From b64fd45da0eb354e27377be3cf3fcb240484fd1e Mon Sep 17 00:00:00 2001 From: Ethan Fox Date: Thu, 4 Apr 2019 15:03:41 -0400 Subject: [PATCH] [FAB-15051] delStandard() function for high-throughput This change is to add a delStandard() function to the high-throughput fabric sample, as well as fix a typo in putStandard(). In addition to modifying the chaincode, an additional bash script, 'del-traditional.sh', was created to remotely delete a created asset from within the docker CLI in accordance with the sample walkthrough. This change is necessary to demonstrate the full capability of the fabric Shim library, such that no assets remain on the ledger that the user doesn't want This change was tested on a local deployment of Fabric 1.4, using the 'Basic Network' asset that was created by Ethan Fox for internal use by the IBM Blockchain Innovation Unit within GBS Global. Change-Id: I34488dc3131f817563568a43f923856fecb07a5a Signed-off-by: Ethan Fox --- high-throughput/README.md | 2 +- high-throughput/chaincode/high-throughput.go | 15 ++++++++++++++- high-throughput/scripts/del-traditional.sh | 7 +++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 high-throughput/scripts/del-traditional.sh diff --git a/high-throughput/README.md b/high-throughput/README.md index 8ce49eb67b..6e85bff38b 100644 --- a/high-throughput/README.md +++ b/high-throughput/README.md @@ -170,7 +170,7 @@ row in the ledger 1000 times, with a value incrementing by one each time (i.e. t expectation would be that the final value of the row is 999. However, the final value changes each time this script is run and you'll find errors in the peer and orderer logs. -There is one other script, `get-traditional.sh`, which simply gets the value of a row in the traditional way, with no deltas. +There are two other scripts, `get-traditional.sh`, which simply gets the value of a row in the traditional way, with no deltas, and `del-traditional.sh` will delete an asset in the traditional way. Examples: `./many-updates.sh testvar 100 +` --> final value from `./get-invoke.sh testvar` should be 100000 diff --git a/high-throughput/chaincode/high-throughput.go b/high-throughput/chaincode/high-throughput.go index 00997a65dd..b54173262d 100644 --- a/high-throughput/chaincode/high-throughput.go +++ b/high-throughput/chaincode/high-throughput.go @@ -71,6 +71,8 @@ func (s *SmartContract) Invoke(APIstub shim.ChaincodeStubInterface) sc.Response return s.putStandard(APIstub, args) } else if function == "getstandard" { return s.getStandard(APIstub, args) + } else if function == "delstandard" { + return s.delStandard(APIstub, args) } return shim.Error("Invalid Smart Contract function name.") @@ -360,7 +362,7 @@ func (s *SmartContract) putStandard(APIstub shim.ChaincodeStubInterface, args [] _, getErr := APIstub.GetState(name) if getErr != nil { - return shim.Error(fmt.Sprintf("Failed to retrieve the statr of %s: %s", name, getErr.Error())) + return shim.Error(fmt.Sprintf("Failed to retrieve the state of %s: %s", name, getErr.Error())) } putErr := APIstub.PutState(name, []byte(valStr)) @@ -381,3 +383,14 @@ func (s *SmartContract) getStandard(APIstub shim.ChaincodeStubInterface, args [] return shim.Success(val) } + +func (s *SmartContract) delStandard(APIstub shim.ChaincodeStubInterface, args []string) sc.Response { + name := args[0] + + getErr := APIstub.DelState(name) + if getErr != nil { + return shim.Error(fmt.Sprintf("Failed to delete state: %s", getErr.Error())) + } + + return shim.Success(nil) +} diff --git a/high-throughput/scripts/del-traditional.sh b/high-throughput/scripts/del-traditional.sh new file mode 100644 index 0000000000..954fab8ac8 --- /dev/null +++ b/high-throughput/scripts/del-traditional.sh @@ -0,0 +1,7 @@ +# +# Copyright IBM Corp All Rights Reserved +# +# SPDX-License-Identifier: Apache-2.0 +# + +peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n $CC_NAME -c '{"Args":["delstandard","'$1'"]}' \ No newline at end of file