github.com/darrenli6/fabric-sdk-example@v0.0.0-20220109053535-94b13b56df8c/common/mocks/ledger/queryexecutor.go (about) 1 /* 2 Copyright IBM Corp. 2017 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package ledger 18 19 import ( 20 "fmt" 21 22 "github.com/hyperledger/fabric/common/ledger" 23 ) 24 25 type MockQueryExecutor struct { 26 // State keeps all namepspaces 27 State map[string]map[string][]byte 28 } 29 30 func NewMockQueryExecutor(state map[string]map[string][]byte) *MockQueryExecutor { 31 return &MockQueryExecutor{ 32 State: state, 33 } 34 } 35 36 func (m *MockQueryExecutor) GetState(namespace string, key string) ([]byte, error) { 37 ns := m.State[namespace] 38 if ns == nil { 39 return nil, fmt.Errorf("Could not retrieve namespace %s", namespace) 40 } 41 42 return ns[key], nil 43 } 44 45 func (m *MockQueryExecutor) GetStateMultipleKeys(namespace string, keys []string) ([][]byte, error) { 46 return nil, nil 47 48 } 49 50 func (m *MockQueryExecutor) GetStateRangeScanIterator(namespace string, startKey string, endKey string) (ledger.ResultsIterator, error) { 51 return nil, nil 52 53 } 54 55 func (m *MockQueryExecutor) ExecuteQuery(namespace, query string) (ledger.ResultsIterator, error) { 56 return nil, nil 57 } 58 59 func (m *MockQueryExecutor) Done() { 60 61 }