Skip to content

Commit

Permalink
feat(indexer): implement schema.HasModuleCodec interface in the `ba…
Browse files Browse the repository at this point in the history
…nk` module (#22349)

Co-authored-by: Facundo Medica <[email protected]>
  • Loading branch information
cool-develope and facundomedica authored Oct 30, 2024
1 parent ee16adb commit 6b6e715
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion x/bank/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions x/bank/keeper/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)),
}

Expand Down Expand Up @@ -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{})
}

0 comments on commit 6b6e715

Please sign in to comment.