From f1a4a6e563ea72affe365d89513e5c83a35e4c28 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Wed, 24 Jun 2015 13:53:37 +0200 Subject: added eth.pendingTransactions --- rpc/api/eth.go | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'rpc/api/eth.go') 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 ðApi{xeth, ethMapping, codec.New(nil)} +func NewEthApi(xeth *xeth.XEth, eth *eth.Ethereum, codec codec.Codec) *ethApi { + return ðApi{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 +} -- cgit v1.2.3 From dc58568a25e54ea601aefb8e97f427cae0814612 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Wed, 24 Jun 2015 14:56:53 +0200 Subject: added eth.resend --- rpc/api/eth.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'rpc/api/eth.go') diff --git a/rpc/api/eth.go b/rpc/api/eth.go index 77c710fb0..2bd7e4cdb 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -6,6 +6,7 @@ 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" @@ -74,6 +75,7 @@ var ( "eth_hashrate": (*ethApi).Hashrate, "eth_getWork": (*ethApi).GetWork, "eth_submitWork": (*ethApi).SubmitWork, + "eth_resend": (*ethApi).Resend, "eth_pendingTransactions": (*ethApi).PendingTransactions, } ) @@ -561,6 +563,22 @@ 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() -- cgit v1.2.3 From a355777ff8531ba91fbdfb093532e7314c15710b Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 29 Jun 2015 11:13:28 +0200 Subject: improved error handling in parsing request --- rpc/api/eth.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'rpc/api/eth.go') diff --git a/rpc/api/eth.go b/rpc/api/eth.go index 2bd7e4cdb..0735754b5 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -12,6 +12,7 @@ import ( "github.com/ethereum/go-ethereum/rpc/shared" "github.com/ethereum/go-ethereum/xeth" "gopkg.in/fatih/set.v0" + "fmt" ) const ( @@ -582,7 +583,7 @@ func (self *ethApi) Resend(req *shared.Request) (interface{}, error) { 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 + // 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 { -- cgit v1.2.3 From f9264e87ec4c612f647a05ea11d5640709577a7f Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 29 Jun 2015 12:32:01 +0200 Subject: add json parsing method for resend transaction --- rpc/api/eth.go | 1 - 1 file changed, 1 deletion(-) (limited to 'rpc/api/eth.go') diff --git a/rpc/api/eth.go b/rpc/api/eth.go index 0735754b5..6c071569c 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -12,7 +12,6 @@ import ( "github.com/ethereum/go-ethereum/rpc/shared" "github.com/ethereum/go-ethereum/xeth" "gopkg.in/fatih/set.v0" - "fmt" ) const ( -- cgit v1.2.3