From de52035a5cbbbaefbdbd11abcc12b635060e00e1 Mon Sep 17 00:00:00 2001 From: Flamewind97 Date: Thu, 13 Apr 2023 15:19:02 +0200 Subject: [PATCH] add singleKVS wrapper --- ecc_go/chaincode/singleKVS.go | 45 ++++++++++++++++++++++ samples/chaincode/secret-keeper-go/main.go | 5 ++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 ecc_go/chaincode/singleKVS.go diff --git a/ecc_go/chaincode/singleKVS.go b/ecc_go/chaincode/singleKVS.go new file mode 100644 index 000000000..9ea6ab01c --- /dev/null +++ b/ecc_go/chaincode/singleKVS.go @@ -0,0 +1,45 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package chaincode + +import ( + "fmt" + + "github.com/hyperledger/fabric-chaincode-go/shim" + "github.com/hyperledger/fabric-private-chaincode/ecc/chaincode" +) + +var SingleKey = "SingleKey" + +type SKVSWrapper struct { + *chaincode.EnclaveChaincode +} + +type skvsStub struct { + shim.ChaincodeStubInterface +} + +func (s *skvsStub) GetState(key string) ([]byte, error) { + fmt.Printf("Inside SKVS solution, GetState, key=%s\n", key) + return s.ChaincodeStubInterface.GetState(SingleKey) + // return s.ChaincodeStubInterface.GetState(key) +} + +func (s *skvsStub) PutState(key string, value []byte) error { + fmt.Printf("Inside SKVS solution, PutState, key=%s, value=%x\n", key, value) + return s.ChaincodeStubInterface.PutState(SingleKey, value) + // return s.ChaincodeStubInterface.PutState(key, value) +} + +func (s *SKVSWrapper) GetStub() shim.ChaincodeStubInterface { + // get the original stub + stub := s.GetStub() + fmt.Println("Inside SKVS solution, GetStub") + // create a new stub with the overridden GetState() function + skvsStub := &skvsStub{stub} + return skvsStub +} diff --git a/samples/chaincode/secret-keeper-go/main.go b/samples/chaincode/secret-keeper-go/main.go index a8f707f1b..b3b1515a0 100644 --- a/samples/chaincode/secret-keeper-go/main.go +++ b/samples/chaincode/secret-keeper-go/main.go @@ -25,11 +25,14 @@ func main() { secretChaincode, _ := contractapi.NewChaincode(&chaincode.SecretKeeper{}) chaincode := fpc.NewPrivateChaincode(secretChaincode) + // single KVS + skvsChaincode := &fpc.SingleKVSWrapper{chaincode} + // start chaincode as a service server := &shim.ChaincodeServer{ CCID: ccid, Address: addr, - CC: chaincode, + CC: skvsChaincode, TLSProps: shim.TLSProperties{ Disabled: true, // just for testing good enough },