Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pageRes.total if not found cases exist #45

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions submodules/move-nft/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,22 @@ func (q Querier) CollectionsByAccount(ctx context.Context, req *nfttypes.QueryCo
return nil, handleCollectionErr(err)
}

collections := []*nfttypes.IndexedCollection{}
indexedCollections := []*nfttypes.IndexedCollection{}
for _, collectionSdkAddr := range collectionSdkAddrs {
collection, err := q.collectionMap.Get(ctx, collectionSdkAddr)
if err != nil {
q.Logger(ctx).Warn("index mismatch found", "collection", collectionSdkAddr, "action", "CollectionsByAccount")
q.Logger(ctx).Warn("index mismatch found", "collection", collectionSdkAddr, "action", "CollectionsByAccount", "error", err)
if cosmoserr.IsOf(err, collections.ErrNotFound) {
pageRes.Total--
}
continue
}
collection.Collection.Name, _ = q.getCollectionNameFromPairSubmodule(ctx, collection.Collection.Name)
collections = append(collections, &collection)
indexedCollections = append(indexedCollections, &collection)
}

return &nfttypes.QueryCollectionsResponse{
Collections: collections,
Collections: indexedCollections,
Pagination: pageRes,
}, nil
}
Expand Down Expand Up @@ -202,7 +205,10 @@ func (sm MoveNftSubmodule) getTokensByAccount(ctx context.Context, req *nfttypes
for _, identifier := range identifiers {
token, err := sm.tokenMap.Get(ctx, identifier)
if err != nil {
sm.Logger(ctx).Warn("index mismatch found", "account", ownerSdkAddr, "action", "CollectionsByAccount")
sm.Logger(ctx).Warn("index mismatch found", "account", ownerSdkAddr, "action", "CollectionsByAccount", "error", err)
if cosmoserr.IsOf(err, collections.ErrNotFound) {
pageRes.Total--
}
continue
}
token.CollectionName, _ = sm.getCollectionNameFromPairSubmodule(ctx, token.CollectionName)
Expand Down Expand Up @@ -243,7 +249,10 @@ func (sm MoveNftSubmodule) getTokensByAccountAndCollection(ctx context.Context,
for _, identifier := range identifiers {
token, err := sm.tokenMap.Get(ctx, identifier)
if err != nil {
sm.Logger(ctx).Warn("index mismatch found", "account", ownerSdkAddr, "collection", colSdkAddr, "action", "GetTokensByAccountAndCollection")
sm.Logger(ctx).Warn("index mismatch found", "account", ownerSdkAddr, "collection", colSdkAddr, "action", "GetTokensByAccountAndCollection", "error", err)
if cosmoserr.IsOf(err, collections.ErrNotFound) {
pageRes.Total--
}
continue
}
token.CollectionName, _ = sm.getCollectionNameFromPairSubmodule(ctx, token.CollectionName)
Expand Down
21 changes: 15 additions & 6 deletions submodules/wasm-nft/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,22 @@ func (q Querier) CollectionsByAccount(ctx context.Context, req *nfttypes.QueryCo
return nil, handleCollectionErr(err)
}

collections := []*nfttypes.IndexedCollection{}
indexedCollections := []*nfttypes.IndexedCollection{}
for _, collectionSdkAddr := range collectionSdkAddrs {
collection, err := q.collectionMap.Get(ctx, collectionSdkAddr)
if err != nil {
q.Logger(ctx).Warn("index mismatch found", "collection", collectionSdkAddr, "action", "CollectionsByAccount")
q.Logger(ctx).Warn("index mismatch found", "collection", collectionSdkAddr, "action", "CollectionsByAccount", "error", err)
if cosmoserr.IsOf(err, collections.ErrNotFound) {
pageRes.Total--
}
continue
}
collection.Collection.Name, _ = q.getCollectionNameFromPairSubmodule(ctx, collection.Collection.Name)
collections = append(collections, &collection)
indexedCollections = append(indexedCollections, &collection)
}

return &nfttypes.QueryCollectionsResponse{
Collections: collections,
Collections: indexedCollections,
Pagination: pageRes,
}, nil
}
Expand Down Expand Up @@ -204,7 +207,10 @@ func (sm WasmNFTSubmodule) getTokensByAccount(ctx context.Context, req *nfttypes
for _, identifier := range identifiers {
token, err := sm.tokenMap.Get(ctx, identifier)
if err != nil {
sm.Logger(ctx).Warn("index mismatch found", "account", ownerSdkAddr, "action", "CollectionsByAccount")
sm.Logger(ctx).Warn("index mismatch found", "account", ownerSdkAddr, "action", "CollectionsByAccount", "error", err)
if cosmoserr.IsOf(err, collections.ErrNotFound) {
pageRes.Total--
}
continue
}
token.CollectionName, _ = sm.getCollectionNameFromPairSubmodule(ctx, token.CollectionName)
Expand Down Expand Up @@ -245,7 +251,10 @@ func (sm WasmNFTSubmodule) getTokensByAccountAndCollection(ctx context.Context,
for _, identifier := range identifiers {
token, err := sm.tokenMap.Get(ctx, identifier)
if err != nil {
sm.Logger(ctx).Warn("index mismatch found", "account", ownerSdkAddr, "collection", colSdkAddr, "action", "GetTokensByAccountAndCollection")
sm.Logger(ctx).Warn("index mismatch found", "account", ownerSdkAddr, "collection", colSdkAddr, "action", "GetTokensByAccountAndCollection", "error", err)
if cosmoserr.IsOf(err, collections.ErrNotFound) {
pageRes.Total--
}
continue
}
token.CollectionName, _ = sm.getCollectionNameFromPairSubmodule(ctx, token.CollectionName)
Expand Down
Loading