@@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
77package enclave_go
88
99import (
10- "encoding/hex"
1110 "encoding/json"
1211
1312 "github.com/hyperledger/fabric-chaincode-go/shim"
@@ -17,15 +16,15 @@ import (
1716
1817type SkvsStubInterface struct {
1918 * FpcStubInterface
20- allDataOld map [string ]string
21- allDataNew map [string ]string
19+ allDataOld map [string ][] byte
20+ allDataNew map [string ][] byte
2221 key string
2322}
2423
2524func NewSkvsStubInterface (stub shim.ChaincodeStubInterface , input * pb.ChaincodeInput , rwset * readWriteSet , sep StateEncryptionFunctions ) * SkvsStubInterface {
2625 logger .Warning ("==== Get New Skvs Interface =====" )
2726 fpcStub := NewFpcStubInterface (stub , input , rwset , sep )
28- skvsStub := SkvsStubInterface {fpcStub , map [string ]string {}, map [string ]string {}, "SKVS" }
27+ skvsStub := SkvsStubInterface {fpcStub , map [string ][] byte {}, map [string ][] byte {}, "SKVS" }
2928 err := skvsStub .InitSKVS ()
3029 if err != nil {
3130 logger .Warningf ("Error!! Initializing SKVS failed" )
@@ -59,39 +58,54 @@ func (s *SkvsStubInterface) InitSKVS() error {
5958 }
6059 }
6160
62- logger .Warningf ("SKVS Init finish, allDataOld = %s, allDataNew = %s" , s .allDataOld , s .allDataNew )
61+ logger .Warningf ("SKVS Init finish, allDataOld: %s, allDataNew: %s" , s .allDataOld , s .allDataNew )
6362 return nil
6463}
6564
6665func (s * SkvsStubInterface ) GetState (key string ) ([]byte , error ) {
67- logger .Warningf ("Calling Get State (Start), key = %s, alldataOld = %s" , key , s .allDataOld )
68- targetHex , found := s .allDataOld [key ]
66+ logger .Warningf ("Calling Get State (Start), key: %s, alldataOld: %s" , key , s .allDataOld )
67+ value , found := s .allDataOld [key ]
6968 if found != true {
7069 return nil , errors .New ("skvs allDataOld key not found" )
7170 }
72- targetBytes , err := hex .DecodeString (targetHex )
73- logger .Warningf ("Calling Get State (End), TargetHex: %s, TargetBytes: %x, err: %s" , targetHex , targetBytes , err )
74- return targetBytes , err
71+ logger .Warningf ("Calling Get State (End), key: %s, value: %x" , key , value )
72+ return value , nil
7573}
7674
7775func (s * SkvsStubInterface ) PutState (key string , value []byte ) error {
78- logger .Warningf ("Calling Put State (Start), key = %s, value = %x, alldata = %s" , key , value , s .allDataNew )
79-
80- valueHex := hex .EncodeToString (value )
81- s .allDataNew [key ] = valueHex
82- logger .Warningf ("Calling Put State (Mid-1), add need data key = %s, valueHex = %s, allData = %s" , key , valueHex , s .allDataNew )
76+ logger .Warningf ("Calling Put State (Start), key: %s, value: %x, alldata: %s" , key , value , s .allDataNew )
8377
78+ s .allDataNew [key ] = value
8479 byteAllData , err := json .Marshal (s .allDataNew )
8580 if err != nil {
8681 return err
8782 }
88- logger .Warningf ("Calling Put State (Mid-2), successfull marshal allData, byteAlldata = %x" , byteAllData )
89-
9083 encValue , err := s .sep .EncryptState (byteAllData )
9184 if err != nil {
9285 return err
9386 }
94- logger .Warningf ("Calling Put State (End), put encValue %x" , encValue )
87+ logger .Warningf ("Calling Put State (End), put encValue: %x" , encValue )
9588
9689 return s .PutPublicState (s .key , encValue )
9790}
91+
92+ func (s * SkvsStubInterface ) DelState (key string ) error {
93+ delete (s .allDataNew , key )
94+ byteAllData , err := json .Marshal (s .allDataNew )
95+ if err != nil {
96+ return err
97+ }
98+ encValue , err := s .sep .EncryptState (byteAllData )
99+ if err != nil {
100+ return err
101+ }
102+ return s .PutPublicState (s .key , encValue )
103+ }
104+
105+ func (s * SkvsStubInterface ) GetStateByRange (startKey string , endKey string ) (shim.StateQueryIteratorInterface , error ) {
106+ panic ("not implemented" ) // TODO: Implement
107+ }
108+
109+ func (s * SkvsStubInterface ) GetStateByRangeWithPagination (startKey string , endKey string , pageSize int32 , bookmark string ) (shim.StateQueryIteratorInterface , * pb.QueryResponseMetadata , error ) {
110+ panic ("not implemented" ) // TODO: Implement
111+ }
0 commit comments