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 indexing err on wasm-nft minting / pair collecting #40

Merged
merged 7 commits into from
Apr 30, 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
4 changes: 3 additions & 1 deletion go.work
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use (
.
./submodules/block
./submodules/move-nft
./submodules/pair
./submodules/move-pair
./submodules/wasm-nft
./submodules/wasm-pair
./submodules/tx
)
18 changes: 12 additions & 6 deletions nft/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 24 additions & 25 deletions submodules/pair/types/query.pb.go → pair/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
12 changes: 6 additions & 6 deletions submodules/pair/types/types.pb.go → pair/types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/indexer/pair/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "google/api/annotations.proto";
import "cosmos_proto/cosmos.proto";
import "indexer/pair/v1/types.proto";

option go_package = "github.com/initia-labs/kvindexer/submodules/pair/types";
option go_package = "github.com/initia-labs/kvindexer/pair/types";

// Query provides the service definition for the Token Pairs
service Query {
Expand Down
2 changes: 1 addition & 1 deletion proto/indexer/pair/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package indexer.pair.v1;
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/initia-labs/kvindexer/submodules/pair/types";
option go_package = "github.com/initia-labs/kvindexer/pair/types";
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.equal_all) = true;

Expand Down
3 changes: 2 additions & 1 deletion submodules/block/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion submodules/block/types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 37 additions & 71 deletions submodules/pair/collect.go → submodules/move-pair/collect.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package pair
package move_pair

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"

"cosmossdk.io/collections"
cosmoserr "cosmossdk.io/errors"
Expand All @@ -18,11 +17,12 @@ import (
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
"github.com/initia-labs/kvindexer/submodules/pair/types"
"github.com/initia-labs/kvindexer/submodules/move-pair/types"
)

const (
ibcTransferPort = "transfer"
ibcTransferPort = "transfer"
ibcNftTransferPort = "nft-transfer"
)

func (sm PairSubmodule) finalizeBlock(ctx context.Context, req abci.RequestFinalizeBlock, res abci.ResponseFinalizeBlock) error {
Expand Down Expand Up @@ -77,27 +77,19 @@ func (sm PairSubmodule) collectOPfungibleTokens(ctx context.Context, msg *opchil

func (sm PairSubmodule) collectIBCNonfungibleTokens(ctx context.Context, txResult *abci.ExecTxResult) (err error) {
var packetData, classId string

for _, event := range txResult.Events {
switch event.Type {
case "recv_packet":
if event.Type == "recv_packet" {
if sm.pickAttribute(event.Attributes, "packet_src_port") != ibcNftTransferPort {
continue
}
packetData = sm.pickAttribute(event.Attributes, "packet_data")
case "class_trace":
} else if event.Type == "class_trace" {
classId = sm.pickAttribute(event.Attributes, "class_id")
if err != nil {
sm.Logger(ctx).Warn("failed to handle class_trace event", "error", err, "event", event)
}
}
if packetData != "" && classId != "" {
break
}
}
if packetData == "" || classId == "" {
return nil
}
err = sm.pricessPairEvent(ctx, packetData, classId)
err = sm.pricessIbcNftPairEvent(ctx, packetData, classId)
if err != nil {
sm.Logger(ctx).Warn("failed to handle recv_packet event", "error", err, "recv_packet.packet_data", packetData, "class_trace.class_id", classId)
sm.Logger(ctx).Warn("failed to handle recv_packet event", "error", err, "recv_packet.packet_data", packetData)
}

return nil
Expand All @@ -112,10 +104,17 @@ func (sm PairSubmodule) pickAttribute(attrs []abci.EventAttribute, key string) s
return ""
}

func (sm PairSubmodule) pricessPairEvent(ctx context.Context, packetDataStr, classId string) (err error) {
sm.Logger(ctx).Debug("processPairEvent", "packet_data", packetDataStr, "class_id", classId)
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{}

if packetDataStr == "" || classId == "" {
return nil
}

if err = json.Unmarshal([]byte(packetDataStr), &packetData); err != nil {
// may be not target
return nil
Expand All @@ -130,73 +129,40 @@ func (sm PairSubmodule) pricessPairEvent(ctx context.Context, packetDataStr, cla
return cosmoserr.Wrap(err, "failed to unmarshal class data")
}

_, err = sm.GetPair(ctx, false, classId)
if err == nil {
return nil // already exists
}
if !cosmoserr.IsOf(err, collections.ErrNotFound) {
return cosmoserr.Wrap(err, "failed to check class existence")
}
// 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")
}

sm.Logger(ctx).Info("nft class added", "classId", classId, "classData", classData)
sm.Logger(ctx).Info("nft class added", "pakcetData", packetData, "classData", classData)
return nil
}

func (sm PairSubmodule) collectIBCFungibleTokens(ctx context.Context) error {

sdkCtx := sdk.UnwrapSDKContext(ctx)
chKeeper := sm.channelKeeper

// get all channels
channels := chKeeper.GetAllChannels(sdkCtx)

ibcChannels := []string{}
for _, channel := range channels {
if channel.PortId != ibcTransferPort {
traces := sm.transferKeeper.GetAllDenomTraces(sdkCtx)
for _, trace := range traces {
_, err := sm.fungiblePairsMap.Get(ctx, trace.IBCDenom())
if err != nil && !cosmoserr.IsOf(err, collections.ErrNotFound) {
continue
}

_ /*clientId*/, cs, err := chKeeper.GetChannelClientState(sdkCtx, channel.PortId, channel.ChannelId)
err = sm.fungiblePairsMap.Set(ctx, trace.IBCDenom(), trace.BaseDenom)
if err != nil {
sm.Logger(ctx).Warn("GetChannelClientState", "error", err)
}
counterpartyChainId := getChainIdFromClientState(cs)
if counterpartyChainId == "" {
sm.Logger(ctx).Warn("channel id is nil")
continue
}
if counterpartyChainId != sdk.UnwrapSDKContext(ctx).ChainID() {
continue
}
ibcChannels = append(ibcChannels, channel.ChannelId)
}

traces := sm.transferKeeper.GetAllDenomTraces(sdkCtx)
for _, ibcChannel := range ibcChannels {
for _, trace := range traces {
if trace.Path != fmt.Sprintf("%s/%s", ibcTransferPort, ibcChannel) {
continue
}

prevDenom, err := sm.fungiblePairsMap.Get(ctx, trace.IBCDenom())
if err != nil && !cosmoserr.IsOf(err, collections.ErrNotFound) {
continue
}
// prevDenom should be empty string if not found, or already set
if prevDenom == trace.BaseDenom {
continue
}

err = sm.fungiblePairsMap.Set(ctx, trace.IBCDenom(), trace.BaseDenom)
if err != nil {
return err
}
sm.Logger(ctx).Warn("failed to set fungible pair", "ibcDenom", trace.IBCDenom(), "baseDenom", trace.BaseDenom, "error", err)
return err
}
sm.Logger(ctx).Info("fungible pair added", "ibcDenom", trace.IBCDenom(), "baseDenom", trace.BaseDenom)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion submodules/pair/go.mod → submodules/move-pair/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/initia-labs/kvindexer/submodules/pair
module github.com/initia-labs/kvindexer/submodules/move-pair

go 1.22

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package pair
package move_pair

import (
"context"

"cosmossdk.io/collections"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/initia-labs/kvindexer/submodules/pair/types"
"github.com/initia-labs/kvindexer/pair/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pair
package move_pair

import (
"context"
Expand Down
Loading
Loading