generated from dymensionxyz/rollapp
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(be): integrate block explorer Json-RPC server (#132)
- Loading branch information
Showing
10 changed files
with
322 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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" | ||
hubgentypes "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" | ||
sequencerstypes "github.com/dymensionxyz/dymension-rdk/x/sequencers/types" | ||
raeberpctypes "github.com/dymensionxyz/rollapp-evm/ra_evm_be_rpc/types" | ||
"github.com/tendermint/tendermint/libs/log" | ||
) | ||
|
||
type RollAppEvmBackendI interface { | ||
// Misc | ||
|
||
GetSequencersModuleParams() (*sequencerstypes.Params, error) | ||
GetHubGenesisModuleParams() (*hubgentypes.Params, error) | ||
} | ||
|
||
var _ RollAppEvmBackendI = (*RollAppEvmBackend)(nil) | ||
|
||
// RollAppEvmBackend implements the RollAppEvmBackendI interface | ||
type RollAppEvmBackend struct { | ||
ctx context.Context | ||
clientCtx client.Context | ||
queryClient *raeberpctypes.QueryClient // gRPC query client | ||
logger log.Logger | ||
cfg config.BeJsonRpcConfig | ||
} | ||
|
||
// NewRollAppEvmBackend creates a new RollAppEvmBackend instance for RollApp EVM Block Explorer | ||
func NewRollAppEvmBackend( | ||
ctx *server.Context, | ||
logger log.Logger, | ||
clientCtx client.Context, | ||
) *RollAppEvmBackend { | ||
appConf, err := config.GetConfig(ctx.Viper) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return &RollAppEvmBackend{ | ||
ctx: context.Background(), | ||
clientCtx: clientCtx, | ||
queryClient: raeberpctypes.NewQueryClient(clientCtx), | ||
logger: logger.With("module", "rae_be_rpc"), | ||
cfg: appConf, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package backend | ||
|
||
import ( | ||
hubgentypes "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" | ||
) | ||
|
||
func (m *RollAppEvmBackend) GetHubGenesisModuleParams() (*hubgentypes.Params, error) { | ||
res, err := m.queryClient.HubGenesisQueryClient.Params(m.ctx, &hubgentypes.QueryParamsRequest{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &res.Params, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
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 RollAppEvmBackendI | ||
defaultInterceptor berpcbackend.RequestInterceptor | ||
} | ||
|
||
func NewRollAppEvmRequestInterceptor( | ||
beRpcBackend berpcbackend.BackendI, | ||
backend RollAppEvmBackendI, | ||
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 | ||
} | ||
break | ||
case "hub-genesis": | ||
hubGenesisParams, errFetch := m.backend.GetHubGenesisModuleParams() | ||
if errFetch != nil { | ||
err = errors.Wrap(errFetch, "failed to get hub genesis params") | ||
} else { | ||
params = *hubGenesisParams | ||
} | ||
break | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 *RollAppEvmBackend) GetSequencersModuleParams() (*sequencerstypes.Params, error) { | ||
res, err := m.queryClient.SequencersQueryClient.Params(m.ctx, &sequencerstypes.QueryParamsRequest{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &res.Params, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package rae | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
raeberpcbackend "github.com/dymensionxyz/rollapp-evm/ra_evm_be_rpc/backend" | ||
"github.com/tendermint/tendermint/libs/log" | ||
) | ||
|
||
// RPC namespaces and API version | ||
const ( | ||
DymRollAppEvmBlockExplorerNamespace = "rae" | ||
|
||
ApiVersion = "1.0" | ||
) | ||
|
||
// API is the RollApp EVM Block Explorer JSON-RPC. | ||
// Developers can create custom API for the chain. | ||
type API struct { | ||
ctx *server.Context | ||
logger log.Logger | ||
backend raeberpcbackend.RollAppEvmBackendI | ||
} | ||
|
||
// NewRollAppEvmApi creates an instance of the RollApp EVM Block Explorer API. | ||
func NewRollAppEvmApi( | ||
ctx *server.Context, | ||
backend raeberpcbackend.RollAppEvmBackendI, | ||
) *API { | ||
return &API{ | ||
ctx: ctx, | ||
logger: ctx.Logger.With("api", "rae"), | ||
backend: backend, | ||
} | ||
} | ||
|
||
func (api *API) Echo(text string) string { | ||
api.logger.Debug("rae_echo") | ||
return fmt.Sprintf("hello \"%s\" from RollApp EVM Block Explorer API", text) | ||
} |
Oops, something went wrong.