github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/slashing/internal/types/keys.go (about)

     1  package types
     2  
     3  import (
     4  	"encoding/binary"
     5  
     6  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     7  )
     8  
     9  const (
    10  	// ModuleName is the name of the module
    11  	ModuleName = "slashing"
    12  
    13  	// StoreKey is the store key string for slashing
    14  	StoreKey = ModuleName
    15  
    16  	// RouterKey is the message route for slashing
    17  	RouterKey = ModuleName
    18  
    19  	// QuerierRoute is the querier route for slashing
    20  	QuerierRoute = ModuleName
    21  )
    22  
    23  // Keys for slashing store
    24  // Items are stored with the following key: values
    25  //
    26  // - 0x01<consAddress_Bytes>: ValidatorSigningInfo
    27  //
    28  // - 0x02<consAddress_Bytes><period_Bytes>: bool
    29  //
    30  // - 0x03<accAddr_Bytes>: crypto.PubKey
    31  var (
    32  	ValidatorSigningInfoKey         = []byte{0x01} // Prefix for signing info
    33  	ValidatorMissedBlockBitArrayKey = []byte{0x02} // Prefix for missed block bit array
    34  	AddrPubkeyRelationKey           = []byte{0x03} // Prefix for address-pubkey relation
    35  )
    36  
    37  // GetValidatorSigningInfoKey - stored by *Consensus* address (not operator address)
    38  func GetValidatorSigningInfoKey(v sdk.ConsAddress) []byte {
    39  	return append(ValidatorSigningInfoKey, v.Bytes()...)
    40  }
    41  
    42  // GetValidatorSigningInfoAddress - extract the address from a validator signing info key
    43  func GetValidatorSigningInfoAddress(key []byte) (v sdk.ConsAddress) {
    44  	addr := key[1:]
    45  	if len(addr) != sdk.AddrLen {
    46  		panic("unexpected key length")
    47  	}
    48  	return sdk.ConsAddress(addr)
    49  }
    50  
    51  // GetValidatorMissedBlockBitArrayPrefixKey - stored by *Consensus* address (not operator address)
    52  func GetValidatorMissedBlockBitArrayPrefixKey(v sdk.ConsAddress) []byte {
    53  	return append(ValidatorMissedBlockBitArrayKey, v.Bytes()...)
    54  }
    55  
    56  // GetValidatorMissedBlockBitArrayKey - stored by *Consensus* address (not operator address)
    57  func GetValidatorMissedBlockBitArrayKey(v sdk.ConsAddress, i int64) []byte {
    58  	b := make([]byte, 8)
    59  	binary.LittleEndian.PutUint64(b, uint64(i))
    60  	return append(GetValidatorMissedBlockBitArrayPrefixKey(v), b...)
    61  }
    62  
    63  // GetAddrPubkeyRelationKey gets pubkey relation key used to get the pubkey from the address
    64  func GetAddrPubkeyRelationKey(address []byte) []byte {
    65  	return append(AddrPubkeyRelationKey, address...)
    66  }