Skip to content

Commit

Permalink
feat: gRPC server for TxStatus endpoint (#3754)
Browse files Browse the repository at this point in the history
Closes: #3753

This in some ways ties into
#3421
  • Loading branch information
cmwaters authored Aug 3, 2024
1 parent 2116525 commit bb4f712
Show file tree
Hide file tree
Showing 9 changed files with 1,083 additions and 50 deletions.
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/celestiaorg/celestia-app/v3/app/ante"
"github.com/celestiaorg/celestia-app/v3/app/encoding"
celestiatx "github.com/celestiaorg/celestia-app/v3/app/grpc/tx"
"github.com/celestiaorg/celestia-app/v3/app/module"
"github.com/celestiaorg/celestia-app/v3/app/posthandler"
appv1 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v1"
Expand Down Expand Up @@ -718,11 +719,13 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, _ config.APIConfig) {
// Register node gRPC service for grpc-gateway.
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
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

0 comments on commit bb4f712

Please sign in to comment.