aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-11 03:16:08 +0800
committerobscuren <geffobscura@gmail.com>2015-03-11 03:16:08 +0800
commitd9f96293bee9bee16ee6abd9774b385df0b9ad87 (patch)
treebee9fc46c70d3bb6cab0dc1528b6736fe6568126 /rpc/api.go
parentf22684439a807f88406e90718e61d536edd469f1 (diff)
parent3d6519e45bbd689b75c3ad6966c2044f29c649df (diff)
downloaddexon-d9f96293bee9bee16ee6abd9774b385df0b9ad87.tar
dexon-d9f96293bee9bee16ee6abd9774b385df0b9ad87.tar.gz
dexon-d9f96293bee9bee16ee6abd9774b385df0b9ad87.tar.bz2
dexon-d9f96293bee9bee16ee6abd9774b385df0b9ad87.tar.lz
dexon-d9f96293bee9bee16ee6abd9774b385df0b9ad87.tar.xz
dexon-d9f96293bee9bee16ee6abd9774b385df0b9ad87.tar.zst
dexon-d9f96293bee9bee16ee6abd9774b385df0b9ad87.zip
Merge branch 'rpcfrontier' of github.com-obscure:ethereum/go-ethereum into rpcfrontier
Conflicts: rpc/args.go
Diffstat (limited to 'rpc/api.go')
-rw-r--r--rpc/api.go95
1 files changed, 90 insertions, 5 deletions
diff --git a/rpc/api.go b/rpc/api.go
index c03168863..0abed3c14 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -415,6 +415,44 @@ func (p *EthereumApi) WhisperMessages(id int, reply *interface{}) error {
return nil
}
+func (p *EthereumApi) GetBlockByHash(blockhash string, includetx bool) (*BlockRes, error) {
+ block := p.xeth().EthBlockByHash(blockhash)
+ br := NewBlockRes(block)
+ br.fullTx = includetx
+ return br, nil
+}
+
+func (p *EthereumApi) GetBlockByNumber(blocknum int64, includetx bool) (*BlockRes, error) {
+ block := p.xeth().EthBlockByNumber(blocknum)
+ br := NewBlockRes(block)
+ br.fullTx = includetx
+ return br, nil
+}
+
+func (p *EthereumApi) GetBlockTransactionCountByHash(blockhash string) (int64, error) {
+ block := p.xeth().EthBlockByHash(blockhash)
+ br := NewBlockRes(block)
+ return int64(len(br.Transactions)), nil
+}
+
+func (p *EthereumApi) GetBlockTransactionCountByNumber(blocknum int64) (int64, error) {
+ block := p.xeth().EthBlockByNumber(blocknum)
+ br := NewBlockRes(block)
+ return int64(len(br.Transactions)), nil
+}
+
+func (p *EthereumApi) GetBlockUncleCountByHash(blockhash string) (int64, error) {
+ block := p.xeth().EthBlockByHash(blockhash)
+ br := NewBlockRes(block)
+ return int64(len(br.Uncles)), nil
+}
+
+func (p *EthereumApi) GetBlockUncleCountByNumber(blocknum int64) (int64, error) {
+ block := p.xeth().EthBlockByNumber(blocknum)
+ br := NewBlockRes(block)
+ return int64(len(br.Uncles)), nil
+}
+
func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error {
// Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC
rpclogger.Infof("%s %s", req.Method, req.Params)
@@ -468,10 +506,49 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
}
return p.GetTxCountAt(args, reply)
case "eth_getBlockTransactionCountByHash":
+ args := new(GetBlockByHashArgs)
+ if err := json.Unmarshal(req.Params, &args); err != nil {
+ return err
+ }
+
+ v, err := p.GetBlockTransactionCountByHash(args.BlockHash)
+ if err != nil {
+ return err
+ }
+ *reply = toHex(big.NewInt(v).Bytes())
case "eth_getBlockTransactionCountByNumber":
+ args := new(GetBlockByNumberArgs)
+ if err := json.Unmarshal(req.Params, &args); err != nil {
+ return err
+ }
+
+ v, err := p.GetBlockTransactionCountByNumber(args.BlockNumber)
+ if err != nil {
+ return err
+ }
+ *reply = toHex(big.NewInt(v).Bytes())
case "eth_getUncleCountByBlockHash":
+ args := new(GetBlockByHashArgs)
+ if err := json.Unmarshal(req.Params, &args); err != nil {
+ return err
+ }
+
+ v, err := p.GetBlockUncleCountByHash(args.BlockHash)
+ if err != nil {
+ return err
+ }
+ *reply = toHex(big.NewInt(v).Bytes())
case "eth_getUncleCountByBlockNumber":
- return errNotImplemented
+ args := new(GetBlockByNumberArgs)
+ if err := json.Unmarshal(req.Params, &args); err != nil {
+ return err
+ }
+
+ v, err := p.GetBlockUncleCountByNumber(args.BlockNumber)
+ if err != nil {
+ return err
+ }
+ *reply = toHex(big.NewInt(v).Bytes())
case "eth_getData":
// TODO handle BlockNumber
args := new(GetDataArgs)
@@ -494,19 +571,27 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
case "eth_flush":
return errNotImplemented
case "eth_getBlockByHash":
- // TODO handle second param for "include transaction objects"
args := new(GetBlockByHashArgs)
if err := json.Unmarshal(req.Params, &args); err != nil {
return err
}
- *reply = p.xeth().BlockByHash(args.BlockHash)
+
+ v, err := p.GetBlockByHash(args.BlockHash, args.Transactions)
+ if err != nil {
+ return err
+ }
+ *reply = v
case "eth_getBlockByNumber":
- // TODO handle second param for "include transaction objects"
args := new(GetBlockByNumberArgs)
if err := json.Unmarshal(req.Params, &args); err != nil {
return err
}
- *reply = p.xeth().BlockByNumber(args.BlockNumber)
+
+ v, err := p.GetBlockByNumber(args.BlockNumber, args.Transactions)
+ if err != nil {
+ return err
+ }
+ *reply = v
case "eth_getTransactionByHash":
case "eth_getTransactionByBlockHashAndIndex":
case "eth_getTransactionByBlockNumberAndIndex":