提交 87b62f75 编写于 作者: B Bas van Kervel 提交者: Bas van Kervel

added txpool API

上级 c6c44338
......@@ -13,6 +13,7 @@ const (
MergedApiName = "merged"
MinerApiName = "miner"
NetApiName = "net"
txPoolApiName = "txpool"
PersonalApiName = "personal"
Web3ApiName = "web3"
)
......@@ -20,7 +21,7 @@ const (
var (
// List with all API's which are offered over the IPC interface by default
DefaultIpcApis = strings.Join([]string{
AdminApiName, EthApiName, DebugApiName, MinerApiName, NetApiName, PersonalApiName, Web3ApiName,
AdminApiName, EthApiName, DebugApiName, MinerApiName, NetApiName, txPoolApiName, PersonalApiName, Web3ApiName,
}, ",")
)
......
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
}
package api
const TxPool_JS = `
web3._extend({
property: 'txpool',
methods:
[
],
properties:
[
new web3._extend.Property({
name: 'status',
getter: 'txpool_status',
outputFormatter: function(obj) { return obj; }
})
]
});
`
......@@ -31,6 +31,8 @@ func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.
apis[i] = NewMinerApi(eth, codec)
case NetApiName:
apis[i] = NewNetApi(xeth, eth, codec)
case txPoolApiName:
apis[i] = NewTxPoolApi(xeth, eth, codec)
case PersonalApiName:
apis[i] = NewPersonalApi(xeth, eth, codec)
case Web3ApiName:
......@@ -53,6 +55,8 @@ func Javascript(name string) string {
return Miner_JS
case NetApiName:
return Net_JS
case txPoolApiName:
return TxPool_JS
case PersonalApiName:
return Personal_JS
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册