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: gRPC server for TxStatus endpoint (backport #3754) #3755

Merged
merged 2 commits into from
Aug 5, 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
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"

celestiatx "github.com/celestiaorg/celestia-app/app/grpc/tx"
"github.com/celestiaorg/celestia-app/x/mint"
mintkeeper "github.com/celestiaorg/celestia-app/x/mint/keeper"
minttypes "github.com/celestiaorg/celestia-app/x/mint/types"
Expand Down Expand Up @@ -682,11 +683,13 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, _ config.APIConfig) {

// Register the
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
celestiatx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
}

// RegisterTxService implements the Application.RegisterTxService method.
func (app *App) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
celestiatx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
Expand Down
81 changes: 81 additions & 0 deletions app/grpc/tx/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package tx

import (
"context"
"encoding/hex"

"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
gogogrpc "github.com/gogo/protobuf/grpc"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)

// RegisterTxService registers the tx service on the gRPC router.
func RegisterTxService(
qrt gogogrpc.Server,
clientCtx client.Context,
interfaceRegistry codectypes.InterfaceRegistry,
) {
RegisterTxServer(
qrt,
NewTxServer(clientCtx, interfaceRegistry),
)
}

// RegisterGRPCGatewayRoutes mounts the tx service's GRPC-gateway routes on the
// given Mux.
func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) {
err := RegisterTxHandlerClient(context.Background(), mux, NewTxClient(clientConn))
if err != nil {
panic(err)
}
}

var _ TxServer = &txServer{}

type txServer struct {
clientCtx client.Context
interfaceRegistry codectypes.InterfaceRegistry
}

func NewTxServer(clientCtx client.Context, interfaceRegistry codectypes.InterfaceRegistry) TxServer {
return &txServer{
clientCtx: clientCtx,
interfaceRegistry: interfaceRegistry,
}
}

// TxStatus implements the TxServer.TxStatus method proxying to the underlying celestia-core RPC server
func (s *txServer) TxStatus(ctx context.Context, req *TxStatusRequest) (*TxStatusResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "request cannot be nil")
}

if len(req.TxId) == 0 {
return nil, status.Error(codes.InvalidArgument, "tx id cannot be empty")
}

node, err := s.clientCtx.GetNode()
if err != nil {
return nil, err
}

txID, err := hex.DecodeString(req.TxId)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid tx id: %s", err)
}

resTx, err := node.TxStatus(ctx, txID)
if err != nil {
return nil, err
}

return &TxStatusResponse{
Height: resTx.Height,
Index: resTx.Index,
ExecutionCode: resTx.ExecutionCode,
Status: resTx.Status,
}, nil
}
Loading
Loading