github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/evm/types/key_mpt.go (about)

     1  package types
     2  
     3  import (
     4  	"bytes"
     5  
     6  	ethcmn "github.com/ethereum/go-ethereum/common"
     7  	"github.com/ethereum/go-ethereum/core/rawdb"
     8  )
     9  
    10  const (
    11  	Uint64Length = 8
    12  )
    13  
    14  // Below are the keys which are different from the key in iavl
    15  var (
    16  	UpgradedKeyPrefixCode = rawdb.CodePrefix // Old: KeyPrefixCode = []byte{0x04}
    17  )
    18  
    19  /*
    20   * KeyPrefixBlockHash         = []byte{0x01}
    21   * KeyPrefixBloom             = []byte{0x02}
    22   * UpgradedKeyPrefixCode      = []byte{"c"}
    23   * KeyPrefixStorage           not stored in db directly
    24   * KeyPrefixChainConfig       = []byte{0x06}
    25   * KeyPrefixHeightHash        = []byte{0x07}
    26   *
    27   * Below are functions used for setting in DiskDB
    28   */
    29  /*
    30   * Append
    31   */
    32  func AppendBlockHashKey(blockHash []byte) []byte {
    33  	return append(KeyPrefixBlockHash, blockHash...)
    34  }
    35  
    36  func AppendBloomKey(height int64) []byte {
    37  	return append(KeyPrefixBloom, BloomKey(height)...)
    38  }
    39  
    40  func AppendUpgradedCodeKey(codeHash []byte) []byte {
    41  	return append(UpgradedKeyPrefixCode, codeHash...)
    42  }
    43  
    44  func AppendHeightHashKey(height uint64) []byte {
    45  	return append(KeyPrefixHeightHash, HeightHashKey(height)...)
    46  }
    47  
    48  /*
    49   * Split
    50   */
    51  func SplitUpgradedCodeHashKey(key []byte) []byte {
    52  	return key[len(UpgradedKeyPrefixCode):]
    53  }
    54  
    55  /*
    56   * IsKey
    57   */
    58  func IsBlockHashKey(key []byte) bool {
    59  	return bytes.HasPrefix(key, KeyPrefixBlockHash) &&
    60  		len(key) == (len(KeyPrefixBlockHash)+ethcmn.HashLength)
    61  }
    62  
    63  func IsBloomKey(key []byte) bool {
    64  	return bytes.HasPrefix(key, KeyPrefixBloom) &&
    65  		len(key) == (len(KeyPrefixBloom)+Uint64Length)
    66  }
    67  
    68  func IsCodeHashKey(key []byte) bool {
    69  	return bytes.HasPrefix(key, UpgradedKeyPrefixCode) &&
    70  		len(key) == (len(UpgradedKeyPrefixCode)+ethcmn.HashLength)
    71  }
    72  
    73  func IsHeightHashKey(key []byte) bool {
    74  	return bytes.HasPrefix(key, KeyPrefixHeightHash) &&
    75  		len(key) == (len(KeyPrefixHeightHash)+Uint64Length)
    76  }