diff options
author | obscuren <geffobscura@gmail.com> | 2015-06-16 01:28:48 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-06-16 01:28:48 +0800 |
commit | 5daf8729be88eca87b302ebf7a46fc69cad0f6d0 (patch) | |
tree | 0053cb5b84978645b3c83895a651c512e081a183 /rpc/api/txpool.go | |
parent | bac9a94ddf20dc530966cbf6cd384aaf94aedc77 (diff) | |
parent | 4673b04503742de9b1622557b44135d6a4934ad6 (diff) | |
download | go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.tar go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.tar.gz go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.tar.bz2 go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.tar.lz go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.tar.xz go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.tar.zst go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.zip |
Merge branch 'release/0.9.30'v0.9.30
Diffstat (limited to 'rpc/api/txpool.go')
-rw-r--r-- | rpc/api/txpool.go | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/rpc/api/txpool.go b/rpc/api/txpool.go new file mode 100644 index 000000000..64550bdaf --- /dev/null +++ b/rpc/api/txpool.go @@ -0,0 +1,75 @@ +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" +) + +const ( + TxPoolApiVersion = "1.0" +) + +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) ApiVersion() string { + return TxPoolApiVersion +} + +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 +} |