aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api/eth.go
diff options
context:
space:
mode:
authorBas van Kervel <bas@ethdev.com>2015-06-24 19:53:37 +0800
committerBas van Kervel <bas@ethdev.com>2015-06-24 19:53:37 +0800
commitf1a4a6e563ea72affe365d89513e5c83a35e4c28 (patch)
treea1c5f9685fd1e3cc0e21799e74c5ef216a1a9f0e /rpc/api/eth.go
parent22c7ce0162f2d14a7340e00e93697780c91d2087 (diff)
downloaddexon-f1a4a6e563ea72affe365d89513e5c83a35e4c28.tar
dexon-f1a4a6e563ea72affe365d89513e5c83a35e4c28.tar.gz
dexon-f1a4a6e563ea72affe365d89513e5c83a35e4c28.tar.bz2
dexon-f1a4a6e563ea72affe365d89513e5c83a35e4c28.tar.lz
dexon-f1a4a6e563ea72affe365d89513e5c83a35e4c28.tar.xz
dexon-f1a4a6e563ea72affe365d89513e5c83a35e4c28.tar.zst
dexon-f1a4a6e563ea72affe365d89513e5c83a35e4c28.zip
added eth.pendingTransactions
Diffstat (limited to 'rpc/api/eth.go')
-rw-r--r--rpc/api/eth.go40
1 files changed, 35 insertions, 5 deletions
diff --git a/rpc/api/eth.go b/rpc/api/eth.go
index 0dff138c6..77c710fb0 100644
--- a/rpc/api/eth.go
+++ b/rpc/api/eth.go
@@ -6,9 +6,11 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/xeth"
+ "gopkg.in/fatih/set.v0"
)
const (
@@ -18,9 +20,10 @@ const (
// eth api provider
// See https://github.com/ethereum/wiki/wiki/JSON-RPC
type ethApi struct {
- xeth *xeth.XEth
- methods map[string]ethhandler
- codec codec.ApiCoder
+ xeth *xeth.XEth
+ ethereum *eth.Ethereum
+ methods map[string]ethhandler
+ codec codec.ApiCoder
}
// eth callback handler
@@ -71,12 +74,13 @@ var (
"eth_hashrate": (*ethApi).Hashrate,
"eth_getWork": (*ethApi).GetWork,
"eth_submitWork": (*ethApi).SubmitWork,
+ "eth_pendingTransactions": (*ethApi).PendingTransactions,
}
)
// create new ethApi instance
-func NewEthApi(xeth *xeth.XEth, codec codec.Codec) *ethApi {
- return &ethApi{xeth, ethMapping, codec.New(nil)}
+func NewEthApi(xeth *xeth.XEth, eth *eth.Ethereum, codec codec.Codec) *ethApi {
+ return &ethApi{xeth, eth, ethMapping, codec.New(nil)}
}
// collection with supported methods
@@ -556,3 +560,29 @@ func (self *ethApi) SubmitWork(req *shared.Request) (interface{}, error) {
}
return self.xeth.RemoteMining().SubmitWork(args.Nonce, common.HexToHash(args.Digest), common.HexToHash(args.Header)), nil
}
+
+func (self *ethApi) PendingTransactions(req *shared.Request) (interface{}, error) {
+ txs := self.ethereum.TxPool().GetTransactions()
+
+ // grab the accounts from the account manager. This will help with determening which
+ // transactions should be returned.
+ accounts, err := self.ethereum.AccountManager().Accounts()
+ if err != nil {
+ return nil, err
+ }
+
+ // Add the accouns to a new set
+ accountSet := set.New()
+ for _, account := range accounts {
+ accountSet.Add(account.Address)
+ }
+
+ var ltxs []*tx
+ for _, tx := range txs {
+ if from, _ := tx.From(); accountSet.Has(from) {
+ ltxs = append(ltxs, newTx(tx))
+ }
+ }
+
+ return ltxs, nil
+}