@@ -38,6 +38,7 @@ type filter struct {
3838 typ Type
3939 deadline * time.Timer // filter is inactive when deadline triggers
4040 hashes []common.Hash
41+ txs []* types.Transaction
4142 crit FilterCriteria
4243 logs []* types.Log
4344 s * Subscription // associated subscription in event system
@@ -96,28 +97,28 @@ func (api *FilterAPI) timeoutLoop(timeout time.Duration) {
9697 }
9798}
9899
99- // NewPendingTransactionFilter creates a filter that fetches pending transaction hashes
100+ // NewPendingTransactionFilter creates a filter that fetches pending transactions
100101// as transactions enter the pending state.
101102//
102103// It is part of the filter package because this filter can be used through the
103104// `eth_getFilterChanges` polling method that is also used for log filters.
104105func (api * FilterAPI ) NewPendingTransactionFilter () rpc.ID {
105106 var (
106- pendingTxs = make (chan []common. Hash )
107+ pendingTxs = make (chan []* types. Transaction )
107108 pendingTxSub = api .events .SubscribePendingTxs (pendingTxs )
108109 )
109110
110111 api .filtersMu .Lock ()
111- api .filters [pendingTxSub .ID ] = & filter {typ : PendingTransactionsSubscription , deadline : time .NewTimer (api .timeout ), hashes : make ([]common. Hash , 0 ), s : pendingTxSub }
112+ api .filters [pendingTxSub .ID ] = & filter {typ : PendingTransactionsSubscription , deadline : time .NewTimer (api .timeout ), txs : make ([]* types. Transaction , 0 ), s : pendingTxSub }
112113 api .filtersMu .Unlock ()
113114
114115 go func () {
115116 for {
116117 select {
117- case ph := <- pendingTxs :
118+ case pTx := <- pendingTxs :
118119 api .filtersMu .Lock ()
119120 if f , found := api .filters [pendingTxSub .ID ]; found {
120- f .hashes = append (f .hashes , ph ... )
121+ f .txs = append (f .txs , pTx ... )
121122 }
122123 api .filtersMu .Unlock ()
123124 case <- pendingTxSub .Err ():
@@ -132,9 +133,10 @@ func (api *FilterAPI) NewPendingTransactionFilter() rpc.ID {
132133 return pendingTxSub .ID
133134}
134135
135- // NewPendingTransactions creates a subscription that is triggered each time a transaction
136- // enters the transaction pool and was signed from one of the transactions this nodes manages.
137- func (api * FilterAPI ) NewPendingTransactions (ctx context.Context ) (* rpc.Subscription , error ) {
136+ // NewPendingTransactions creates a subscription that is triggered each time a
137+ // transaction enters the transaction pool. If fullTx is true the full tx is
138+ // sent to the client, otherwise the hash is sent.
139+ func (api * FilterAPI ) NewPendingTransactions (ctx context.Context , fullTx * bool ) (* rpc.Subscription , error ) {
138140 notifier , supported := rpc .NotifierFromContext (ctx )
139141 if ! supported {
140142 return & rpc.Subscription {}, rpc .ErrNotificationsUnsupported
@@ -143,16 +145,20 @@ func (api *FilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Subscrip
143145 rpcSub := notifier .CreateSubscription ()
144146
145147 go func () {
146- txHashes := make (chan []common. Hash , 128 )
147- pendingTxSub := api .events .SubscribePendingTxs (txHashes )
148+ txs := make (chan []* types. Transaction , 128 )
149+ pendingTxSub := api .events .SubscribePendingTxs (txs )
148150
149151 for {
150152 select {
151- case hashes := <- txHashes :
153+ case txs := <- txs :
152154 // To keep the original behaviour, send a single tx hash in one notification.
153155 // TODO(rjl493456442) Send a batch of tx hashes in one notification
154- for _ , h := range hashes {
155- notifier .Notify (rpcSub .ID , h )
156+ for _ , tx := range txs {
157+ if fullTx != nil && * fullTx {
158+ notifier .Notify (rpcSub .ID , tx )
159+ } else {
160+ notifier .Notify (rpcSub .ID , tx .Hash ())
161+ }
156162 }
157163 case <- rpcSub .Err ():
158164 pendingTxSub .Unsubscribe ()
@@ -411,10 +417,14 @@ func (api *FilterAPI) GetFilterChanges(id rpc.ID) (interface{}, error) {
411417 f .deadline .Reset (api .timeout )
412418
413419 switch f .typ {
414- case PendingTransactionsSubscription , BlocksSubscription :
420+ case BlocksSubscription :
415421 hashes := f .hashes
416422 f .hashes = nil
417423 return returnHashes (hashes ), nil
424+ case PendingTransactionsSubscription :
425+ txs := f .txs
426+ f .txs = nil
427+ return txs , nil
418428 case LogsSubscription , MinedAndPendingLogsSubscription :
419429 logs := f .logs
420430 f .logs = nil
0 commit comments