Skip to content

Commit

Permalink
Merge pull request #45 from initia-labs/fix/nfts
Browse files Browse the repository at this point in the history
fix pageRes.total if not found cases exist
  • Loading branch information
Vritra4 authored Jun 14, 2024
2 parents 6236f4a + 0a0a4eb commit c18ac17
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
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

0 comments on commit c18ac17

Please sign in to comment.