-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: gRPC server for TxStatus endpoint (#3754)
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
1 parent
1de1fb6
commit 9366dd7
Showing
8 changed files
with
1,114 additions
and
6 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
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 | ||
} |
Oops, something went wrong.