Skip to content

Commit

Permalink
add singleKVS wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
chenchanglew committed Jun 11, 2024
1 parent 3568516 commit de52035
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
45 changes: 45 additions & 0 deletions ecc_go/chaincode/singleKVS.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 4 additions & 1 deletion samples/chaincode/secret-keeper-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down

0 comments on commit de52035

Please sign in to comment.