aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api/eth.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-06-30 23:27:03 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-06-30 23:27:03 +0800
commitba95e445e16481ea7a94a462347def19b0c2bf2c (patch)
tree23b3b86b1828819f6fffe411567824c2f227e147 /rpc/api/eth.go
parent130f3b270a9b2f7bd680188c67013695d5f9412b (diff)
parent8c4d493c66cf14f0bcb8b650045a644722ad8d90 (diff)
downloadgo-tangerine-ba95e445e16481ea7a94a462347def19b0c2bf2c.tar
go-tangerine-ba95e445e16481ea7a94a462347def19b0c2bf2c.tar.gz
go-tangerine-ba95e445e16481ea7a94a462347def19b0c2bf2c.tar.bz2
go-tangerine-ba95e445e16481ea7a94a462347def19b0c2bf2c.tar.lz
go-tangerine-ba95e445e16481ea7a94a462347def19b0c2bf2c.tar.xz
go-tangerine-ba95e445e16481ea7a94a462347def19b0c2bf2c.tar.zst
go-tangerine-ba95e445e16481ea7a94a462347def19b0c2bf2c.zip
Merge pull request #1328 from bas-vk/issue1327
Add pendingTransactions and resend
Diffstat (limited to 'rpc/api/eth.go')
-rw-r--r--rpc/api/eth.go58
1 files changed, 53 insertions, 5 deletions
diff --git a/rpc/api/eth.go b/rpc/api/eth.go
index 962c8d0f9..db0b4b024 100644
--- a/rpc/api/eth.go
+++ b/rpc/api/eth.go
@@ -6,9 +6,12 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/core/types"
+ "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 +21,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 +75,14 @@ var (
"eth_hashrate": (*ethApi).Hashrate,
"eth_getWork": (*ethApi).GetWork,
"eth_submitWork": (*ethApi).SubmitWork,
+ "eth_resend": (*ethApi).Resend,
+ "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 +554,45 @@ 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) Resend(req *shared.Request) (interface{}, error) {
+ args := new(ResendArgs)
+ if err := self.codec.Decode(req.Params, &args); err != nil {
+ return nil, shared.NewDecodeParamError(err.Error())
+ }
+
+ ret, err := self.xeth.Transact(args.Tx.From, args.Tx.To, args.Tx.Nonce, args.Tx.Value, args.GasLimit, args.GasPrice, args.Tx.Data)
+ if err != nil {
+ return nil, err
+ }
+
+ self.ethereum.TxPool().RemoveTransactions(types.Transactions{args.Tx.tx})
+
+ return ret, 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 determining 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
+}