Skip to content

Commit

Permalink
fix indexer about nft burn / fix querier
Browse files Browse the repository at this point in the history
  • Loading branch information
Vritra4 committed Jun 13, 2024
1 parent d640e64 commit 2374c02
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 14 deletions.
5 changes: 5 additions & 0 deletions submodules/move-nft/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ func (sm MoveNftSubmodule) handleBurnEvent(ctx context.Context, event types.Even
ownerAddr, _ := getVMAddress(cdc, token.OwnerAddr)
ownerSdkAddr := getCosmosAddress(ownerAddr)

err = sm.tokenOwnerMap.Remove(ctx, collections.Join3(ownerSdkAddr, tpk.K1(), tpk.K2()))
if err != nil {
sm.Logger(ctx).Error("failed to remove from tokenOwnerMap", "error", err)
}

err = sm.applyCollectionOwnerMap(ctx, collectionSdkAddr, ownerSdkAddr, false)
if err != nil {
return err // just return err, no wrap
Expand Down
9 changes: 6 additions & 3 deletions submodules/move-nft/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func (q Querier) CollectionsByAccount(ctx context.Context, req *nfttypes.QueryCo
for _, collectionSdkAddr := range collectionSdkAddrs {
collection, err := q.collectionMap.Get(ctx, collectionSdkAddr)
if err != nil {
return nil, handleCollectionErr(err)
q.Logger(ctx).Warn("index mismatch found", "collection", collectionSdkAddr, "action", "CollectionsByAccount")
continue
}
collection.Collection.Name, _ = q.getCollectionNameFromPairSubmodule(ctx, collection.Collection.Name)
collections = append(collections, &collection)
Expand Down Expand Up @@ -201,7 +202,8 @@ func (sm MoveNftSubmodule) getTokensByAccount(ctx context.Context, req *nfttypes
for _, identifier := range identifiers {
token, err := sm.tokenMap.Get(ctx, identifier)
if err != nil {
return nil, handleCollectionErr(err)
sm.Logger(ctx).Warn("index mismatch found", "account", ownerSdkAddr, "action", "CollectionsByAccount")
continue
}
token.CollectionName, _ = sm.getCollectionNameFromPairSubmodule(ctx, token.CollectionName)
res = append(res, &token)
Expand Down Expand Up @@ -241,7 +243,8 @@ func (sm MoveNftSubmodule) getTokensByAccountAndCollection(ctx context.Context,
for _, identifier := range identifiers {
token, err := sm.tokenMap.Get(ctx, identifier)
if err != nil {
return nil, handleCollectionErr(err)
sm.Logger(ctx).Warn("index mismatch found", "account", ownerSdkAddr, "collection", colSdkAddr, "action", "GetTokensByAccountAndCollection")
continue
}
token.CollectionName, _ = sm.getCollectionNameFromPairSubmodule(ctx, token.CollectionName)
res = append(res, &token)
Expand Down
10 changes: 7 additions & 3 deletions submodules/move-nft/submodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ type MoveNftSubmodule struct {
vmKeeper types.MoveKeeper
pairSubmodule types.PairSubmodule

collectionMap *collections.Map[sdk.AccAddress, nfttypes.IndexedCollection]
// collectionMap: key(collection address`), value(collection)
collectionMap *collections.Map[sdk.AccAddress, nfttypes.IndexedCollection]
// collectionOwnerMap: key(owner address, collection address), value(collection`s object address)
collectionOwnerMap *collections.Map[collections.Pair[sdk.AccAddress, sdk.AccAddress], uint64]
tokenMap *collections.IndexedMap[collections.Pair[sdk.AccAddress, string], nfttypes.IndexedToken, TokenIndex]
tokenOwnerMap *collections.Map[collections.Triple[sdk.AccAddress, sdk.AccAddress, string], bool]
// tokenMap: key(owner address, token id), value(token)
tokenMap *collections.IndexedMap[collections.Pair[sdk.AccAddress, string], nfttypes.IndexedToken, TokenIndex]
// tokenOwnerMap: key(owner address, collection address, token id), value(bool as placeholder)
tokenOwnerMap *collections.Map[collections.Triple[sdk.AccAddress, sdk.AccAddress, string], bool]
}

func NewMoveNftSubmodule(
Expand Down
2 changes: 1 addition & 1 deletion submodules/move-nft/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const (
SubmoduleName = "move-nft"

// Version is the current version of the submodule
Version = "v0.1.2"
Version = "v0.1.3"
)

// store prefixes
Expand Down
2 changes: 1 addition & 1 deletion submodules/wasm-nft/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (sm WasmNFTSubmodule) handleBurnEvent(ctx context.Context, event types.Even
ownerAddr, _ := getVMAddress(sm.ac, token.OwnerAddr)
ownerSdkAddr := getCosmosAddress(ownerAddr)

err = sm.tokenOwnerMap.Set(ctx, collections.Join3(ownerSdkAddr, tpk.K1(), tpk.K2()), true)
err = sm.tokenOwnerMap.Remove(ctx, collections.Join3(ownerSdkAddr, tpk.K1(), tpk.K2()))
if err != nil {
sm.Logger(ctx).Error("failed to remove from tokenOwnerSet", "owner", ownerSdkAddr, "collection-addr", tpk.K1(), "token-id", tpk.K2(), "error", err)
return cosmoserr.Wrap(err, "failed to insert token into tokenOwnerSet")
Expand Down
6 changes: 4 additions & 2 deletions submodules/wasm-nft/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func (q Querier) CollectionsByAccount(ctx context.Context, req *nfttypes.QueryCo
for _, collectionSdkAddr := range collectionSdkAddrs {
collection, err := q.collectionMap.Get(ctx, collectionSdkAddr)
if err != nil {
return nil, handleCollectionErr(err)
q.Logger(ctx).Warn("index mismatch found", "collection", collectionSdkAddr, "action", "CollectionsByAccount")
continue
}
collection.Collection.Name, _ = q.getCollectionNameFromPairSubmodule(ctx, collection.Collection.Name)
collections = append(collections, &collection)
Expand Down Expand Up @@ -203,7 +204,8 @@ func (sm WasmNFTSubmodule) getTokensByAccount(ctx context.Context, req *nfttypes
for _, identifier := range identifiers {
token, err := sm.tokenMap.Get(ctx, identifier)
if err != nil {
return nil, handleCollectionErr(err)
sm.Logger(ctx).Warn("index mismatch found", "account", ownerSdkAddr, "action", "CollectionsByAccount")
continue
}
token.CollectionName, _ = sm.getCollectionNameFromPairSubmodule(ctx, token.CollectionName)
res = append(res, &token)
Expand Down
10 changes: 7 additions & 3 deletions submodules/wasm-nft/submodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ type WasmNFTSubmodule struct {
vmKeeper types.WasmKeeper
pairSubmodule types.PairSubmodule

collectionMap *collections.Map[sdk.AccAddress, nfttypes.IndexedCollection]
// collectionMap: key(collection address`), value(collection)
collectionMap *collections.Map[sdk.AccAddress, nfttypes.IndexedCollection]
// collectionOwnerMap: key(owner address, collection address), value(collection`s object address)
collectionOwnerMap *collections.Map[collections.Pair[sdk.AccAddress, sdk.AccAddress], uint64]
tokenMap *collections.Map[collections.Pair[sdk.AccAddress, string], nfttypes.IndexedToken]
tokenOwnerMap *collections.Map[collections.Triple[sdk.AccAddress, sdk.AccAddress, string], bool]
// tokenMap: key(owner address, token id), value(token)
tokenMap *collections.Map[collections.Pair[sdk.AccAddress, string], nfttypes.IndexedToken]
// tokenOwnerMap: key(owner address, collection address, token id), value(bool as placeholder)
tokenOwnerMap *collections.Map[collections.Triple[sdk.AccAddress, sdk.AccAddress, string], bool]
}

func NewWasmNFTSubmodule(
Expand Down
2 changes: 1 addition & 1 deletion submodules/wasm-nft/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const (
SubmoduleName = "wasm-nft"

// Version is the current version of the submodule
Version = "v0.1.2"
Version = "v0.1.3"
)

// store prefixes
Expand Down

0 comments on commit 2374c02

Please sign in to comment.