Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com>
This commit is contained in:
parent
46be66ed42
commit
abd0bd5b10
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/address"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -15,8 +16,8 @@ const (
|
||||
|
||||
var (
|
||||
DelegationKey = []byte{0x31} // key for a delegation
|
||||
DelegationByValIndexKey = []byte{0x37} // key for delegations by a validator
|
||||
HistoricalInfoKey = []byte{0x50} // prefix for the historical info
|
||||
DelegationByValIndexKey = []byte{0x71} // key for delegations by a validator
|
||||
)
|
||||
|
||||
// ParseDelegationKey parses given key and returns delagator, validator address bytes
|
||||
@ -59,3 +60,14 @@ func GetHistoricalInfoKey(height int64) []byte {
|
||||
binary.BigEndian.PutUint64(heightBytes, uint64(height))
|
||||
return append(HistoricalInfoKey, heightBytes...)
|
||||
}
|
||||
|
||||
// GetDelegationsByValPrefixKey builds a prefix key bytes with the given validator address bytes.
|
||||
func GetDelegationsByValPrefixKey(valAddr sdk.ValAddress) []byte {
|
||||
return append(DelegationByValIndexKey, address.MustLengthPrefix(valAddr)...)
|
||||
}
|
||||
|
||||
// GetDelegationsByValKey creates the key for delegations by validator address
|
||||
// VALUE: staking/Delegation
|
||||
func GetDelegationsByValKey(valAddr sdk.ValAddress, delAddr sdk.AccAddress) []byte {
|
||||
return append(GetDelegationsByValPrefixKey(valAddr), delAddr...)
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ func getValDelegations(ctx sdk.Context, cdc codec.Codec, storeKey storetypes.Sto
|
||||
var delegations []stakingtypes.Delegation
|
||||
|
||||
store := ctx.KVStore(storeKey)
|
||||
iterator := storetypes.KVStorePrefixIterator(store, stakingtypes.GetDelegationsByValPrefixKey(valAddr))
|
||||
iterator := storetypes.KVStorePrefixIterator(store, v5.GetDelegationsByValPrefixKey(valAddr))
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
var delegation stakingtypes.Delegation
|
||||
valAddr, delAddr, err := stakingtypes.ParseDelegationsByValKey(iterator.Key())
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
func migrateDelegationsByValidatorIndex(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
|
||||
@ -23,7 +22,7 @@ func migrateDelegationsByValidatorIndex(ctx sdk.Context, store storetypes.KVStor
|
||||
return err
|
||||
}
|
||||
|
||||
store.Set(types.GetDelegationsByValKey(val, del), []byte{})
|
||||
store.Set(GetDelegationsByValKey(val, del), []byte{})
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Loading…
Reference in New Issue
Block a user