github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/evm/types/key.go (about) 1 package types 2 3 import ( 4 ethcmn "github.com/ethereum/go-ethereum/common" 5 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 6 ) 7 8 const ( 9 // ModuleName string name of module 10 ModuleName = "evm" 11 12 // StoreKey key for ethereum storage data, account code (StateDB) or block 13 // related data for Web3. 14 // The EVM module should use a prefix store. 15 StoreKey = ModuleName 16 17 // RouterKey uses module name for routing 18 RouterKey = ModuleName 19 20 // SysContractAddressKey uses for save system contract address 21 SysContractAddressKey = "sysContractAddress" 22 ) 23 24 // KVStore key prefixes 25 var ( 26 KeyPrefixBlockHash = []byte{0x01} 27 KeyPrefixBloom = []byte{0x02} 28 KeyPrefixCode = []byte{0x04} 29 KeyPrefixStorage = []byte{0x05} 30 KeyPrefixChainConfig = []byte{0x06} 31 KeyPrefixHeightHash = []byte{0x07} 32 KeyPrefixContractDeploymentWhitelist = []byte{0x08} 33 KeyPrefixContractBlockedList = []byte{0x09} 34 KeyPrefixSysContractAddress = []byte{0x10} 35 KeyPrefixContractCodeHash = []byte{0x11} 36 37 KeyPrefixEvmRootHash = []byte("evmRootHash") 38 ) 39 40 // HeightHashKey returns the key for the given chain epoch and height. 41 // The key will be composed in the following order: 42 // 43 // key = prefix + bytes(height) 44 // 45 // This ordering facilitates the iteration by height for the EVM GetHashFn 46 // queries. 47 func HeightHashKey(height uint64) []byte { 48 return sdk.Uint64ToBigEndian(height) 49 } 50 51 // BloomKey defines the store key for a block Bloom 52 func BloomKey(height int64) []byte { 53 return sdk.Uint64ToBigEndian(uint64(height)) 54 } 55 56 // AddressStoragePrefix returns a prefix to iterate over a given account storage. 57 func AddressStoragePrefix(address ethcmn.Address) []byte { 58 return append(KeyPrefixStorage, address.Bytes()...) 59 } 60 61 // getContractDeploymentWhitelistMemberKey builds the key for an approved contract deployer 62 func GetContractDeploymentWhitelistMemberKey(distributorAddr sdk.AccAddress) []byte { 63 return append(KeyPrefixContractDeploymentWhitelist, distributorAddr...) 64 } 65 66 // splitApprovedDeployerAddress splits the deployer address from a ContractDeploymentWhitelistMemberKey 67 func splitApprovedDeployerAddress(key []byte) sdk.AccAddress { 68 return key[1:] 69 } 70 71 // getContractBlockedListMemberKey builds the key for a blocked contract address 72 func GetContractBlockedListMemberKey(contractAddr sdk.AccAddress) []byte { 73 return append(KeyPrefixContractBlockedList, contractAddr...) 74 } 75 76 // splitBlockedContractAddress splits the blocked contract address from a ContractBlockedListMemberKey 77 func splitBlockedContractAddress(key []byte) sdk.AccAddress { 78 return key[1:] 79 } 80 81 // GetSysContractAddressKey builds the key for system contract address 82 func GetSysContractAddressKey() []byte { 83 return append(KeyPrefixSysContractAddress, []byte(SysContractAddressKey)...) 84 } 85 86 func GetInitContractCodeHashKey(contractAddr sdk.AccAddress) []byte { 87 return append(KeyPrefixContractCodeHash, contractAddr...) 88 }