@@ -38,6 +38,7 @@ type filter struct {
38
38
typ Type
39
39
deadline * time.Timer // filter is inactive when deadline triggers
40
40
hashes []common.Hash
41
+ txs []* types.Transaction
41
42
crit FilterCriteria
42
43
logs []* types.Log
43
44
s * Subscription // associated subscription in event system
@@ -96,28 +97,28 @@ func (api *FilterAPI) timeoutLoop(timeout time.Duration) {
96
97
}
97
98
}
98
99
99
- // NewPendingTransactionFilter creates a filter that fetches pending transaction hashes
100
+ // NewPendingTransactionFilter creates a filter that fetches pending transactions
100
101
// as transactions enter the pending state.
101
102
//
102
103
// It is part of the filter package because this filter can be used through the
103
104
// `eth_getFilterChanges` polling method that is also used for log filters.
104
105
func (api * FilterAPI ) NewPendingTransactionFilter () rpc.ID {
105
106
var (
106
- pendingTxs = make (chan []common. Hash )
107
+ pendingTxs = make (chan []* types. Transaction )
107
108
pendingTxSub = api .events .SubscribePendingTxs (pendingTxs )
108
109
)
109
110
110
111
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 }
112
113
api .filtersMu .Unlock ()
113
114
114
115
go func () {
115
116
for {
116
117
select {
117
- case ph := <- pendingTxs :
118
+ case pTx := <- pendingTxs :
118
119
api .filtersMu .Lock ()
119
120
if f , found := api .filters [pendingTxSub .ID ]; found {
120
- f .hashes = append (f .hashes , ph ... )
121
+ f .txs = append (f .txs , pTx ... )
121
122
}
122
123
api .filtersMu .Unlock ()
123
124
case <- pendingTxSub .Err ():
@@ -132,9 +133,10 @@ func (api *FilterAPI) NewPendingTransactionFilter() rpc.ID {
132
133
return pendingTxSub .ID
133
134
}
134
135
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 ) {
138
140
notifier , supported := rpc .NotifierFromContext (ctx )
139
141
if ! supported {
140
142
return & rpc.Subscription {}, rpc .ErrNotificationsUnsupported
@@ -143,16 +145,20 @@ func (api *FilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Subscrip
143
145
rpcSub := notifier .CreateSubscription ()
144
146
145
147
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 )
148
150
149
151
for {
150
152
select {
151
- case hashes := <- txHashes :
153
+ case txs := <- txs :
152
154
// To keep the original behaviour, send a single tx hash in one notification.
153
155
// 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
+ }
156
162
}
157
163
case <- rpcSub .Err ():
158
164
pendingTxSub .Unsubscribe ()
@@ -411,10 +417,14 @@ func (api *FilterAPI) GetFilterChanges(id rpc.ID) (interface{}, error) {
411
417
f .deadline .Reset (api .timeout )
412
418
413
419
switch f .typ {
414
- case PendingTransactionsSubscription , BlocksSubscription :
420
+ case BlocksSubscription :
415
421
hashes := f .hashes
416
422
f .hashes = nil
417
423
return returnHashes (hashes ), nil
424
+ case PendingTransactionsSubscription :
425
+ txs := f .txs
426
+ f .txs = nil
427
+ return txs , nil
418
428
case LogsSubscription , MinedAndPendingLogsSubscription :
419
429
logs := f .logs
420
430
f .logs = nil
0 commit comments