diff --git a/x/bank/go.mod b/x/bank/go.mod index 87e20a338b7f..8f3ff02f12b1 100644 --- a/x/bank/go.mod +++ b/x/bank/go.mod @@ -160,8 +160,9 @@ require ( sigs.k8s.io/yaml v1.4.0 // indirect ) +require cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 + require ( - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect github.com/cosmos/cosmos-db v1.0.3-0.20240911104526-ddc3f09bfc22 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/x/bank/keeper/view.go b/x/bank/keeper/view.go index 496e907de8ca..08dc56300077 100644 --- a/x/bank/keeper/view.go +++ b/x/bank/keeper/view.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/core/appmodule" errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" + "cosmossdk.io/schema" "cosmossdk.io/x/bank/types" "github.com/cosmos/cosmos-sdk/codec" @@ -78,10 +79,10 @@ func NewBaseViewKeeper(env appmodule.Environment, cdc codec.BinaryCodec, ak type cdc: cdc, ak: ak, addrCdc: ak.AddressCodec(), - Supply: collections.NewMap(sb, types.SupplyKey, "supply", collections.StringKey, sdk.IntValue), - DenomMetadata: collections.NewMap(sb, types.DenomMetadataPrefix, "denom_metadata", collections.StringKey, codec.CollValue[types.Metadata](cdc)), - SendEnabled: collections.NewMap(sb, types.SendEnabledPrefix, "send_enabled", collections.StringKey, codec.BoolValue), // NOTE: we use a bool value which uses protobuf to retain state backwards compat - Balances: collections.NewIndexedMap(sb, types.BalancesPrefix, "balances", collections.PairKeyCodec(sdk.AccAddressKey, collections.StringKey), types.BalanceValueCodec, newBalancesIndexes(sb)), + Supply: collections.NewMap(sb, types.SupplyKey, "supply", collections.StringKey.WithName("supply"), sdk.IntValue), + DenomMetadata: collections.NewMap(sb, types.DenomMetadataPrefix, "denom_metadata", collections.StringKey.WithName("denom_metadata"), codec.CollValue[types.Metadata](cdc)), + SendEnabled: collections.NewMap(sb, types.SendEnabledPrefix, "send_enabled", collections.StringKey.WithName("send_enabled"), codec.BoolValue), // NOTE: we use a bool value which uses protobuf to retain state backwards compat + Balances: collections.NewIndexedMap(sb, types.BalancesPrefix, "balances", collections.NamedPairKeyCodec("address", sdk.AccAddressKey, "balances", collections.StringKey), types.BalanceValueCodec, newBalancesIndexes(sb)), Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), } @@ -256,3 +257,9 @@ func (k BaseViewKeeper) ValidateBalance(ctx context.Context, addr sdk.AccAddress return nil } + +// ModuleCodec implements `schema.HasModuleCodec` interface. +// It allows the indexer to decode the module's KVPairUpdate. +func (k BaseViewKeeper) ModuleCodec() (schema.ModuleCodec, error) { + return k.Schema.ModuleCodec(collections.IndexingOptions{}) +}