aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
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-30 17:20:31 +0800
commit056e9dd393eeb7ddb4f6bf3e508228e1874bc94e (patch)
treef21087dbe1e6a955d22b96586a9b846d3471003f /rpc
parent9226369b5daf8c1bf738369cd838963a5d58362d (diff)
downloadgo-tangerine-056e9dd393eeb7ddb4f6bf3e508228e1874bc94e.tar
go-tangerine-056e9dd393eeb7ddb4f6bf3e508228e1874bc94e.tar.gz
go-tangerine-056e9dd393eeb7ddb4f6bf3e508228e1874bc94e.tar.bz2
go-tangerine-056e9dd393eeb7ddb4f6bf3e508228e1874bc94e.tar.lz
go-tangerine-056e9dd393eeb7ddb4f6bf3e508228e1874bc94e.tar.xz
go-tangerine-056e9dd393eeb7ddb4f6bf3e508228e1874bc94e.tar.zst
go-tangerine-056e9dd393eeb7ddb4f6bf3e508228e1874bc94e.zip
added eth.pendingTransactions
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api/eth.go40
-rw-r--r--rpc/api/eth_args.go34
-rw-r--r--rpc/api/eth_js.go8
-rw-r--r--rpc/api/utils.go3
4 files changed, 79 insertions, 6 deletions
diff --git a/rpc/api/eth.go b/rpc/api/eth.go
index 962c8d0f9..d77bf9803 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
@@ -548,3 +552,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
+}
diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go
index bf8ffead6..39c003f66 100644
--- a/rpc/api/eth_args.go
+++ b/rpc/api/eth_args.go
@@ -5,8 +5,11 @@ import (
"fmt"
"math/big"
+ "strconv"
+
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
+ "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc/shared"
)
@@ -858,3 +861,34 @@ func (args *SubmitWorkArgs) UnmarshalJSON(b []byte) (err error) {
return nil
}
+
+type tx struct {
+ tx *types.Transaction
+
+ To string
+ From string
+ Nonce string
+ Value string
+ Data string
+ GasLimit string
+ GasPrice string
+}
+
+func newTx(t *types.Transaction) *tx {
+ from, _ := t.From()
+ var to string
+ if t := t.To(); t != nil {
+ to = t.Hex()
+ }
+
+ return &tx{
+ tx: t,
+ To: to,
+ From: from.Hex(),
+ Value: t.Amount.String(),
+ Nonce: strconv.Itoa(int(t.Nonce())),
+ Data: "0x" + common.Bytes2Hex(t.Data()),
+ GasLimit: t.GasLimit.String(),
+ GasPrice: t.GasPrice().String(),
+ }
+}
diff --git a/rpc/api/eth_js.go b/rpc/api/eth_js.go
index e1268eb76..8d0fe8f0a 100644
--- a/rpc/api/eth_js.go
+++ b/rpc/api/eth_js.go
@@ -15,6 +15,14 @@ web3._extend({
inputFormatter: [web3._extend.formatters.formatInputString,web3._extend.formatters.formatInputString],
outputFormatter: web3._extend.formatters.formatOutputString
})
+ ],
+ properties:
+ [
+ new web3._extend.Property({
+ name: 'pendingTransactions',
+ getter: 'eth_pendingTransactions',
+ outputFormatter: function(obj) { return obj; }
+ })
]
});
`
diff --git a/rpc/api/utils.go b/rpc/api/utils.go
index 6e4835de6..3d46f78d3 100644
--- a/rpc/api/utils.go
+++ b/rpc/api/utils.go
@@ -84,6 +84,7 @@ var (
"hashrate",
"getWork",
"submitWork",
+ "pendingTransactions",
},
"miner": []string{
"hashrate",
@@ -149,7 +150,7 @@ func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.
case shared.DbApiName:
apis[i] = NewDbApi(xeth, eth, codec)
case shared.EthApiName:
- apis[i] = NewEthApi(xeth, codec)
+ apis[i] = NewEthApi(xeth, eth, codec)
case shared.MinerApiName:
apis[i] = NewMinerApi(eth, codec)
case shared.NetApiName: