diff options
author | Bas van Kervel <bas@ethdev.com> | 2015-06-10 16:37:10 +0800 |
---|---|---|
committer | Bas van Kervel <basvankervel@gmail.com> | 2015-06-11 20:01:41 +0800 |
commit | 87b62f75a7b9c15c17f3352f1b50ad88966e7070 (patch) | |
tree | b63038e521d6d685160725e55168796f7f035179 /rpc/api/txpool.go | |
parent | c6c443385b3e9998d3090785e4287e3836c70219 (diff) | |
download | go-tangerine-87b62f75a7b9c15c17f3352f1b50ad88966e7070.tar go-tangerine-87b62f75a7b9c15c17f3352f1b50ad88966e7070.tar.gz go-tangerine-87b62f75a7b9c15c17f3352f1b50ad88966e7070.tar.bz2 go-tangerine-87b62f75a7b9c15c17f3352f1b50ad88966e7070.tar.lz go-tangerine-87b62f75a7b9c15c17f3352f1b50ad88966e7070.tar.xz go-tangerine-87b62f75a7b9c15c17f3352f1b50ad88966e7070.tar.zst go-tangerine-87b62f75a7b9c15c17f3352f1b50ad88966e7070.zip |
added txpool API
Diffstat (limited to 'rpc/api/txpool.go')
-rw-r--r-- | rpc/api/txpool.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/rpc/api/txpool.go b/rpc/api/txpool.go new file mode 100644 index 000000000..f340c501f --- /dev/null +++ b/rpc/api/txpool.go @@ -0,0 +1,67 @@ +package api + +import ( + "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" +) + +var ( + // mapping between methods and handlers + txpoolMapping = map[string]txpoolhandler{ + "txpool_status": (*txPoolApi).Status, + } +) + +// net callback handler +type txpoolhandler func(*txPoolApi, *shared.Request) (interface{}, error) + +// txpool api provider +type txPoolApi struct { + xeth *xeth.XEth + ethereum *eth.Ethereum + methods map[string]txpoolhandler + codec codec.ApiCoder +} + +// create a new txpool api instance +func NewTxPoolApi(xeth *xeth.XEth, eth *eth.Ethereum, coder codec.Codec) *txPoolApi { + return &txPoolApi{ + xeth: xeth, + ethereum: eth, + methods: txpoolMapping, + codec: coder.New(nil), + } +} + +// collection with supported methods +func (self *txPoolApi) Methods() []string { + methods := make([]string, len(self.methods)) + i := 0 + for k := range self.methods { + methods[i] = k + i++ + } + return methods +} + +// Execute given request +func (self *txPoolApi) Execute(req *shared.Request) (interface{}, error) { + if callback, ok := self.methods[req.Method]; ok { + return callback(self, req) + } + + return nil, shared.NewNotImplementedError(req.Method) +} + +func (self *txPoolApi) Name() string { + return txPoolApiName +} + +func (self *txPoolApi) Status(req *shared.Request) (interface{}, error) { + return map[string]int{ + "pending": self.ethereum.TxPool().GetTransactions().Len(), + "queued": self.ethereum.TxPool().GetQueuedTransactions().Len(), + }, nil +} |