Get transaction via block & index
This commit is contained in:
parent
ece29c5d8d
commit
9ce5229ddf
27
rpc/api.go
27
rpc/api.go
@ -593,8 +593,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
|
||||
|
10
rpc/args.go
10
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user