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

     1  package types
     2  
     3  import sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     4  
     5  const (
     6  	// ModuleName is the module name constant used in many places
     7  	ModuleName = "distribution"
     8  
     9  	// StoreKey is the store key string for distribution
    10  	StoreKey = ModuleName
    11  
    12  	// RouterKey is the message route for distribution
    13  	RouterKey = ModuleName
    14  
    15  	// QuerierRoute is the querier route for distribution
    16  	QuerierRoute = ModuleName
    17  
    18  	// ShortUseByCli added for fbchaincli
    19  	ShortUseByCli = "distr"
    20  )
    21  
    22  // Keys for distribution store
    23  // Items are stored with the following key: values
    24  //
    25  // - 0x01: sdk.ConsAddress
    26  //
    27  // - 0x03<accAddr_Bytes>: sdk.AccAddress
    28  //
    29  // - 0x07<valAddr_Bytes>: ValidatorCurrentRewards
    30  var (
    31  	FeePoolKey                           = []byte{0x00} // key for global distribution state
    32  	ProposerKey                          = []byte{0x01} // key for the proposer operator address
    33  	DelegatorWithdrawAddrPrefix          = []byte{0x03} // key for delegator withdraw address
    34  	ValidatorAccumulatedCommissionPrefix = []byte{0x07} // key for accumulated validator commission
    35  )
    36  
    37  // GetDelegatorWithdrawInfoAddress returns an address from a delegator's withdraw info key
    38  func GetDelegatorWithdrawInfoAddress(key []byte) (delAddr sdk.AccAddress) {
    39  	addr := key[1:]
    40  	if len(addr) != sdk.AddrLen {
    41  		panic("unexpected key length")
    42  	}
    43  	return sdk.AccAddress(addr)
    44  }
    45  
    46  // GetValidatorAccumulatedCommissionAddress returns the address from a validator's accumulated commission key
    47  func GetValidatorAccumulatedCommissionAddress(key []byte) (valAddr sdk.ValAddress) {
    48  	addr := key[1:]
    49  	if len(addr) != sdk.AddrLen {
    50  		panic("unexpected key length")
    51  	}
    52  	return sdk.ValAddress(addr)
    53  }
    54  
    55  // GetDelegatorWithdrawAddrKey returns the key for a delegator's withdraw addr
    56  func GetDelegatorWithdrawAddrKey(delAddr sdk.AccAddress) []byte {
    57  	return append(DelegatorWithdrawAddrPrefix, delAddr.Bytes()...)
    58  }
    59  
    60  // GetValidatorAccumulatedCommissionKey returns the key for a validator's current commission
    61  func GetValidatorAccumulatedCommissionKey(v sdk.ValAddress) []byte {
    62  	return append(ValidatorAccumulatedCommissionPrefix, v.Bytes()...)
    63  }