-
Notifications
You must be signed in to change notification settings - Fork 199
/
readOnlySCContainer.go
55 lines (44 loc) · 1.55 KB
/
readOnlySCContainer.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
package factory
import (
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-go/vm"
)
// readOnlySCContainer is a wrapper over a scContainer which works read-only. write operations are disabled
type readOnlySCContainer struct {
scContainer vm.SystemSCContainer
}
// NewReadOnlySCContainer returns a new instance of readOnlySCContainer
func NewReadOnlySCContainer(scContainer vm.SystemSCContainer) (*readOnlySCContainer, error) {
if check.IfNil(scContainer) {
return nil, vm.ErrNilSystemContractsContainer
}
return &readOnlySCContainer{scContainer: scContainer}, nil
}
// Get returns the object stored at a certain key.
// Returns an error if the element does not exist
func (r *readOnlySCContainer) Get(key []byte) (vm.SystemSmartContract, error) {
return r.scContainer.Get(key)
}
// Add is disabled from readOnlySCContainer
func (r *readOnlySCContainer) Add(_ []byte, _ vm.SystemSmartContract) error {
return nil
}
// Replace is disabled from readOnlySCContainer
func (r *readOnlySCContainer) Replace(_ []byte, _ vm.SystemSmartContract) error {
return nil
}
// Remove is disabled from readOnlySCContainer
func (r *readOnlySCContainer) Remove(_ []byte) {
}
// Len returns the number of containers
func (r *readOnlySCContainer) Len() int {
return r.scContainer.Len()
}
// Keys returns all the keys from the containers
func (r *readOnlySCContainer) Keys() [][]byte {
return r.scContainer.Keys()
}
// IsInterfaceNil returns true if underlying object is nil
func (r *readOnlySCContainer) IsInterfaceNil() bool {
return r == nil
}