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

(cherry picked from commit bb4f712)

# Conflicts:
#	app/app.go
#	app/test/std_sdk_test.go
#	app/test/testnode_test.go
  • Loading branch information
cmwaters authored and mergify[bot] committed Aug 3, 2024
1 parent b6db108 commit ee9412f
Show file tree
Hide file tree
Showing 8 changed files with 1,115 additions and 6 deletions.
24 changes: 24 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,31 @@ import (
"os"
"path/filepath"

<<<<<<< HEAD

Check failure on line 8 in app/app.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: missing import path

Check failure on line 8 in app/app.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

missing import path (typecheck)

Check failure on line 8 in app/app.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: missing import path

Check failure on line 8 in app/app.go

View workflow job for this annotation

GitHub Actions / test / test-coverage

missing import path

Check failure on line 8 in app/app.go

View workflow job for this annotation

GitHub Actions / test / test-race

missing import path

Check failure on line 8 in app/app.go

View workflow job for this annotation

GitHub Actions / test / test

missing import path

Check failure on line 8 in app/app.go

View workflow job for this annotation

GitHub Actions / test / test-short

missing import path
"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"
=======

Check failure on line 12 in app/app.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: missing import path

Check failure on line 12 in app/app.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

missing import path (typecheck)
"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"
appv2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2"
"github.com/celestiaorg/celestia-app/v3/pkg/proof"
blobkeeper "github.com/celestiaorg/celestia-app/v3/x/blob/keeper"
blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types"
blobstreamkeeper "github.com/celestiaorg/celestia-app/v3/x/blobstream/keeper"
blobstreamtypes "github.com/celestiaorg/celestia-app/v3/x/blobstream/types"
"github.com/celestiaorg/celestia-app/v3/x/minfee"
mintkeeper "github.com/celestiaorg/celestia-app/v3/x/mint/keeper"
minttypes "github.com/celestiaorg/celestia-app/v3/x/mint/types"
"github.com/celestiaorg/celestia-app/v3/x/paramfilter"
"github.com/celestiaorg/celestia-app/v3/x/signal"
signaltypes "github.com/celestiaorg/celestia-app/v3/x/signal/types"
"github.com/celestiaorg/celestia-app/v3/x/tokenfilter"
>>>>>>> bb4f7128 (feat: gRPC server for TxStatus endpoint (#3754))

Check failure on line 32 in app/app.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: missing import path

Check failure on line 32 in app/app.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

invalid character U+0023 '#' (typecheck)

Check failure on line 32 in app/app.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

missing import path (typecheck)
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
Expand Down Expand Up @@ -682,11 +704,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 ee9412f

Please sign in to comment.