github.com/Finschia/finschia-sdk@v0.48.1/x/slashing/legacy/v040/keys.go (about) 1 // Package v040 is copy-pasted from: 2 // https://github.com/cosmos/cosmos-sdk/blob/v0.41.0/x/slashing/types/keys.go 3 package v040 4 5 import ( 6 "encoding/binary" 7 8 sdk "github.com/Finschia/finschia-sdk/types" 9 "github.com/Finschia/finschia-sdk/types/kv" 10 v040auth "github.com/Finschia/finschia-sdk/x/auth/legacy/v040" 11 ) 12 13 const ( 14 // ModuleName is the name of the module 15 ModuleName = "slashing" 16 17 // StoreKey is the store key string for slashing 18 StoreKey = ModuleName 19 20 // RouterKey is the message route for slashing 21 RouterKey = ModuleName 22 23 // QuerierRoute is the querier route for slashing 24 QuerierRoute = ModuleName 25 ) 26 27 // Keys for slashing store 28 // Items are stored with the following key: values 29 // 30 // - 0x01<consAddress_Bytes>: ValidatorSigningInfo 31 // 32 // - 0x02<consAddress_Bytes><period_Bytes>: bool 33 // 34 // - 0x03<accAddr_Bytes>: crypto.PubKey 35 var ( 36 ValidatorSigningInfoKeyPrefix = []byte{0x01} // Prefix for signing info 37 ValidatorMissedBlockBitArrayKeyPrefix = []byte{0x02} // Prefix for missed block bit array 38 AddrPubkeyRelationKeyPrefix = []byte{0x03} // Prefix for address-pubkey relation 39 ) 40 41 // ValidatorSigningInfoKey - stored by *Consensus* address (not operator address) 42 func ValidatorSigningInfoKey(v sdk.ConsAddress) []byte { 43 return append(ValidatorSigningInfoKeyPrefix, v.Bytes()...) 44 } 45 46 // ValidatorSigningInfoAddress - extract the address from a validator signing info key 47 func ValidatorSigningInfoAddress(key []byte) (v sdk.ConsAddress) { 48 kv.AssertKeyAtLeastLength(key, 2) 49 addr := key[1:] 50 kv.AssertKeyLength(addr, v040auth.AddrLen) 51 return sdk.ConsAddress(addr) 52 } 53 54 // ValidatorMissedBlockBitArrayPrefixKey - stored by *Consensus* address (not operator address) 55 func ValidatorMissedBlockBitArrayPrefixKey(v sdk.ConsAddress) []byte { 56 return append(ValidatorMissedBlockBitArrayKeyPrefix, v.Bytes()...) 57 } 58 59 // ValidatorMissedBlockBitArrayKey - stored by *Consensus* address (not operator address) 60 func ValidatorMissedBlockBitArrayKey(v sdk.ConsAddress, i int64) []byte { 61 b := make([]byte, 8) 62 binary.LittleEndian.PutUint64(b, uint64(i)) 63 return append(ValidatorMissedBlockBitArrayPrefixKey(v), b...) 64 } 65 66 // AddrPubkeyRelationKey gets pubkey relation key used to get the pubkey from the address 67 func AddrPubkeyRelationKey(address []byte) []byte { 68 return append(AddrPubkeyRelationKeyPrefix, address...) 69 }