Skip to content

Commit

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

This in some ways ties into
https://github.com/celestiaorg/celestia-app/issues/3421<hr>This is an
automatic backport of pull request #3754 done by
[Mergify](https://mergify.com).

---------

Co-authored-by: Callum Waters <[email protected]>
  • Loading branch information
mergify[bot] and cmwaters committed Aug 5, 2024
1 parent b6db108 commit 548e21a
Show file tree
Hide file tree
Showing 7 changed files with 1,055 additions and 6 deletions.
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

0 comments on commit 548e21a

Please sign in to comment.