aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-11 01:52:45 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-11 01:52:45 +0800
commit3d6519e45bbd689b75c3ad6966c2044f29c649df (patch)
tree7bb30324d9002b3a6ea1fb7777b62e23a03a25c4 /rpc/api.go
parent617804c32731c5103319e7072557f62a9ce63836 (diff)
downloaddexon-3d6519e45bbd689b75c3ad6966c2044f29c649df.tar.gz
dexon-3d6519e45bbd689b75c3ad6966c2044f29c649df.tar.zst
dexon-3d6519e45bbd689b75c3ad6966c2044f29c649df.zip
Update response types
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 dc0945d19..20e0e705c 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.DebugDetailf("%T %s", req.Params, 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":