-
Notifications
You must be signed in to change notification settings - Fork 198
/
interface.go
103 lines (89 loc) · 3.1 KB
/
interface.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
package state
import (
"github.com/ElrondNetwork/elrond-go/data"
)
// HashLength defines how many bytes are used in a hash
const HashLength = 32
// AddressConverter is used to convert to/from AddressContainer
type AddressConverter interface {
AddressLen() int
CreateAddressFromPublicKeyBytes(pubKey []byte) (AddressContainer, error)
ConvertToHex(addressContainer AddressContainer) (string, error)
CreateAddressFromHex(hexAddress string) (AddressContainer, error)
PrepareAddressBytes(addressBytes []byte) ([]byte, error)
IsInterfaceNil() bool
}
// AddressContainer models what an Address struct should do
type AddressContainer interface {
Bytes() []byte
IsInterfaceNil() bool
}
// AccountFactory creates an account of different types
type AccountFactory interface {
CreateAccount(address AddressContainer, tracker AccountTracker) (AccountHandler, error)
IsInterfaceNil() bool
}
// AccountTracker saves an account state and journalizes new entries
type AccountTracker interface {
SaveAccount(accountHandler AccountHandler) error
Journalize(entry JournalEntry)
IsInterfaceNil() bool
}
// Updater set a new value for a key, implemented by trie
type Updater interface {
Update(key, value []byte) error
IsInterfaceNil() bool
}
// AccountHandler models a state account, which can journalize and revert
// It knows about code and data, as data structures not hashes
type AccountHandler interface {
AddressContainer() AddressContainer
GetCodeHash() []byte
SetCodeHash([]byte)
SetCodeHashWithJournal([]byte) error
GetCode() []byte
SetCode(code []byte)
SetNonce(nonce uint64)
GetNonce() uint64
SetNonceWithJournal(nonce uint64) error
GetRootHash() []byte
SetRootHash([]byte)
SetRootHashWithJournal([]byte) error
DataTrie() data.Trie
SetDataTrie(trie data.Trie)
DataTrieTracker() DataTrieTracker
IsInterfaceNil() bool
}
// DataTrieTracker models what how to manipulate data held by a SC account
type DataTrieTracker interface {
ClearDataCaches()
DirtyData() map[string][]byte
OriginalValue(key []byte) []byte
RetrieveValue(key []byte) ([]byte, error)
SaveKeyValue(key []byte, value []byte)
SetDataTrie(tr data.Trie)
DataTrie() data.Trie
IsInterfaceNil() bool
}
// AccountsAdapter is used for the structure that manages the accounts on top of a trie.PatriciaMerkleTrie
// implementation
type AccountsAdapter interface {
GetAccountWithJournal(addressContainer AddressContainer) (AccountHandler, error) // will create if it not exist
GetExistingAccount(addressContainer AddressContainer) (AccountHandler, error)
HasAccount(addressContainer AddressContainer) (bool, error)
RemoveAccount(addressContainer AddressContainer) error
Commit() ([]byte, error)
JournalLen() int
RevertToSnapshot(snapshot int) error
RootHash() ([]byte, error)
RecreateTrie(rootHash []byte) error
PutCode(accountHandler AccountHandler, code []byte) error
RemoveCode(codeHash []byte) error
SaveDataTrie(accountHandler AccountHandler) error
IsInterfaceNil() bool
}
// JournalEntry will be used to implement different state changes to be able to easily revert them
type JournalEntry interface {
Revert() (AccountHandler, error)
IsInterfaceNil() bool
}