feat: Add tx encode and decode endpoints (#13789)

* add grpc endpoint for encoding proto tx's
This commit is contained in:
Likhita Polavarapu
2022-11-15 04:55:27 +00:00
committed by GitHub
parent ec27c5384b
commit bcff22a376
8 changed files with 3277 additions and 71 deletions
+40
View File
@@ -248,10 +248,50 @@ func (s txServer) GetBlockWithTxs(ctx context.Context, req *txtypes.GetBlockWith
}, nil
}
// BroadcastTx implements the ServiceServer.BroadcastTx RPC method.
func (s txServer) BroadcastTx(ctx context.Context, req *txtypes.BroadcastTxRequest) (*txtypes.BroadcastTxResponse, error) {
return client.TxServiceBroadcast(ctx, s.clientCtx, req)
}
// TxEncode implements the ServiceServer.TxEncode RPC method.
func (s txServer) TxEncode(ctx context.Context, req *txtypes.TxEncodeRequest) (*txtypes.TxEncodeResponse, error) {
if req.Tx == nil {
return nil, status.Error(codes.InvalidArgument, "invalid empty tx")
}
txBuilder := &wrapper{tx: req.Tx}
encodedBytes, err := s.clientCtx.TxConfig.TxEncoder()(txBuilder)
if err != nil {
return nil, err
}
return &txtypes.TxEncodeResponse{
TxBytes: encodedBytes,
}, nil
}
// TxDecode implements the ServiceServer.TxDecode RPC method.
func (s txServer) TxDecode(ctx context.Context, req *txtypes.TxDecodeRequest) (*txtypes.TxDecodeResponse, error) {
if req.TxBytes == nil {
return nil, status.Error(codes.InvalidArgument, "invalid empty tx bytes")
}
txb, err := s.clientCtx.TxConfig.TxDecoder()(req.TxBytes)
if err != nil {
return nil, err
}
txWrapper, ok := txb.(*wrapper)
if ok {
return &txtypes.TxDecodeResponse{
Tx: txWrapper.tx,
}, nil
}
return nil, fmt.Errorf("expected %T, got %T", &wrapper{}, txb)
}
// RegisterTxService registers the tx service on the gRPC router.
func RegisterTxService(
qrt gogogrpc.Server,