github.com/Finschia/finschia-sdk@v0.48.1/x/slashing/types/keys.go (about)

     1  package types
     2  
     3  import (
     4  	"encoding/binary"
     5  
     6  	sdk "github.com/Finschia/finschia-sdk/types"
     7  	"github.com/Finschia/finschia-sdk/types/address"
     8  	"github.com/Finschia/finschia-sdk/types/kv"
     9  )
    10  
    11  const (
    12  	// ModuleName is the name of the module
    13  	ModuleName = "slashing"
    14  
    15  	// StoreKey is the store key string for slashing
    16  	StoreKey = ModuleName
    17  
    18  	// RouterKey is the message route for slashing
    19  	RouterKey = ModuleName
    20  
    21  	// QuerierRoute is the querier route for slashing
    22  	QuerierRoute = ModuleName
    23  )
    24  
    25  // Keys for slashing store
    26  // Items are stored with the following key: values
    27  //
    28  // - 0x01<consAddrLen (1 Byte)><consAddress_Bytes>: ValidatorSigningInfo
    29  //
    30  // - 0x02<consAddrLen (1 Byte)><consAddress_Bytes><period_Bytes>: bool
    31  //
    32  // - 0x03<accAddrLen (1 Byte)><accAddr_Bytes>: cryptotypes.PubKey
    33  var (
    34  	ValidatorSigningInfoKeyPrefix         = []byte{0x01} // Prefix for signing info
    35  	ValidatorMissedBlockBitArrayKeyPrefix = []byte{0x02} // Prefix for missed block bit array
    36  	AddrPubkeyRelationKeyPrefix           = []byte{0x03} // Prefix for address-pubkey relation
    37  )
    38  
    39  // ValidatorSigningInfoKey - stored by *Consensus* address (not operator address)
    40  func ValidatorSigningInfoKey(v sdk.ConsAddress) []byte {
    41  	return append(ValidatorSigningInfoKeyPrefix, address.MustLengthPrefix(v.Bytes())...)
    42  }
    43  
    44  // ValidatorSigningInfoAddress - extract the address from a validator signing info key
    45  func ValidatorSigningInfoAddress(key []byte) (v sdk.ConsAddress) {
    46  	// Remove prefix and address length.
    47  	kv.AssertKeyAtLeastLength(key, 3)
    48  	addr := key[2:]
    49  
    50  	return sdk.ConsAddress(addr)
    51  }
    52  
    53  // ValidatorMissedBlockBitArrayPrefixKey - stored by *Consensus* address (not operator address)
    54  func ValidatorMissedBlockBitArrayPrefixKey(v sdk.ConsAddress) []byte {
    55  	return append(ValidatorMissedBlockBitArrayKeyPrefix, address.MustLengthPrefix(v.Bytes())...)
    56  }
    57  
    58  // ValidatorMissedBlockBitArrayKey - stored by *Consensus* address (not operator address)
    59  func ValidatorMissedBlockBitArrayKey(v sdk.ConsAddress, i int64) []byte {
    60  	b := make([]byte, 8)
    61  	binary.LittleEndian.PutUint64(b, uint64(i))
    62  
    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(addr []byte) []byte {
    68  	return append(AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(addr)...)
    69  }