From 0e1710a0f8606ecb78b12c9405127f377bc5e970 Mon Sep 17 00:00:00 2001 From: guanghonglu Date: Tue, 7 Feb 2023 18:02:26 +0800 Subject: [PATCH] fix: add GetStateFromKeyWithExists method and log --bug=1004998 --- sdk/mock_sdk_interface.go | 16 ++++++++++++++++ sdk/sdk.go | 4 ++++ sdk/sdk_interface.go | 16 ++++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/sdk/mock_sdk_interface.go b/sdk/mock_sdk_interface.go index 2d89283..43daadd 100644 --- a/sdk/mock_sdk_interface.go +++ b/sdk/mock_sdk_interface.go @@ -398,6 +398,22 @@ func (mr *MockSDKInterfaceMockRecorder) GetStateFromKeyByte(key interface{}) *go return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStateFromKeyByte", reflect.TypeOf((*MockSDKInterface)(nil).GetStateFromKeyByte), key) } +// GetStateFromKeyWithExists mocks base method. +func (m *MockSDKInterface) GetStateFromKeyWithExists(key string) (string, bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStateFromKeyWithExists", key) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(bool) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetStateFromKeyWithExists indicates an expected call of GetStateFromKeyWithExists. +func (mr *MockSDKInterfaceMockRecorder) GetStateFromKeyWithExists(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStateFromKeyWithExists", reflect.TypeOf((*MockSDKInterface)(nil).GetStateFromKeyWithExists), key) +} + // GetStateWithExists mocks base method. func (m *MockSDKInterface) GetStateWithExists(key, field string) (string, bool, error) { m.ctrl.T.Helper() diff --git a/sdk/sdk.go b/sdk/sdk.go index fe69df2..bbd6978 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -206,6 +206,10 @@ func (s *SDK) GetStateFromKey(key string) (string, error) { return s.GetState(key, "") } +func (s *SDK) GetStateFromKeyWithExists(key string) (string, bool, error) { + return s.GetStateWithExists(key, "") +} + func (s *SDK) GetStateFromKeyByte(key string) ([]byte, error) { return s.GetStateByte(key, "") } diff --git a/sdk/sdk_interface.go b/sdk/sdk_interface.go index 48b432b..a6581e3 100644 --- a/sdk/sdk_interface.go +++ b/sdk/sdk_interface.go @@ -34,12 +34,13 @@ type SDKInterface interface { // @param field: 获取的参数名 // @return1: 获取结果,格式为string // @return2: 获取错误信息 + // Deprecated GetState(key, field string) (string, error) // GetStateWithExists get [key, field] from chain and db // @param key: 获取的参数名 // @param field: 获取的参数名 // @return1: 获取结果,格式为string - // @return2: 是否存在,bool + // @return2: 是否存在,bool, 字符串长度为0不代表不存在 // @return3: 获取错误信息 GetStateWithExists(key, field string) (string, bool, error) // GetBatchState get [BatchKeys] from chain and db @@ -50,17 +51,24 @@ type SDKInterface interface { // GetStateByte get [key, field] from chain and db // @param key: 获取的参数名 // @param field: 获取的参数名 - // @return1: 获取结果,格式为[]byte + // @return1: 获取结果,格式为[]byte, nil表示不存在 // @return2: 获取错误信息 GetStateByte(key, field string) ([]byte, error) // GetStateFromKey get [key] from chain and db // @param key: 获取的参数名 // @return1: 获取结果,格式为string // @return2: 获取错误信息 + // Deprecated GetStateFromKey(key string) (string, error) + // GetStateFromKeyWithExists get [key] from chain and db + // @param key: 获取的参数名 + // @return1: 获取结果,格式为string + // @return2: 是否存在,bool, 字符串长度为0不代表不存在 + // @return3: 获取错误信息 + GetStateFromKeyWithExists(key string) (string, bool, error) // GetStateFromKeyByte get [key] from chain and db // @param key: 获取的参数名 - // @return1: 获取结果,格式为[]byte + // @return1: 获取结果,格式为[]byte, nil表示不存在 // @return2: 获取错误信息 GetStateFromKeyByte(key string) ([]byte, error) // PutState put [key, field, value] to chain @@ -196,7 +204,7 @@ type SDKInterface interface { // GetSenderAddr Get the address of the origin caller address, same with Origin() // @return1: origin caller address // @return2: 获取错误信息 - //Deprecated + // Deprecated GetSenderAddr() (string, error) // Sender Get the address of the sender address, if the contract is called by another contract, the result will be // the caller contract's address -- GitLab