@@ -16,6 +16,7 @@ import (
16
16
"github.com/ethereum/go-ethereum/rpc"
17
17
"github.com/ethereum/go-ethereum/xeth"
18
18
"github.com/robertkrimen/otto"
19
+ "gopkg.in/fatih/set.v0"
19
20
)
20
21
21
22
/*
@@ -25,7 +26,7 @@ node admin bindings
25
26
func (js * jsre ) adminBindings () {
26
27
ethO , _ := js .re .Get ("eth" )
27
28
eth := ethO .Object ()
28
- eth .Set ("transactions " , js .transactions )
29
+ eth .Set ("pendingTransactions " , js .pendingTransactions )
29
30
eth .Set ("resend" , js .resend )
30
31
31
32
js .re .Set ("admin" , struct {}{})
@@ -80,43 +81,30 @@ func (js *jsre) getBlock(call otto.FunctionCall) (*types.Block, error) {
80
81
return nil , errors .New ("requires block number or block hash as argument" )
81
82
}
82
83
83
- type tx struct {
84
- tx * types.Transaction
85
-
86
- To string
87
- From string
88
- Nonce string
89
- Value string
90
- Data string
91
- GasLimit string
92
- GasPrice string
93
- }
84
+ func (js * jsre ) pendingTransactions (call otto.FunctionCall ) otto.Value {
85
+ txs := js .ethereum .TxPool ().GetTransactions ()
94
86
95
- func newTx (t * types.Transaction ) * tx {
96
- from , _ := t .From ()
97
- var to string
98
- if t := t .To (); t != nil {
99
- to = t .Hex ()
87
+ // grab the accounts from the account manager. This will help with determening which
88
+ // transactions should be returned.
89
+ accounts , err := js .ethereum .AccountManager ().Accounts ()
90
+ if err != nil {
91
+ fmt .Println (err )
92
+ return otto .UndefinedValue ()
100
93
}
101
94
102
- return & tx {
103
- tx : t ,
104
- To : to ,
105
- From : from .Hex (),
106
- Value : t .Amount .String (),
107
- Nonce : strconv .Itoa (int (t .Nonce ())),
108
- Data : "0x" + common .Bytes2Hex (t .Data ()),
109
- GasLimit : t .GasLimit .String (),
110
- GasPrice : t .GasPrice ().String (),
95
+ // Add the accouns to a new set
96
+ accountSet := set .New ()
97
+ for _ , account := range accounts {
98
+ accountSet .Add (common .BytesToAddress (account .Address ))
111
99
}
112
- }
113
-
114
- func (js * jsre ) transactions (call otto.FunctionCall ) otto.Value {
115
- txs := js .ethereum .TxPool ().GetTransactions ()
116
100
117
- ltxs := make ([]* tx , len (txs ))
118
- for i , tx := range txs {
119
- ltxs [i ] = newTx (tx )
101
+ //ltxs := make([]*tx, len(txs))
102
+ var ltxs []* tx
103
+ for _ , tx := range txs {
104
+ // no need to check err
105
+ if from , _ := tx .From (); accountSet .Has (from ) {
106
+ ltxs = append (ltxs , newTx (tx ))
107
+ }
120
108
}
121
109
122
110
return js .re .ToVal (ltxs )
@@ -504,3 +492,35 @@ func (js *jsre) dumpBlock(call otto.FunctionCall) otto.Value {
504
492
return js .re .ToVal (dump )
505
493
506
494
}
495
+
496
+ // internal transaction type which will allow us to resend transactions using `eth.resend`
497
+ type tx struct {
498
+ tx * types.Transaction
499
+
500
+ To string
501
+ From string
502
+ Nonce string
503
+ Value string
504
+ Data string
505
+ GasLimit string
506
+ GasPrice string
507
+ }
508
+
509
+ func newTx (t * types.Transaction ) * tx {
510
+ from , _ := t .From ()
511
+ var to string
512
+ if t := t .To (); t != nil {
513
+ to = t .Hex ()
514
+ }
515
+
516
+ return & tx {
517
+ tx : t ,
518
+ To : to ,
519
+ From : from .Hex (),
520
+ Value : t .Amount .String (),
521
+ Nonce : strconv .Itoa (int (t .Nonce ())),
522
+ Data : "0x" + common .Bytes2Hex (t .Data ()),
523
+ GasLimit : t .GasLimit .String (),
524
+ GasPrice : t .GasPrice ().String (),
525
+ }
526
+ }
0 commit comments