aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api.go27
-rw-r--r--rpc/args.go10
-rw-r--r--rpc/responses.go4
3 files changed, 41 insertions, 0 deletions
diff --git a/rpc/api.go b/rpc/api.go
index 5c399a844..f552b3ef3 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -597,8 +597,35 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
}
*reply = v
case "eth_getTransactionByHash":
+ return errNotImplemented
case "eth_getTransactionByBlockHashAndIndex":
+ args := new(HashIndexArgs)
+ if err := json.Unmarshal(req.Params, &args); err != nil {
+ return err
+ }
+
+ v, err := p.GetBlockByHash(args.BlockHash, true)
+ if err != nil {
+ return err
+ }
+ if args.TxIndex > int64(len(v.Transactions)) || args.TxIndex < 0 {
+ return NewErrorWithMessage(errDecodeArgs, "Transaction index does not exist")
+ }
+ *reply = v.Transactions[args.TxIndex]
case "eth_getTransactionByBlockNumberAndIndex":
+ args := new(BlockNumIndexArgs)
+ if err := json.Unmarshal(req.Params, &args); err != nil {
+ return err
+ }
+
+ v, err := p.GetBlockByNumber(args.BlockNumber, true)
+ if err != nil {
+ return err
+ }
+ if args.TxIndex > int64(len(v.Transactions)) || args.TxIndex < 0 {
+ return NewErrorWithMessage(errDecodeArgs, "Transaction index does not exist")
+ }
+ *reply = v.Transactions[args.TxIndex]
case "eth_getUncleByBlockHashAndIndex":
case "eth_getUncleByBlockNumberAndIndex":
return errNotImplemented
diff --git a/rpc/args.go b/rpc/args.go
index ab711e78f..2f361526a 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -217,6 +217,16 @@ func (args *GetDataArgs) requirements() error {
return nil
}
+type BlockNumIndexArgs struct {
+ BlockNumber int64
+ TxIndex int64
+}
+
+type HashIndexArgs struct {
+ BlockHash string
+ TxIndex int64
+}
+
type Sha3Args struct {
Data string
}
diff --git a/rpc/responses.go b/rpc/responses.go
index f5db285e1..20b13f6e2 100644
--- a/rpc/responses.go
+++ b/rpc/responses.go
@@ -91,6 +91,10 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) {
}
func NewBlockRes(block *types.Block) *BlockRes {
+ if block == nil {
+ return &BlockRes{}
+ }
+
res := new(BlockRes)
res.BlockNumber = block.Number().Int64()
res.BlockHash = block.Hash()