/
roots.go
39 lines (32 loc) · 1.1 KB
/
roots.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
package utxotrie
import (
"github.com/MadBase/MadNet/constants"
"github.com/MadBase/MadNet/constants/dbprefix"
"github.com/MadBase/MadNet/utils"
"github.com/dgraph-io/badger/v2"
)
func SetCurrentStateRoot(txn *badger.Txn, root []byte) error {
return utils.SetValue(txn, dbprefix.PrefixCurrentStateRoot(), root)
}
func GetCurrentStateRoot(txn *badger.Txn) ([]byte, error) {
root, err := utils.GetValue(txn, dbprefix.PrefixCurrentStateRoot())
if err != nil {
if err != badger.ErrKeyNotFound {
return nil, err
}
return make([]byte, constants.HashLen), nil
}
return root, nil
}
func SetPendingStateRoot(txn *badger.Txn, root []byte) error {
return utils.SetValue(txn, dbprefix.PrefixPendingStateRoot(), root)
}
func GetPendingStateRoot(txn *badger.Txn) ([]byte, error) {
return utils.GetValue(txn, dbprefix.PrefixPendingStateRoot())
}
func SetCanonicalStateRoot(txn *badger.Txn, root []byte) error {
return utils.SetValue(txn, dbprefix.PrefixCanonicalStateRoot(), root)
}
func GetCanonicalStateRoot(txn *badger.Txn) ([]byte, error) {
return utils.GetValue(txn, dbprefix.PrefixCanonicalStateRoot())
}