github.com/Finschia/finschia-sdk@v0.48.1/x/bank/types/key.go (about) 1 package types 2 3 import ( 4 sdk "github.com/Finschia/finschia-sdk/types" 5 "github.com/Finschia/finschia-sdk/types/address" 6 "github.com/Finschia/finschia-sdk/types/kv" 7 ) 8 9 const ( 10 // ModuleName defines the module name 11 ModuleName = "bank" 12 13 // StoreKey defines the primary module store key 14 StoreKey = ModuleName 15 16 // RouterKey defines the module's message routing key 17 RouterKey = ModuleName 18 19 // QuerierRoute defines the module's query routing key 20 QuerierRoute = ModuleName 21 ) 22 23 // KVStore keys 24 var ( 25 // BalancesPrefix is the prefix for the account balances store. We use a byte 26 // (instead of `[]byte("balances")` to save some disk space). 27 BalancesPrefix = []byte{0x02} 28 SupplyKey = []byte{0x00} 29 DenomMetadataPrefix = []byte{0x1} 30 ) 31 32 // AddressFromBalancesStore returns an account address from a balances prefix 33 // store. The key must not contain the prefix BalancesPrefix as the prefix store 34 // iterator discards the actual prefix. 35 // 36 // If invalid key is passed, AddressFromBalancesStore returns ErrInvalidKey. 37 func AddressFromBalancesStore(key []byte) (sdk.AccAddress, error) { 38 if len(key) == 0 { 39 return nil, ErrInvalidKey 40 } 41 kv.AssertKeyAtLeastLength(key, 1) 42 addrLen := key[0] 43 bound := int(addrLen) 44 if len(key)-1 < bound { 45 return nil, ErrInvalidKey 46 } 47 return key[1 : bound+1], nil 48 } 49 50 // CreateAccountBalancesPrefix creates the prefix for an account's balances. 51 func CreateAccountBalancesPrefix(addr []byte) []byte { 52 return append(BalancesPrefix, address.MustLengthPrefix(addr)...) 53 } 54 55 // CreatePrefixedAccountStoreKey returns the key for the given account and denomination. 56 // This method can be used when performing an ABCI query for the balance of an account. 57 func CreatePrefixedAccountStoreKey(addr []byte, denom []byte) []byte { 58 return append(CreateAccountBalancesPrefix(addr), denom...) 59 }