Skip to content

Commit

Permalink
wip: no evm-nft yet
Browse files Browse the repository at this point in the history
  • Loading branch information
Vritra4 committed May 2, 2024
1 parent e4cdc29 commit 3aa7a8a
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 10 deletions.
117 changes: 109 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"net/http"
"os"
"path/filepath"
"reflect"

"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"cosmossdk.io/core/address"
"cosmossdk.io/log"
"cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -151,6 +151,15 @@ import (
forwardingkeeper "github.com/noble-assets/forwarding/x/forwarding/keeper"
forwardingtypes "github.com/noble-assets/forwarding/x/forwarding/types"

// kvindexer
indexer "github.com/initia-labs/kvindexer"
indexerconfig "github.com/initia-labs/kvindexer/config"
blocksubmodule "github.com/initia-labs/kvindexer/submodules/block"
"github.com/initia-labs/kvindexer/submodules/pair"
tx "github.com/initia-labs/kvindexer/submodules/tx"
indexermodule "github.com/initia-labs/kvindexer/x/kvindexer"
indexerkeeper "github.com/initia-labs/kvindexer/x/kvindexer/keeper"

// unnamed import of statik for swagger UI support
_ "github.com/initia-labs/minievm/client/docs/statik"
)
Expand Down Expand Up @@ -248,6 +257,10 @@ type MinitiaApp struct {

// Override of BaseApp's CheckTx
checkTxHandler blockchecktx.CheckTx

// fake keeper to indexer
indexerKeeper *indexerkeeper.Keeper
indexerModule indexermodule.AppModuleBasic
}

// NewMinitiaApp returns a reference to an initialized Initia.
Expand Down Expand Up @@ -720,6 +733,10 @@ func NewMinitiaApp(
oracle.NewAppModule(appCodec, *app.OracleKeeper),
)

if err := app.setupIndexer(appOpts, homePath, ac, vc, appCodec); err != nil {
panic(err)
}

// BasicModuleManager defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration and genesis verification.
// By default it is composed of all the module from the module manager.
Expand Down Expand Up @@ -784,6 +801,7 @@ func NewMinitiaApp(
if err != nil {
panic(err)
}
app.indexerModule.RegisterServices(app.configurator)

// register upgrade handler for later use
app.RegisterUpgradeHandlers(app.configurator)
Expand Down Expand Up @@ -1086,6 +1104,9 @@ func (app *MinitiaApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.AP
// Register grpc-gateway routes for all modules.
app.BasicModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register grpc-gateway routes for indexer module.
app.indexerModule.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register swagger API from root so that other applications can override easily
if apiConfig.Swagger {
RegisterSwaggerAPI(apiSvr.Router)
Expand Down Expand Up @@ -1184,13 +1205,6 @@ func (app *MinitiaApp) TxConfig() client.TxConfig {
return app.txConfig
}

// ChainID gets chainID from private fields of BaseApp
// Should be removed once SDK 0.50.x will be adopted
func (app *MinitiaApp) ChainID() string { // TODO: remove this method once chain updates to v0.50.x
field := reflect.ValueOf(app.BaseApp).Elem().FieldByName("chainID")
return field.String()
}

// allow 20 and 32 bytes address
func VerifyAddressLen() func(addr []byte) error {
return func(addr []byte) error {
Expand All @@ -1201,3 +1215,90 @@ func VerifyAddressLen() func(addr []byte) error {
return nil
}
}

func (app *MinitiaApp) setupIndexer(appOpts servertypes.AppOptions, homePath string, ac, vc address.Codec, appCodec codec.Codec) error {
// initialize the indexer fake-keeper
indexerConfig, err := indexerconfig.NewConfig(appOpts)
if err != nil {
panic(err)
}
app.indexerKeeper = indexerkeeper.NewKeeper(
appCodec,
"evm",
homePath,
indexerConfig,
ac,
vc,
)

smBlock, err := blocksubmodule.NewBlockSubmodule(appCodec, app.indexerKeeper, app.OPChildKeeper)
if err != nil {
panic(err)
}
smTx, err := tx.NewTxSubmodule(appCodec, app.indexerKeeper)
if err != nil {
panic(err)
}
smPair, err := pair.NewPairSubmodule(appCodec, app.indexerKeeper, app.IBCKeeper.ChannelKeeper, app.TransferKeeper)
if err != nil {
panic(err)
}
/*
smNft, err := nft.NewMoveNftSubmodule(ac, appCodec, app.indexerKeeper, app.EvmKeeper, smPair)
if err != nil {
panic(err)
}
err = app.indexerKeeper.RegisterSubmodules(smBlock, smTx, smPair, smNft)
*/
err = app.indexerKeeper.RegisterSubmodules(smBlock, smTx, smPair)
if err != nil {
panic(err)
}
app.indexerModule = indexermodule.NewAppModuleBasic(app.indexerKeeper)
// Add your implementation here

indexer, err := indexer.NewIndexer(app.GetBaseApp().Logger(), app.indexerKeeper)
if err != nil || indexer == nil {
return nil
}

if err = indexer.Validate(); err != nil {
return err
}

if err = indexer.Prepare(nil); err != nil {
return err
}

if err = app.indexerKeeper.Seal(); err != nil {
return err
}

if err = indexer.Start(nil); err != nil {
return err
}

streamingManager := storetypes.StreamingManager{
ABCIListeners: []storetypes.ABCIListener{indexer},
StopNodeOnErr: true,
}
app.SetStreamingManager(streamingManager)

return nil
}

// Close closes the underlying baseapp, the oracle service, and the prometheus server if required.
// This method blocks on the closure of both the prometheus server, and the oracle-service
func (app *MinitiaApp) Close() error {
if app.indexerKeeper != nil {
if err := app.indexerKeeper.Close(); err != nil {
return err
}
}

if err := app.BaseApp.Close(); err != nil {
return err
}

return nil
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ require (
github.com/holiman/uint256 v1.2.4
github.com/initia-labs/OPinit v0.2.6
github.com/initia-labs/initia v0.2.7
github.com/initia-labs/kvindexer v0.1.3
github.com/initia-labs/kvindexer/submodules/block v0.1.0
github.com/initia-labs/kvindexer/submodules/pair v0.1.1
github.com/initia-labs/kvindexer/submodules/tx v0.1.0
github.com/noble-assets/forwarding v0.0.0-20240416085758-ed8e9efaf69a
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
Expand Down
14 changes: 12 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,12 @@ github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg
github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/gobwas/ws v1.1.0 h1:7RFti/xnNkMJnrK7D1yQ/iCIB5OrrY/54/H930kIbHA=
github.com/gobwas/ws v1.1.0/go.mod h1:nzvNcVha5eUziGrbxFCo6qFIojQHjJV5cLYIbezhfL0=
Expand Down Expand Up @@ -784,6 +786,14 @@ github.com/initia-labs/ibc-go/v8 v8.0.0-20240419124350-4275a05abe2c h1:FDwh5zZbm
github.com/initia-labs/ibc-go/v8 v8.0.0-20240419124350-4275a05abe2c/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8=
github.com/initia-labs/initia v0.2.7 h1:avSfEh+nheYC7gFxnfHaXSHRBZYWHI19vn/T0luI4y8=
github.com/initia-labs/initia v0.2.7/go.mod h1:PFWX4I983j462shp3a1lLRheBiIfZrRoF/MQI/CsL9o=
github.com/initia-labs/kvindexer v0.1.3 h1:TLkgJjp5TiPnH+OzYfk7ZKQTKqGOfSte59Y3gasob+o=
github.com/initia-labs/kvindexer v0.1.3/go.mod h1:rvAmgCAmEs4KM8sRRPcyTqNNwi8s2JiHybiFkYfp4KE=
github.com/initia-labs/kvindexer/submodules/block v0.1.0 h1:y+EXnksd/I2F96mzIoQA64nZUZON2P+99YrSzeLCLoY=
github.com/initia-labs/kvindexer/submodules/block v0.1.0/go.mod h1:4c+c59wVAnjuaJv/pcDYaUkeVmOqVV+orqEjya/RIjo=
github.com/initia-labs/kvindexer/submodules/pair v0.1.1 h1:o151gA4jIbqEl+pWTOCizkiOPgkA5ANuNbHfqAQijoE=
github.com/initia-labs/kvindexer/submodules/pair v0.1.1/go.mod h1:8X1GE1ZLkH7z8TKb5MUh7UClTkcqVFIwXIIRdsqeUZY=
github.com/initia-labs/kvindexer/submodules/tx v0.1.0 h1:6kbf6wmzXPN0XCQLasiFgq1AlZHkt5K3/ZG+IWw1nNs=
github.com/initia-labs/kvindexer/submodules/tx v0.1.0/go.mod h1:i0XeLbLa6xdgTR01WF8kaAO50vMmwxbeq0fKexwpFHU=
github.com/initia-labs/movevm v0.2.7 h1:6UM35Cp6XQ1LgM7gnaSYouc7osSwxSQJsZgQdpXnBM4=
github.com/initia-labs/movevm v0.2.7/go.mod h1:6MxR4GP5zH3JUc1IMgfqAe1e483mZVS7fshPknZPJ30=
github.com/initia-labs/slinky v0.0.0-20240418051646-d45167cc66b1 h1:7mXLhI/X+GLdAYNmzXE5CIvTuOgETUMB7tR6VHvX/tY=
Expand Down
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1/go.mod h1:oJDH3BJKyqBA2TXFhDs
github.com/go-xmlfmt/xmlfmt v1.1.2/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM=
github.com/go-zookeeper/zk v1.0.2/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid/v5 v5.0.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
github.com/gogo/status v1.1.0/go.mod h1:BFv9nrluPLmrS0EmGVvLaPNmRosr9KapBYd5/hpY1WM=
Expand Down

0 comments on commit 3aa7a8a

Please sign in to comment.