-
Notifications
You must be signed in to change notification settings - Fork 199
/
whiteListDataVerifier.go
54 lines (43 loc) · 1.3 KB
/
whiteListDataVerifier.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
package interceptors
import (
"fmt"
"github.com/ElrondNetwork/elrond-go/core/check"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/storage"
)
var _ process.WhiteListHandler = (*whiteListDataVerifier)(nil)
type whiteListDataVerifier struct {
cache storage.Cacher
}
// NewWhiteListDataVerifier returns a default data verifier
func NewWhiteListDataVerifier(cacher storage.Cacher) (*whiteListDataVerifier, error) {
if check.IfNil(cacher) {
return nil, fmt.Errorf("%w in NewWhiteListDataVerifier", process.ErrNilCacher)
}
return &whiteListDataVerifier{
cache: cacher,
}, nil
}
// IsWhiteListed return true if intercepted data is accepted
func (w *whiteListDataVerifier) IsWhiteListed(interceptedData process.InterceptedData) bool {
if check.IfNil(interceptedData) {
return false
}
return w.cache.Has(interceptedData.Hash())
}
// Add adds all the list to the cache
func (w *whiteListDataVerifier) Add(keys [][]byte) {
for _, key := range keys {
_ = w.cache.Put(key, struct{}{})
}
}
// Remove removes all the keys from the cache
func (w *whiteListDataVerifier) Remove(keys [][]byte) {
for _, key := range keys {
w.cache.Remove(key)
}
}
// IsInterfaceNil returns true if underlying object is nil
func (w *whiteListDataVerifier) IsInterfaceNil() bool {
return w == nil
}