@@ -11,6 +11,7 @@ import (
11
11
"net/http"
12
12
"sync"
13
13
14
+ "github.com/cosmos/cosmos-sdk/client"
14
15
"github.com/gorilla/mux"
15
16
"github.com/gorilla/websocket"
16
17
"github.com/pkg/errors"
@@ -73,7 +74,7 @@ type websocketsServer struct {
73
74
logger log.Logger
74
75
}
75
76
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 {
77
78
logger = logger .With ("api" , "websocket-server" )
78
79
_ , port , _ := net .SplitHostPort (cfg .JSONRPC .Address )
79
80
@@ -82,7 +83,7 @@ func NewWebsocketsServer(logger log.Logger, tmWSClient *rpcclient.WSClient, cfg
82
83
wsAddr : cfg .JSONRPC .WsAddress ,
83
84
certFile : cfg .TLS .CertificatePath ,
84
85
keyFile : cfg .TLS .KeyPath ,
85
- api : newPubSubAPI (logger , tmWSClient ),
86
+ api : newPubSubAPI (clientCtx , logger , tmWSClient ),
86
87
logger : logger ,
87
88
}
88
89
}
@@ -293,16 +294,18 @@ type pubSubAPI struct {
293
294
filtersMu * sync.RWMutex
294
295
filters map [rpc.ID ]* wsSubscription
295
296
logger log.Logger
297
+ clientCtx client.Context
296
298
}
297
299
298
300
// 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 {
300
302
logger = logger .With ("module" , "websocket-client" )
301
303
return & pubSubAPI {
302
304
events : rpcfilters .NewEventSystem (logger , tmWSClient ),
303
305
filtersMu : new (sync.RWMutex ),
304
306
filters : make (map [rpc.ID ]* wsSubscription ),
305
307
logger : logger ,
308
+ clientCtx : clientCtx ,
306
309
}
307
310
}
308
311
@@ -680,7 +683,11 @@ func (api *pubSubAPI) subscribePendingTransactions(wsConn *wsConn) (rpc.ID, erro
680
683
select {
681
684
case ev := <- txsCh :
682
685
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
+ }
684
691
685
692
api .filtersMu .RLock ()
686
693
for subID , wsSub := range api .filters {
@@ -695,7 +702,7 @@ func (api *pubSubAPI) subscribePendingTransactions(wsConn *wsConn) (rpc.ID, erro
695
702
Method : "eth_subscription" ,
696
703
Params : & SubscriptionResult {
697
704
Subscription : subID ,
698
- Result : txHash ,
705
+ Result : ethTx . Hash ,
699
706
},
700
707
}
701
708
0 commit comments