Skip to content

Commit

Permalink
Merge pull request #69 from initia-labs/chore/cleanup
Browse files Browse the repository at this point in the history
chore: cleanup/minor refactoring
  • Loading branch information
Vritra4 authored Dec 5, 2024
2 parents f8ff862 + 396f9c7 commit d436c08
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
# for private repo access
GOPRIVATE: github.com/initia-labs
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }}
GOLANGCI_LINT_VERSION: v1.59.1
GOLANGCI_LINT_VERSION: v1.62.2
name: golangci-lint
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ linters:
- dogsled
- dupl
- errcheck
- exportloopref
- copyloopvar
- goconst
- gofmt
- goimports
Expand Down
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))

# process linker flags
# TODO:
ldflags =

# DB backend selection
Expand Down Expand Up @@ -101,10 +100,6 @@ ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif

# The below include contains the tools and runsim targets.
# FIXME: uncomment the line below
#include contrib/devtools/Makefile

all: lint test


Expand Down
23 changes: 23 additions & 0 deletions collection/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package collection

import (
"cosmossdk.io/collections"
"github.com/cosmos/cosmos-sdk/types/query"
)

// WithCollectionPaginationTriplePrefix applies a prefix to a collection, whose key is a collection.Triple,
// being paginated that needs prefixing.
func WithCollectionPaginationTriplePrefix[K1, K2, K3 any](prefix K1) func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
return func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
prefix := collections.TriplePrefix[K1, K2, K3](prefix)
o.Prefix = &prefix
}
}

// WithCollectionPaginationTriplePrefix2 is similar to WithCollectionPaginationTriplePrefix, but it takes two prefixes.
func WithCollectionPaginationTriplePrefix2[K1, K2, K3 any](prefix K1, prefix2 K2) func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
return func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
prefix := collections.TripleSuperPrefix[K1, K2, K3](prefix, prefix2)
o.Prefix = &prefix
}
}
11 changes: 9 additions & 2 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import (
"github.com/spf13/viper"
)

// IndexerConfig defines the configuration options for the kvindexer.
type IndexerConfig struct {
Enable bool `mapstructure:"indexer.enable"`
CacheCapacity int `mapstructure:"indexer.cache-capacity"`
// Enable defines whether the kvindexer is enabled.
Enable bool `mapstructure:"indexer.enable"`
// CacheCapacity defines the size of the cache used by the kvindexer. (unit: MiB)
CacheCapacity int `mapstructure:"indexer.cache-capacity"`
// Backend defines the type of the backend store and its options.
// It should have a key-value pair named 'type', and the value should exist in store supported by cosmos-db.
// Recommend to use default value unless you know about backend db storage.
// NOTE: "goleveldb" is the only supported type in the current version.
BackendConfig *viper.Viper `mapstructure:"indexer.backend"`
}

Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/initia-labs/kvindexer

go 1.22.7

toolchain go1.23.0
go 1.23.3

require (
cosmossdk.io/collections v0.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.work
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
go 1.23
go 1.23.3

use (
.
./submodules/block
./submodules/evm-nft
./submodules/move-nft
./submodules/pair
./submodules/tx
./submodules/wasm-nft
./submodules/wasm-pair
./submodules/tx
)
1 change: 0 additions & 1 deletion indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (i Indexer) ListenCommit(ctx context.Context, res abci.ResponseCommit, chan
if err != nil {
i.logger.Error("failed to handle commit", "err", err)
}
//err = i.keeper.WriteStore()

return err
}
21 changes: 3 additions & 18 deletions submodules/evm-nft/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

kvcollection "github.com/initia-labs/kvindexer/collection"
nfttypes "github.com/initia-labs/kvindexer/nft/types"
)

Expand Down Expand Up @@ -178,7 +179,7 @@ func (sm EvmNFTSubmodule) getTokensByAccount(ctx context.Context, req *nfttypes.
identifiers = append(identifiers, collections.Join(k.K2(), k.K3()))
return v, nil
},
WithCollectionPaginationTriplePrefix[sdk.AccAddress, sdk.AccAddress, string](ownerSdkAddr),
kvcollection.WithCollectionPaginationTriplePrefix[sdk.AccAddress, sdk.AccAddress, string](ownerSdkAddr),
)
if err != nil {
return nil, handleCollectionErr(err)
Expand Down Expand Up @@ -221,7 +222,7 @@ func (sm EvmNFTSubmodule) getTokensByAccountAndCollection(ctx context.Context, r
identifiers = append(identifiers, collections.Join(k.K2(), k.K3()))
return v, nil
},
WithCollectionPaginationTriplePrefix2[sdk.AccAddress, sdk.AccAddress, string](ownerSdkAddr, colSdkAddr),
kvcollection.WithCollectionPaginationTriplePrefix2[sdk.AccAddress, sdk.AccAddress, string](ownerSdkAddr, colSdkAddr),
)
if err != nil {
return nil, handleCollectionErr(err)
Expand Down Expand Up @@ -273,19 +274,3 @@ func (sm EvmNFTSubmodule) getTokensByAccountCollectionAndTokenId(ctx context.Con
Tokens: []*nfttypes.IndexedToken{&token},
}, nil
}

// WithCollectionPaginationTriplePrefix applies a prefix to a collection, whose key is a collection.Triple,
// being paginated that needs prefixing.
func WithCollectionPaginationTriplePrefix[K1, K2, K3 any](prefix K1) func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
return func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
prefix := collections.TriplePrefix[K1, K2, K3](prefix)
o.Prefix = &prefix
}
}

func WithCollectionPaginationTriplePrefix2[K1, K2, K3 any](prefix K1, prefix2 K2) func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
return func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
prefix := collections.TripleSuperPrefix[K1, K2, K3](prefix, prefix2)
o.Prefix = &prefix
}
}
3 changes: 1 addition & 2 deletions submodules/move-nft/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (sm MoveNftSubmodule) handleMintEvent(ctx context.Context, event types.Even
_, err = sm.collectionMap.Get(ctx, collectionSdkAddr)
if err != nil {
if !cosmoserr.IsOf(err, collections.ErrNotFound) {
return errors.New("")
return err
}
err = sm.collectionMap.Set(ctx, collectionSdkAddr, *collection)
if err != nil {
Expand Down Expand Up @@ -221,7 +221,6 @@ func (sm MoveNftSubmodule) handleMutateEvent(ctx context.Context, event types.Ev

// remove the nft from the sender's collection
tpk, err := sm.tokenMap.Indexes.TokenAddress.MatchExact(ctx, objectSdkAddr)
//objectKey, err := nftByOwner.TokenAddress.MatchExact(ctx, objectSdkAddr)
if err != nil {
return errors.New("object key not found")
}
Expand Down
19 changes: 3 additions & 16 deletions submodules/move-nft/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

kvcollection "github.com/initia-labs/kvindexer/collection"
nfttypes "github.com/initia-labs/kvindexer/nft/types"
)

Expand Down Expand Up @@ -183,7 +184,7 @@ func (sm MoveNftSubmodule) getTokensByAccount(ctx context.Context, req *nfttypes
identifiers = append(identifiers, collections.Join(k.K2(), k.K3()))
return v, nil
},
WithCollectionPaginationTriplePrefix[sdk.AccAddress, sdk.AccAddress, string](ownerSdkAddr),
kvcollection.WithCollectionPaginationTriplePrefix[sdk.AccAddress, sdk.AccAddress, string](ownerSdkAddr),
)
if err != nil {
return nil, handleCollectionErr(err)
Expand Down Expand Up @@ -228,7 +229,7 @@ func (sm MoveNftSubmodule) getTokensByAccountAndCollection(ctx context.Context,
identifiers = append(identifiers, collections.Join(k.K2(), k.K3()))
return v, nil
},
WithCollectionPaginationTriplePrefix2[sdk.AccAddress, sdk.AccAddress, string](ownerSdkAddr, colSdkAddr),
kvcollection.WithCollectionPaginationTriplePrefix2[sdk.AccAddress, sdk.AccAddress, string](ownerSdkAddr, colSdkAddr),
)
if err != nil {
return nil, handleCollectionErr(err)
Expand Down Expand Up @@ -281,17 +282,3 @@ func (sm MoveNftSubmodule) getTokensByAccountCollectionAndTokenId(ctx context.Co
Tokens: []*nfttypes.IndexedToken{&token},
}, nil
}

func WithCollectionPaginationTriplePrefix[K1, K2, K3 any](prefix K1) func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
return func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
prefix := collections.TriplePrefix[K1, K2, K3](prefix)
o.Prefix = &prefix
}
}

func WithCollectionPaginationTriplePrefix2[K1, K2, K3 any](prefix K1, prefix2 K2) func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
return func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
prefix := collections.TripleSuperPrefix[K1, K2, K3](prefix, prefix2)
o.Prefix = &prefix
}
}
1 change: 0 additions & 1 deletion submodules/move-nft/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type TokenIndex struct {
func (i TokenIndex) IndexesList() []collections.Index[collections.Pair[sdk.AccAddress, string], nfttypes.IndexedToken] {
return []collections.Index[collections.Pair[sdk.AccAddress, string], nfttypes.IndexedToken]{
i.TokenAddress,
//i.OwnerAddress,
}
}

Expand Down
17 changes: 4 additions & 13 deletions submodules/pair/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ func (sm PairSubmodule) pickAttribute(attrs []abci.EventAttribute, key string) s
return ""
}

func (sm PairSubmodule) generateCw721FromIcs721PortInfo(port, channel string) string {
return port + "/" + channel
}

func (sm PairSubmodule) pricessIbcNftPairEvent(ctx context.Context, packetDataStr, classId string) (err error) {
packetData := types.PacketData{}

Expand All @@ -129,15 +125,6 @@ func (sm PairSubmodule) pricessIbcNftPairEvent(ctx context.Context, packetDataSt
return cosmoserr.Wrap(err, "failed to unmarshal class data")
}

// block this part overwrite to recent
// _, err = sm.GetPair(ctx, false, packetData.ClassId)
// if err == nil {
// return nil // already exists
// }
// if !cosmoserr.IsOf(err, collections.ErrNotFound) {
// return cosmoserr.Wrap(err, "failed to check class existence")
// }

err = sm.SetPair(ctx, false, false, classId, classData.Name)
if err != nil {
return cosmoserr.Wrap(err, "failed to set class")
Expand Down Expand Up @@ -178,3 +165,7 @@ func getChainIdFromClientState(csi exportedibc.ClientState) string {
}
return cs.ChainId
}

func (sm PairSubmodule) generateCw721FromIcs721PortInfo(port, channel string) string {
return port + "/" + channel
}
21 changes: 3 additions & 18 deletions submodules/wasm-nft/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

kvcollection "github.com/initia-labs/kvindexer/collection"
nfttypes "github.com/initia-labs/kvindexer/nft/types"
)

Expand Down Expand Up @@ -182,7 +183,7 @@ func (sm WasmNFTSubmodule) getTokensByAccount(ctx context.Context, req *nfttypes
identifiers = append(identifiers, collections.Join(k.K2(), k.K3()))
return v, nil
},
WithCollectionPaginationTriplePrefix[sdk.AccAddress, sdk.AccAddress, string](ownerSdkAddr),
kvcollection.WithCollectionPaginationTriplePrefix[sdk.AccAddress, sdk.AccAddress, string](ownerSdkAddr),
)
if err != nil {
return nil, handleCollectionErr(err)
Expand Down Expand Up @@ -227,7 +228,7 @@ func (sm WasmNFTSubmodule) getTokensByAccountAndCollection(ctx context.Context,
identifiers = append(identifiers, collections.Join(k.K2(), k.K3()))
return v, nil
},
WithCollectionPaginationTriplePrefix2[sdk.AccAddress, sdk.AccAddress, string](ownerSdkAddr, colSdkAddr),
kvcollection.WithCollectionPaginationTriplePrefix2[sdk.AccAddress, sdk.AccAddress, string](ownerSdkAddr, colSdkAddr),
)
if err != nil {
return nil, handleCollectionErr(err)
Expand Down Expand Up @@ -280,19 +281,3 @@ func (sm WasmNFTSubmodule) getTokensByAccountCollectionAndTokenId(ctx context.Co
Tokens: []*nfttypes.IndexedToken{&token},
}, nil
}

// WithCollectionPaginationTriplePrefix applies a prefix to a collection, whose key is a collection.Triple,
// being paginated that needs prefixing.
func WithCollectionPaginationTriplePrefix[K1, K2, K3 any](prefix K1) func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
return func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
prefix := collections.TriplePrefix[K1, K2, K3](prefix)
o.Prefix = &prefix
}
}

func WithCollectionPaginationTriplePrefix2[K1, K2, K3 any](prefix K1, prefix2 K2) func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
return func(o *query.CollectionsPaginateOptions[collections.Triple[K1, K2, K3]]) {
prefix := collections.TripleSuperPrefix[K1, K2, K3](prefix, prefix2)
o.Prefix = &prefix
}
}
4 changes: 1 addition & 3 deletions submodules/wasm-nft/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ type EventWithAttributeMap struct {
type CollectionResource struct {
Type string `json:"type,omitempty"`
Collection nfttypes.Collection `json:"data"`
// from here is additional fields, not original collection data
//ObjectAddr string `json:"object_addr,omitempty"`
}

// internal use only: struct from move resource
Expand Down Expand Up @@ -51,5 +49,5 @@ type OwnerOf struct {

type Approval struct {
Spender string `json:"spender"`
Expiration uint64 `json:"expiration"` // FIXME: height? timestamp?
Expiration uint64 `json:"expiration"`
}
8 changes: 0 additions & 8 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package indexer

import (
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/initia-labs/kvindexer/config"
"github.com/initia-labs/kvindexer/x/kvindexer/keeper"
)
Expand All @@ -13,9 +11,3 @@ type Indexer struct {
keeper *keeper.Keeper
logger log.Logger
}

type IndexableApplication interface {
GetIndexerKeeper() *keeper.Keeper
GetBaseApp() *baseapp.BaseApp
GetKeys() map[string]*storetypes.KVStoreKey
}
1 change: 1 addition & 0 deletions x/kvindexer/keeper/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (k *Keeper) RegisterSubmodules(submodules ...types.Submodule) error {
return nil
}

// HandleFinalizeBlock processes the FinalizeBlock event for all submodules.
func (k *Keeper) HandleFinalizeBlock(ctx context.Context, req abci.RequestFinalizeBlock, res abci.ResponseFinalizeBlock) (err error) {
defer func() {
if err := recover(); err != nil {
Expand Down
1 change: 0 additions & 1 deletion x/kvindexer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var (

// AppModuleBasic defines the basic application module used by the move module.
type AppModuleBasic struct {
//cdc codec.Codec
keeper *keeper.Keeper
}

Expand Down

0 comments on commit d436c08

Please sign in to comment.