-
Notifications
You must be signed in to change notification settings - Fork 197
/
trieStub.go
213 lines (170 loc) · 5.09 KB
/
trieStub.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package trie
import (
"context"
"errors"
"github.com/ElrondNetwork/elrond-go/common"
)
var errNotImplemented = errors.New("not implemented")
// TrieStub -
type TrieStub struct {
GetCalled func(key []byte) ([]byte, uint32, error)
UpdateCalled func(key, value []byte) error
DeleteCalled func(key []byte) error
RootCalled func() ([]byte, error)
CommitCalled func() error
RecreateCalled func(root []byte) (common.Trie, error)
RecreateFromEpochCalled func(options common.RootHashHolder) (common.Trie, error)
GetObsoleteHashesCalled func() [][]byte
AppendToOldHashesCalled func([][]byte)
GetSerializedNodesCalled func([]byte, uint64) ([][]byte, uint64, error)
GetAllHashesCalled func() ([][]byte, error)
GetAllLeavesOnChannelCalled func(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, keyBuilder common.KeyBuilder) error
GetProofCalled func(key []byte) ([][]byte, []byte, error)
VerifyProofCalled func(rootHash []byte, key []byte, proof [][]byte) (bool, error)
GetStorageManagerCalled func() common.StorageManager
GetSerializedNodeCalled func(bytes []byte) ([]byte, error)
GetNumNodesCalled func() common.NumNodesDTO
GetOldRootCalled func() []byte
CloseCalled func() error
}
// GetStorageManager -
func (ts *TrieStub) GetStorageManager() common.StorageManager {
if ts.GetStorageManagerCalled != nil {
return ts.GetStorageManagerCalled()
}
return nil
}
// GetProof -
func (ts *TrieStub) GetProof(key []byte) ([][]byte, []byte, error) {
if ts.GetProofCalled != nil {
return ts.GetProofCalled(key)
}
return nil, nil, nil
}
// VerifyProof -
func (ts *TrieStub) VerifyProof(rootHash []byte, key []byte, proof [][]byte) (bool, error) {
if ts.VerifyProofCalled != nil {
return ts.VerifyProofCalled(rootHash, key, proof)
}
return false, nil
}
// GetAllLeavesOnChannel -
func (ts *TrieStub) GetAllLeavesOnChannel(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, keyBuilder common.KeyBuilder) error {
if ts.GetAllLeavesOnChannelCalled != nil {
return ts.GetAllLeavesOnChannelCalled(leavesChannels, ctx, rootHash, keyBuilder)
}
return nil
}
// Get -
func (ts *TrieStub) Get(key []byte) ([]byte, uint32, error) {
if ts.GetCalled != nil {
return ts.GetCalled(key)
}
return nil, 0, errNotImplemented
}
// Update -
func (ts *TrieStub) Update(key, value []byte) error {
if ts.UpdateCalled != nil {
return ts.UpdateCalled(key, value)
}
return errNotImplemented
}
// Delete -
func (ts *TrieStub) Delete(key []byte) error {
if ts.DeleteCalled != nil {
return ts.DeleteCalled(key)
}
return errNotImplemented
}
// RootHash -
func (ts *TrieStub) RootHash() ([]byte, error) {
if ts.RootCalled != nil {
return ts.RootCalled()
}
return nil, errNotImplemented
}
// Commit -
func (ts *TrieStub) Commit() error {
if ts.CommitCalled != nil {
return ts.CommitCalled()
}
return errNotImplemented
}
// Recreate -
func (ts *TrieStub) Recreate(root []byte) (common.Trie, error) {
if ts.RecreateCalled != nil {
return ts.RecreateCalled(root)
}
return nil, errNotImplemented
}
// RecreateFromEpoch -
func (ts *TrieStub) RecreateFromEpoch(options common.RootHashHolder) (common.Trie, error) {
if ts.RecreateFromEpochCalled != nil {
return ts.RecreateFromEpochCalled(options)
}
return nil, errNotImplemented
}
// String -
func (ts *TrieStub) String() string {
return "stub trie"
}
// IsInterfaceNil returns true if there is no value under the interface
func (ts *TrieStub) IsInterfaceNil() bool {
return ts == nil
}
// GetObsoleteHashes resets the oldHashes and oldRoot variables and returns the old hashes
func (ts *TrieStub) GetObsoleteHashes() [][]byte {
if ts.GetObsoleteHashesCalled != nil {
return ts.GetObsoleteHashesCalled()
}
return nil
}
// GetSerializedNodes -
func (ts *TrieStub) GetSerializedNodes(hash []byte, maxBuffToSend uint64) ([][]byte, uint64, error) {
if ts.GetSerializedNodesCalled != nil {
return ts.GetSerializedNodesCalled(hash, maxBuffToSend)
}
return nil, 0, nil
}
// GetDirtyHashes -
func (ts *TrieStub) GetDirtyHashes() (common.ModifiedHashes, error) {
return nil, nil
}
// SetNewHashes -
func (ts *TrieStub) SetNewHashes(_ common.ModifiedHashes) {
}
// GetAllHashes -
func (ts *TrieStub) GetAllHashes() ([][]byte, error) {
if ts.GetAllHashesCalled != nil {
return ts.GetAllHashesCalled()
}
return nil, nil
}
// GetSerializedNode -
func (ts *TrieStub) GetSerializedNode(bytes []byte) ([]byte, error) {
if ts.GetSerializedNodeCalled != nil {
return ts.GetSerializedNodeCalled(bytes)
}
return nil, nil
}
// GetNumNodes -
func (ts *TrieStub) GetNumNodes() common.NumNodesDTO {
if ts.GetNumNodesCalled != nil {
return ts.GetNumNodesCalled()
}
return common.NumNodesDTO{}
}
// GetOldRoot -
func (ts *TrieStub) GetOldRoot() []byte {
if ts.GetOldRootCalled != nil {
return ts.GetOldRootCalled()
}
return nil
}
// Close -
func (ts *TrieStub) Close() error {
if ts.CloseCalled != nil {
return ts.CloseCalled()
}
return nil
}