-
Notifications
You must be signed in to change notification settings - Fork 180
/
key_mpt.go
76 lines (63 loc) · 1.77 KB
/
key_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 types
import (
"bytes"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
)
const (
Uint64Length = 8
)
// Below are the keys which are different from the key in iavl
var (
UpgradedKeyPrefixCode = rawdb.CodePrefix // Old: KeyPrefixCode = []byte{0x04}
)
/*
* KeyPrefixBlockHash = []byte{0x01}
* KeyPrefixBloom = []byte{0x02}
* UpgradedKeyPrefixCode = []byte{"c"}
* KeyPrefixStorage not stored in db directly
* KeyPrefixChainConfig = []byte{0x06}
* KeyPrefixHeightHash = []byte{0x07}
*
* Below are functions used for setting in DiskDB
*/
/*
* Append
*/
func AppendBlockHashKey(blockHash []byte) []byte {
return append(KeyPrefixBlockHash, blockHash...)
}
func AppendBloomKey(height int64) []byte {
return append(KeyPrefixBloom, BloomKey(height)...)
}
func AppendUpgradedCodeKey(codeHash []byte) []byte {
return append(UpgradedKeyPrefixCode, codeHash...)
}
func AppendHeightHashKey(height uint64) []byte {
return append(KeyPrefixHeightHash, HeightHashKey(height)...)
}
/*
* Split
*/
func SplitUpgradedCodeHashKey(key []byte) []byte {
return key[len(UpgradedKeyPrefixCode):]
}
/*
* IsKey
*/
func IsBlockHashKey(key []byte) bool {
return bytes.HasPrefix(key, KeyPrefixBlockHash) &&
len(key) == (len(KeyPrefixBlockHash)+ethcmn.HashLength)
}
func IsBloomKey(key []byte) bool {
return bytes.HasPrefix(key, KeyPrefixBloom) &&
len(key) == (len(KeyPrefixBloom)+Uint64Length)
}
func IsCodeHashKey(key []byte) bool {
return bytes.HasPrefix(key, UpgradedKeyPrefixCode) &&
len(key) == (len(UpgradedKeyPrefixCode)+ethcmn.HashLength)
}
func IsHeightHashKey(key []byte) bool {
return bytes.HasPrefix(key, KeyPrefixHeightHash) &&
len(key) == (len(KeyPrefixHeightHash)+Uint64Length)
}