feat: Add tx encode and decode endpoints (#13789)
* add grpc endpoint for encoding proto tx's
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user