Co-authored-by: testinginprod <98415576+testinginprod@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
parent
73aa872155
commit
981c294d1d
@ -94,26 +94,26 @@ func (a genericAddressKey[T]) SizeNonTerminal(key T) int {
|
||||
return collections.BytesKey.SizeNonTerminal(key)
|
||||
}
|
||||
|
||||
// Deprecated: genericAddressIndexKey is a special key codec used to retain state backwards compatibility
|
||||
// Deprecated: lengthPrefixedAddressKey is a special key codec used to retain state backwards compatibility
|
||||
// when a generic address key (be: AccAddress, ValAddress, ConsAddress), is used as an index key.
|
||||
// More docs can be found in the AddressKeyAsIndexKey function.
|
||||
type genericAddressIndexKey[T addressUnion] struct {
|
||||
// More docs can be found in the LengthPrefixedAddressKey function.
|
||||
type lengthPrefixedAddressKey[T addressUnion] struct {
|
||||
collcodec.KeyCodec[T]
|
||||
}
|
||||
|
||||
func (g genericAddressIndexKey[T]) Encode(buffer []byte, key T) (int, error) {
|
||||
func (g lengthPrefixedAddressKey[T]) Encode(buffer []byte, key T) (int, error) {
|
||||
return g.EncodeNonTerminal(buffer, key)
|
||||
}
|
||||
|
||||
func (g genericAddressIndexKey[T]) Decode(buffer []byte) (int, T, error) {
|
||||
func (g lengthPrefixedAddressKey[T]) Decode(buffer []byte) (int, T, error) {
|
||||
return g.DecodeNonTerminal(buffer)
|
||||
}
|
||||
|
||||
func (g genericAddressIndexKey[T]) Size(key T) int { return g.SizeNonTerminal(key) }
|
||||
func (g lengthPrefixedAddressKey[T]) Size(key T) int { return g.SizeNonTerminal(key) }
|
||||
|
||||
func (g genericAddressIndexKey[T]) KeyType() string { return "index_key/" + g.KeyCodec.KeyType() }
|
||||
func (g lengthPrefixedAddressKey[T]) KeyType() string { return "index_key/" + g.KeyCodec.KeyType() }
|
||||
|
||||
// Deprecated: AddressKeyAsIndexKey implements an SDK backwards compatible indexing key encoder
|
||||
// Deprecated: LengthPrefixedAddressKey implements an SDK backwards compatible indexing key encoder
|
||||
// for addresses.
|
||||
// The status quo in the SDK is that address keys are length prefixed even when they're the
|
||||
// last part of a composite key. This should never be used unless to retain state compatibility.
|
||||
@ -122,8 +122,8 @@ func (g genericAddressIndexKey[T]) KeyType() string { return "index_key/" + g.Ke
|
||||
// byte to the string, then when you know when the string part finishes, it's logical that the
|
||||
// part which remains is the address key. In the SDK instead we prepend to the address key its
|
||||
// length too.
|
||||
func AddressKeyAsIndexKey[T addressUnion](keyCodec collcodec.KeyCodec[T]) collcodec.KeyCodec[T] {
|
||||
return genericAddressIndexKey[T]{
|
||||
func LengthPrefixedAddressKey[T addressUnion](keyCodec collcodec.KeyCodec[T]) collcodec.KeyCodec[T] {
|
||||
return lengthPrefixedAddressKey[T]{
|
||||
keyCodec,
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ func TestCollectionsCorrectness(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("AddressIndexingKey", func(t *testing.T) {
|
||||
colltest.TestKeyCodec(t, AddressKeyAsIndexKey(AccAddressKey), AccAddress{0x2, 0x5, 0x8})
|
||||
colltest.TestKeyCodec(t, LengthPrefixedAddressKey(AccAddressKey), AccAddress{0x2, 0x5, 0x8})
|
||||
})
|
||||
|
||||
t.Run("Time", func(t *testing.T) {
|
||||
|
||||
@ -42,7 +42,7 @@ func newBalancesIndexes(sb *collections.SchemaBuilder) BalancesIndexes {
|
||||
return BalancesIndexes{
|
||||
Denom: indexes.NewReversePair[math.Int](
|
||||
sb, types.DenomAddressPrefix, "address_by_denom_index",
|
||||
collections.PairKeyCodec(sdk.AddressKeyAsIndexKey(sdk.AccAddressKey), collections.StringKey), // nolint:staticcheck // Note: refer to the AddressKeyAsIndexKey docs to understand why we do this.
|
||||
collections.PairKeyCodec(sdk.LengthPrefixedAddressKey(sdk.AccAddressKey), collections.StringKey), // nolint:staticcheck // Note: refer to the LengthPrefixedAddressKey docs to understand why we do this.
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,8 +103,8 @@ func NewKeeper(
|
||||
authority: authority,
|
||||
Constitution: collections.NewItem(sb, types.ConstitutionKey, "constitution", collections.StringValue),
|
||||
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[v1.Params](cdc)),
|
||||
Deposits: collections.NewMap(sb, types.DepositsKeyPrefix, "deposits", collections.PairKeyCodec(collections.Uint64Key, sdk.AddressKeyAsIndexKey(sdk.AccAddressKey)), codec.CollValue[v1.Deposit](cdc)), // nolint: staticcheck // sdk.AddressKeyAsIndexKey is needed to retain state compatibility
|
||||
Votes: collections.NewMap(sb, types.VotesKeyPrefix, "votes", collections.PairKeyCodec(collections.Uint64Key, sdk.AddressKeyAsIndexKey(sdk.AccAddressKey)), codec.CollValue[v1.Vote](cdc)), // nolint: staticcheck // sdk.AddressKeyAsIndexKey is needed to retain state compatibility
|
||||
Deposits: collections.NewMap(sb, types.DepositsKeyPrefix, "deposits", collections.PairKeyCodec(collections.Uint64Key, sdk.LengthPrefixedAddressKey(sdk.AccAddressKey)), codec.CollValue[v1.Deposit](cdc)), // nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility
|
||||
Votes: collections.NewMap(sb, types.VotesKeyPrefix, "votes", collections.PairKeyCodec(collections.Uint64Key, sdk.LengthPrefixedAddressKey(sdk.AccAddressKey)), codec.CollValue[v1.Vote](cdc)), // nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility
|
||||
ProposalID: collections.NewSequence(sb, types.ProposalIDKey, "proposal_id"),
|
||||
Proposals: collections.NewMap(sb, types.ProposalsKeyPrefix, "proposals", collections.Uint64Key, codec.CollValue[v1.Proposal](cdc)),
|
||||
ActiveProposalsQueue: collections.NewMap(sb, types.ActiveProposalQueuePrefix, "active_proposals_queue", collections.PairKeyCodec(sdk.TimeKey, collections.Uint64Key), collections.Uint64Value), // sdk.TimeKey is needed to retain state compatibility
|
||||
|
||||
Loading…
Reference in New Issue
Block a user