Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit aeb6aeb

Browse files
authored
Problem: newPendingTransactions filter don't return ethereum tx hash (#900)
1 parent cad7545 commit aeb6aeb

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
7272
* (rpc) [tharsis#865](https://github.com/tharsis/ethermint/pull/865) Fix RPC Filter parameters being ignored
7373
* (evm) [tharsis#871](https://github.com/tharsis/ethermint/pull/871) Set correct nonce in `EthCall` and `EstimateGas` grpc query.
7474
* (rpc) [tharsis#878](https://github.com/tharsis/ethermint/pull/878) Workaround to make GetBlock RPC api report correct block gas used.
75+
* (rpc) [tharsis#900](https://github.com/tharsis/ethermint/pull/900) newPendingTransactions filter return ethereum tx hash.
7576

7677
## [v0.9.0] - 2021-12-01
7778

rpc/ethereum/types/utils.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ func RawTxToEthTx(clientCtx client.Context, txBz tmtypes.Tx) (*evmtypes.MsgEther
3131
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
3232
}
3333

34-
ethTx, ok := tx.(*evmtypes.MsgEthereumTx)
34+
if len(tx.GetMsgs()) != 1 {
35+
return nil, errors.New("not ethereum tx")
36+
}
37+
38+
ethTx, ok := tx.GetMsgs()[0].(*evmtypes.MsgEthereumTx)
3539
if !ok {
36-
return nil, fmt.Errorf("invalid transaction type %T, expected %T", tx, evmtypes.MsgEthereumTx{})
40+
return nil, fmt.Errorf("invalid msg type %T, expected %T", tx, evmtypes.MsgEthereumTx{})
3741
}
3842
return ethTx, nil
3943
}

rpc/websockets.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"sync"
1313

14+
"github.com/cosmos/cosmos-sdk/client"
1415
"github.com/gorilla/mux"
1516
"github.com/gorilla/websocket"
1617
"github.com/pkg/errors"
@@ -73,7 +74,7 @@ type websocketsServer struct {
7374
logger log.Logger
7475
}
7576

76-
func NewWebsocketsServer(logger log.Logger, tmWSClient *rpcclient.WSClient, cfg config.Config) WebsocketsServer {
77+
func NewWebsocketsServer(clientCtx client.Context, logger log.Logger, tmWSClient *rpcclient.WSClient, cfg config.Config) WebsocketsServer {
7778
logger = logger.With("api", "websocket-server")
7879
_, port, _ := net.SplitHostPort(cfg.JSONRPC.Address)
7980

@@ -82,7 +83,7 @@ func NewWebsocketsServer(logger log.Logger, tmWSClient *rpcclient.WSClient, cfg
8283
wsAddr: cfg.JSONRPC.WsAddress,
8384
certFile: cfg.TLS.CertificatePath,
8485
keyFile: cfg.TLS.KeyPath,
85-
api: newPubSubAPI(logger, tmWSClient),
86+
api: newPubSubAPI(clientCtx, logger, tmWSClient),
8687
logger: logger,
8788
}
8889
}
@@ -293,16 +294,18 @@ type pubSubAPI struct {
293294
filtersMu *sync.RWMutex
294295
filters map[rpc.ID]*wsSubscription
295296
logger log.Logger
297+
clientCtx client.Context
296298
}
297299

298300
// newPubSubAPI creates an instance of the ethereum PubSub API.
299-
func newPubSubAPI(logger log.Logger, tmWSClient *rpcclient.WSClient) *pubSubAPI {
301+
func newPubSubAPI(clientCtx client.Context, logger log.Logger, tmWSClient *rpcclient.WSClient) *pubSubAPI {
300302
logger = logger.With("module", "websocket-client")
301303
return &pubSubAPI{
302304
events: rpcfilters.NewEventSystem(logger, tmWSClient),
303305
filtersMu: new(sync.RWMutex),
304306
filters: make(map[rpc.ID]*wsSubscription),
305307
logger: logger,
308+
clientCtx: clientCtx,
306309
}
307310
}
308311

@@ -680,7 +683,11 @@ func (api *pubSubAPI) subscribePendingTransactions(wsConn *wsConn) (rpc.ID, erro
680683
select {
681684
case ev := <-txsCh:
682685
data, _ := ev.Data.(tmtypes.EventDataTx)
683-
txHash := common.BytesToHash(tmtypes.Tx(data.Tx).Hash())
686+
ethTx, err := types.RawTxToEthTx(api.clientCtx, data.Tx)
687+
if err != nil {
688+
// not ethereum tx
689+
panic("debug")
690+
}
684691

685692
api.filtersMu.RLock()
686693
for subID, wsSub := range api.filters {
@@ -695,7 +702,7 @@ func (api *pubSubAPI) subscribePendingTransactions(wsConn *wsConn) (rpc.ID, erro
695702
Method: "eth_subscription",
696703
Params: &SubscriptionResult{
697704
Subscription: subID,
698-
Result: txHash,
705+
Result: ethTx.Hash,
699706
},
700707
}
701708

server/json_rpc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func StartJSONRPC(ctx *server.Context, clientCtx client.Context, tmRPCAddr, tmEn
7575

7676
// allocate separate WS connection to Tendermint
7777
tmWsClient = ConnectTmWS(tmRPCAddr, tmEndpoint, ctx.Logger)
78-
wsSrv := rpc.NewWebsocketsServer(ctx.Logger, tmWsClient, config)
78+
wsSrv := rpc.NewWebsocketsServer(clientCtx, ctx.Logger, tmWsClient, config)
7979
wsSrv.Start()
8080
return httpSrv, httpSrvDone, nil
8181
}

0 commit comments

Comments
 (0)