Skip to content

Commit 05ac120

Browse files
committed
cmd/geth: limit pendingTransactions to owned accounts.
1 parent eb40292 commit 05ac120

File tree

1 file changed

+53
-33
lines changed

1 file changed

+53
-33
lines changed

cmd/geth/admin.go

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/ethereum/go-ethereum/rpc"
1717
"github.com/ethereum/go-ethereum/xeth"
1818
"github.com/robertkrimen/otto"
19+
"gopkg.in/fatih/set.v0"
1920
)
2021

2122
/*
@@ -25,7 +26,7 @@ node admin bindings
2526
func (js *jsre) adminBindings() {
2627
ethO, _ := js.re.Get("eth")
2728
eth := ethO.Object()
28-
eth.Set("transactions", js.transactions)
29+
eth.Set("pendingTransactions", js.pendingTransactions)
2930
eth.Set("resend", js.resend)
3031

3132
js.re.Set("admin", struct{}{})
@@ -80,43 +81,30 @@ func (js *jsre) getBlock(call otto.FunctionCall) (*types.Block, error) {
8081
return nil, errors.New("requires block number or block hash as argument")
8182
}
8283

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()
9486

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()
10093
}
10194

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))
11199
}
112-
}
113-
114-
func (js *jsre) transactions(call otto.FunctionCall) otto.Value {
115-
txs := js.ethereum.TxPool().GetTransactions()
116100

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+
}
120108
}
121109

122110
return js.re.ToVal(ltxs)
@@ -504,3 +492,35 @@ func (js *jsre) dumpBlock(call otto.FunctionCall) otto.Value {
504492
return js.re.ToVal(dump)
505493

506494
}
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

Comments
 (0)