From b2c9128b314cd2908e195975fe11ef9c0d9cc80e Mon Sep 17 00:00:00 2001 From: Vritra4 Date: Mon, 22 Apr 2024 17:59:42 +0900 Subject: [PATCH 1/2] fix query failure when nil is in res --- submodules/move-nft/grpc_query.go | 10 ++++++++++ submodules/wasm-nft/grpc_query.go | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/submodules/move-nft/grpc_query.go b/submodules/move-nft/grpc_query.go index 9dede6d..220cf70 100644 --- a/submodules/move-nft/grpc_query.go +++ b/submodules/move-nft/grpc_query.go @@ -12,6 +12,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/initia-labs/kvindexer/nft/types" nfttypes "github.com/initia-labs/kvindexer/nft/types" ) @@ -144,9 +145,14 @@ func (sm MoveNftSubmodule) getTokensByCollection(ctx context.Context, req *nftty return &v, nil }, ) + if err != nil { return nil, handleCollectionErr(err) } + res = slices.DeleteFunc(res, func(item *types.IndexedToken) bool { + return item == nil + }) + res = slices.Clip(res) return &nfttypes.QueryTokensResponse{ Tokens: res, @@ -238,6 +244,10 @@ func (sm MoveNftSubmodule) getTokensByAccountAndCollection(ctx context.Context, if err != nil { return nil, status.Error(codes.Internal, err.Error()) } + res = slices.DeleteFunc(res, func(item *types.IndexedToken) bool { + return item == nil + }) + res = slices.Clip(res) return &nfttypes.QueryTokensResponse{ Tokens: res, diff --git a/submodules/wasm-nft/grpc_query.go b/submodules/wasm-nft/grpc_query.go index 3a1ac42..c69cc91 100644 --- a/submodules/wasm-nft/grpc_query.go +++ b/submodules/wasm-nft/grpc_query.go @@ -12,6 +12,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/initia-labs/kvindexer/nft/types" nfttypes "github.com/initia-labs/kvindexer/nft/types" ) @@ -147,6 +148,10 @@ func (sm WasmNFTSubmodule) getTokensByCollection(ctx context.Context, req *nftty if err != nil { return nil, handleCollectionErr(err) } + res = slices.DeleteFunc(res, func(item *types.IndexedToken) bool { + return item == nil + }) + res = slices.Clip(res) return &nfttypes.QueryTokensResponse{ Tokens: res, @@ -238,6 +243,10 @@ func (sm WasmNFTSubmodule) getTokensByAccountAndCollection(ctx context.Context, if err != nil { return nil, status.Error(codes.Internal, err.Error()) } + res = slices.DeleteFunc(res, func(item *types.IndexedToken) bool { + return item == nil + }) + res = slices.Clip(res) return &nfttypes.QueryTokensResponse{ Tokens: res, From 13511d809178403538f817ca7b51d1788f1b14f9 Mon Sep 17 00:00:00 2001 From: Vritra4 Date: Mon, 22 Apr 2024 18:01:25 +0900 Subject: [PATCH 2/2] fix duplicated import --- submodules/move-nft/grpc_query.go | 5 ++--- submodules/wasm-nft/grpc_query.go | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/submodules/move-nft/grpc_query.go b/submodules/move-nft/grpc_query.go index 220cf70..410b9ec 100644 --- a/submodules/move-nft/grpc_query.go +++ b/submodules/move-nft/grpc_query.go @@ -12,7 +12,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/initia-labs/kvindexer/nft/types" nfttypes "github.com/initia-labs/kvindexer/nft/types" ) @@ -149,7 +148,7 @@ func (sm MoveNftSubmodule) getTokensByCollection(ctx context.Context, req *nftty if err != nil { return nil, handleCollectionErr(err) } - res = slices.DeleteFunc(res, func(item *types.IndexedToken) bool { + res = slices.DeleteFunc(res, func(item *nfttypes.IndexedToken) bool { return item == nil }) res = slices.Clip(res) @@ -244,7 +243,7 @@ func (sm MoveNftSubmodule) getTokensByAccountAndCollection(ctx context.Context, if err != nil { return nil, status.Error(codes.Internal, err.Error()) } - res = slices.DeleteFunc(res, func(item *types.IndexedToken) bool { + res = slices.DeleteFunc(res, func(item *nfttypes.IndexedToken) bool { return item == nil }) res = slices.Clip(res) diff --git a/submodules/wasm-nft/grpc_query.go b/submodules/wasm-nft/grpc_query.go index c69cc91..5d277b2 100644 --- a/submodules/wasm-nft/grpc_query.go +++ b/submodules/wasm-nft/grpc_query.go @@ -12,7 +12,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/initia-labs/kvindexer/nft/types" nfttypes "github.com/initia-labs/kvindexer/nft/types" ) @@ -148,7 +147,7 @@ func (sm WasmNFTSubmodule) getTokensByCollection(ctx context.Context, req *nftty if err != nil { return nil, handleCollectionErr(err) } - res = slices.DeleteFunc(res, func(item *types.IndexedToken) bool { + res = slices.DeleteFunc(res, func(item *nfttypes.IndexedToken) bool { return item == nil }) res = slices.Clip(res) @@ -243,7 +242,7 @@ func (sm WasmNFTSubmodule) getTokensByAccountAndCollection(ctx context.Context, if err != nil { return nil, status.Error(codes.Internal, err.Error()) } - res = slices.DeleteFunc(res, func(item *types.IndexedToken) bool { + res = slices.DeleteFunc(res, func(item *nfttypes.IndexedToken) bool { return item == nil }) res = slices.Clip(res)