-
Notifications
You must be signed in to change notification settings - Fork 0
/
keeper_mpt.go
76 lines (67 loc) · 1.99 KB
/
keeper_mpt.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
package keeper
import (
"encoding/binary"
ethtypes "github.com/ethereum/go-ethereum/core/types"
sdk "github.com/furyaxyz/fuxchain/libs/cosmos-sdk/types"
"github.com/furyaxyz/fuxchain/x/evm/types"
)
/*
* Getters for keys in x/evm/types/keys.go
* TODO: these interfaces are used for setting/getting data in rawdb, instead of iavl.
* TODO: delete these if we decide persist data in iavl.
*/
func (k Keeper) getBlockHashInDiskDB(hash []byte) (int64, bool) {
key := types.AppendBlockHashKey(hash)
bz, err := k.db.TrieDB().DiskDB().Get(key)
if err != nil {
return 0, false
}
if len(bz) == 0 {
return 0, false
}
height := binary.BigEndian.Uint64(bz)
return int64(height), true
}
func (k Keeper) setBlockHashInDiskDB(hash []byte, height int64) {
key := types.AppendBlockHashKey(hash)
bz := sdk.Uint64ToBigEndian(uint64(height))
k.db.TrieDB().DiskDB().Put(key, bz)
}
func (k Keeper) iterateBlockHashInDiskDB(fn func(key []byte, value []byte) (stop bool)) {
iterator := k.db.TrieDB().DiskDB().NewIterator(types.KeyPrefixBlockHash, nil)
defer iterator.Release()
for iterator.Next() {
if !types.IsBlockHashKey(iterator.Key()) {
continue
}
key, value := iterator.Key(), iterator.Value()
if stop := fn(key, value); stop {
break
}
}
}
func (k Keeper) getBlockBloomInDiskDB(height int64) ethtypes.Bloom {
key := types.AppendBloomKey(height)
bz, err := k.db.TrieDB().DiskDB().Get(key)
if err != nil {
return ethtypes.Bloom{}
}
return ethtypes.BytesToBloom(bz)
}
func (k Keeper) setBlockBloomInDiskDB(height int64, bloom ethtypes.Bloom) {
key := types.AppendBloomKey(height)
k.db.TrieDB().DiskDB().Put(key, bloom.Bytes())
}
func (k Keeper) iterateBlockBloomInDiskDB(fn func(key []byte, value []byte) (stop bool)) {
iterator := k.db.TrieDB().DiskDB().NewIterator(types.KeyPrefixBloom, nil)
defer iterator.Release()
for iterator.Next() {
if !types.IsBloomKey(iterator.Key()) {
continue
}
key, value := iterator.Key(), iterator.Value()
if stop := fn(key, value); stop {
break
}
}
}