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

feat(be): integrate block explorer Json-RPC server #41

Merged
11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ go 1.22.1
require (
cosmossdk.io/errors v1.0.0-beta.7
github.com/CosmWasm/wasmd v0.33.0
github.com/bcdevtools/block-explorer-rpc-cosmos v1.0.1
github.com/bcdevtools/wasm-block-explorer-rpc-cosmos v1.0.1
github.com/cosmos/cosmos-sdk v0.46.15
github.com/cosmos/ibc-go/v6 v6.2.1
github.com/dymensionxyz/dymension-rdk v1.2.0-beta
github.com/dymensionxyz/dymint v1.0.1-alpha
github.com/ethereum/go-ethereum v1.12.0
github.com/gorilla/mux v1.8.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.18.0
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.5.1
Expand All @@ -32,6 +36,7 @@ require (
github.com/99designs/keyring v1.2.1 // indirect
github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect
github.com/CosmWasm/wasmvm v1.3.0 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/Workiva/go-datastructures v1.0.53 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/avast/retry-go/v4 v4.5.0 // indirect
Expand Down Expand Up @@ -90,7 +95,6 @@ require (
github.com/dymensionxyz/cosmosclient v0.4.2-beta // indirect
github.com/dymensionxyz/dymension/v3 v3.0.0-rc02.0.20240304125623-d447bab68709 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/ethereum/go-ethereum v1.12.0 // indirect
github.com/evmos/evmos/v12 v12.1.6 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/filecoin-project/go-jsonrpc v0.3.1 // indirect
Expand All @@ -103,6 +107,7 @@ require (
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
Expand Down Expand Up @@ -212,7 +217,6 @@ require (
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/pierrec/xxHash v0.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
Expand All @@ -228,6 +232,7 @@ require (
github.com/rs/cors v1.9.0 // indirect
github.com/rs/zerolog v1.29.1 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
Expand All @@ -245,6 +250,8 @@ require (
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/vedhavyas/go-subkey v1.0.3 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1/go.mod h1:rLiOUrPLW/Er5kRcQ7
github.com/aws/aws-sdk-go-v2/service/sso v1.1.1/go.mod h1:SuZJxklHxLAXgLTc1iFXbEWkXs7QRTQpCLGaKIprQW0=
github.com/aws/aws-sdk-go-v2/service/sts v1.1.1/go.mod h1:Wi0EBZwiz/K44YliU0EKxqTCJGUfYTWXrrBwkq736bM=
github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/bcdevtools/block-explorer-rpc-cosmos v1.0.1 h1:/mkYfjhJSQr71mJUFbOoyRvykSUj6TgwB9m9sKtqtOI=
github.com/bcdevtools/block-explorer-rpc-cosmos v1.0.1/go.mod h1:AWXHI5ICXK4wB+A59dNddzq5Xdc1wtQDRiIXfMw8cwc=
github.com/bcdevtools/wasm-block-explorer-rpc-cosmos v1.0.1 h1:Foj4wfN7WLPxxabMrnJXKbjXcB4BpmFdeHzCzb+tGks=
github.com/bcdevtools/wasm-block-explorer-rpc-cosmos v1.0.1/go.mod h1:Lxsmp+l1ivLidAxx/6eZ/aFMeFxpmiOaMbKXPG6yCwI=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
Expand Down Expand Up @@ -631,6 +635,7 @@ github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ4
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
Expand Down Expand Up @@ -1828,6 +1833,7 @@ golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -1913,6 +1919,7 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
Expand Down
48 changes: 48 additions & 0 deletions ra_wasm_be_rpc/backend/backend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package backend

import (
"context"
"github.com/bcdevtools/block-explorer-rpc-cosmos/be_rpc/config"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"
sequencerstypes "github.com/dymensionxyz/dymension-rdk/x/sequencers/types"
rawberpctypes "github.com/dymensionxyz/rollapp-wasm/ra_wasm_be_rpc/types"
"github.com/tendermint/tendermint/libs/log"
)

type RollAppWasmBackendI interface {
// Misc

GetSequencersModuleParams() (*sequencerstypes.Params, error)
}

var _ RollAppWasmBackendI = (*RollAppWasmBackend)(nil)

// RollAppWasmBackend implements the RollAppWasmBackendI interface
type RollAppWasmBackend struct {
ctx context.Context
clientCtx client.Context
queryClient *rawberpctypes.QueryClient // gRPC query client
logger log.Logger
cfg config.BeJsonRpcConfig
}

// NewRollAppWasmBackend creates a new RollAppWasmBackend instance for RollApp EVM Block Explorer
func NewRollAppWasmBackend(
ctx *server.Context,
logger log.Logger,
clientCtx client.Context,
) *RollAppWasmBackend {
appConf, err := config.GetConfig(ctx.Viper)
if err != nil {
panic(err)
}

return &RollAppWasmBackend{
ctx: context.Background(),
clientCtx: clientCtx,
queryClient: rawberpctypes.NewQueryClient(clientCtx),
logger: logger.With("module", "raw_be_rpc"),
cfg: appConf,
}
}
73 changes: 73 additions & 0 deletions ra_wasm_be_rpc/backend/rollapp_wasm_interceptor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package backend

import (
berpcbackend "github.com/bcdevtools/block-explorer-rpc-cosmos/be_rpc/backend"
berpctypes "github.com/bcdevtools/block-explorer-rpc-cosmos/be_rpc/types"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

var _ berpcbackend.RequestInterceptor = (*RollAppEvmRequestInterceptor)(nil)

type RollAppEvmRequestInterceptor struct {
beRpcBackend berpcbackend.BackendI
backend RollAppWasmBackendI
defaultInterceptor berpcbackend.RequestInterceptor
}

func NewRollAppEvmRequestInterceptor(
beRpcBackend berpcbackend.BackendI,
backend RollAppWasmBackendI,
defaultInterceptor berpcbackend.RequestInterceptor,
) *RollAppEvmRequestInterceptor {
return &RollAppEvmRequestInterceptor{
beRpcBackend: beRpcBackend,
backend: backend,
defaultInterceptor: defaultInterceptor,
}
}

func (m *RollAppEvmRequestInterceptor) GetTransactionByHash(hashStr string) (intercepted bool, response berpctypes.GenericBackendResponse, err error) {
// handled completely by the default interceptor
return m.defaultInterceptor.GetTransactionByHash(hashStr)
}

func (m *RollAppEvmRequestInterceptor) GetDenomsInformation() (intercepted, append bool, denoms map[string]string, err error) {
// handled completely by the default interceptor
return m.defaultInterceptor.GetDenomsInformation()
}

func (m *RollAppEvmRequestInterceptor) GetModuleParams(moduleName string) (intercepted bool, res berpctypes.GenericBackendResponse, err error) {
var params any

switch moduleName {
case "sequencers":
sequencersParams, errFetch := m.backend.GetSequencersModuleParams()
if errFetch != nil {
err = errors.Wrap(errFetch, "failed to get sequencers params")
} else {
params = *sequencersParams
}
default:
return m.defaultInterceptor.GetModuleParams(moduleName)
}

if err != nil {
return
}

res, err = berpctypes.NewGenericBackendResponseFrom(params)
if err != nil {
err = status.Error(codes.Internal, errors.Wrap(err, "module params").Error())
return
}

intercepted = true
return
}

func (m *RollAppEvmRequestInterceptor) GetAccount(accountAddressStr string) (intercepted, append bool, response berpctypes.GenericBackendResponse, err error) {
// handled completely by the default interceptor
return m.defaultInterceptor.GetAccount(accountAddressStr)
}
13 changes: 13 additions & 0 deletions ra_wasm_be_rpc/backend/sequencers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package backend

import (
sequencerstypes "github.com/dymensionxyz/dymension-rdk/x/sequencers/types"
)

func (m *RollAppWasmBackend) GetSequencersModuleParams() (*sequencerstypes.Params, error) {
res, err := m.queryClient.SequencersQueryClient.Params(m.ctx, &sequencerstypes.QueryParamsRequest{})
if err != nil {
return nil, err
}
return &res.Params, nil
}
40 changes: 40 additions & 0 deletions ra_wasm_be_rpc/namespaces/raw/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package raw

import (
"fmt"
"github.com/cosmos/cosmos-sdk/server"
rawberpcbackend "github.com/dymensionxyz/rollapp-wasm/ra_wasm_be_rpc/backend"
"github.com/tendermint/tendermint/libs/log"
)

// RPC namespaces and API version
const (
DymRollAppWasmBlockExplorerNamespace = "raw"

ApiVersion = "1.0"
)

// API is the RollApp Wasm Block Explorer JSON-RPC.
// Developers can create custom API for the chain.
type API struct {
ctx *server.Context
logger log.Logger
backend rawberpcbackend.RollAppWasmBackendI
}

// NewRollAppWasmAPI creates an instance of the RollApp Wasm Block Explorer API.
func NewRollAppWasmAPI(
ctx *server.Context,
backend rawberpcbackend.RollAppWasmBackendI,
) *API {
return &API{
ctx: ctx,
logger: ctx.Logger.With("api", "raw"),
backend: backend,
}
}

func (api *API) Echo(text string) string {
api.logger.Debug("raw_echo")
return fmt.Sprintf("hello \"%s\" from RollApp Wasm Block Explorer API", text)
}
29 changes: 29 additions & 0 deletions ra_wasm_be_rpc/types/query_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package types

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/types/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
epochstypes "github.com/dymensionxyz/dymension-rdk/x/epochs/types"
sequencerstypes "github.com/dymensionxyz/dymension-rdk/x/sequencers/types"
)

// QueryClient defines a gRPC Client used for:
// - Transaction simulation
type QueryClient struct {
tx.ServiceClient

BankQueryClient banktypes.QueryClient
SequencersQueryClient sequencerstypes.QueryClient
EpochQueryClient epochstypes.QueryClient
}

// NewQueryClient creates a new gRPC query client
func NewQueryClient(clientCtx client.Context) *QueryClient {
return &QueryClient{
ServiceClient: tx.NewServiceClient(clientCtx),
BankQueryClient: banktypes.NewQueryClient(clientCtx),
SequencersQueryClient: sequencerstypes.NewQueryClient(clientCtx),
EpochQueryClient: epochstypes.NewQueryClient(clientCtx),
}
}
4 changes: 4 additions & 0 deletions rollappd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"

berpcconfig "github.com/bcdevtools/block-explorer-rpc-cosmos/be_rpc/config"
rdkserver "github.com/dymensionxyz/dymension-rdk/server"
"github.com/dymensionxyz/dymension-rdk/utils"
dymintconf "github.com/dymensionxyz/dymint/config"
Expand Down Expand Up @@ -102,6 +103,9 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
chainID := client.GetClientContextFromCmd(cmd).ChainID
dymintconf.EnsureRoot(home, dymintconf.DefaultConfig(home, chainID))

//create Block Explorer Json-RPC toml config file
berpcconfig.EnsureRoot(home, berpcconfig.DefaultBeJsonRpcConfig())

return nil
},
}
Expand Down
Loading
Loading