From d465e410eff0ab255d0e427a8cf2f37ac10311da Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 11 Mar 2015 10:25:15 -0500 Subject: [PATCH 1/4] TxIndex -> Index --- rpc/api.go | 8 ++++---- rpc/args.go | 4 ++-- rpc/responses.go | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/rpc/api.go b/rpc/api.go index f552b3ef3a..335f6cabd7 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -608,10 +608,10 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err != nil { return err } - if args.TxIndex > int64(len(v.Transactions)) || args.TxIndex < 0 { + if args.Index > int64(len(v.Transactions)) || args.Index < 0 { return NewErrorWithMessage(errDecodeArgs, "Transaction index does not exist") } - *reply = v.Transactions[args.TxIndex] + *reply = v.Transactions[args.Index] case "eth_getTransactionByBlockNumberAndIndex": args := new(BlockNumIndexArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -622,10 +622,10 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err != nil { return err } - if args.TxIndex > int64(len(v.Transactions)) || args.TxIndex < 0 { + if args.Index > int64(len(v.Transactions)) || args.Index < 0 { return NewErrorWithMessage(errDecodeArgs, "Transaction index does not exist") } - *reply = v.Transactions[args.TxIndex] + *reply = v.Transactions[args.Index] case "eth_getUncleByBlockHashAndIndex": case "eth_getUncleByBlockNumberAndIndex": return errNotImplemented diff --git a/rpc/args.go b/rpc/args.go index 2f361526a6..ff41e501fd 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -219,12 +219,12 @@ func (args *GetDataArgs) requirements() error { type BlockNumIndexArgs struct { BlockNumber int64 - TxIndex int64 + Index int64 } type HashIndexArgs struct { BlockHash string - TxIndex int64 + Index int64 } type Sha3Args struct { diff --git a/rpc/responses.go b/rpc/responses.go index 20b13f6e25..f41ce7b968 100644 --- a/rpc/responses.go +++ b/rpc/responses.go @@ -2,6 +2,7 @@ package rpc import ( "encoding/json" + // "fmt" "math/big" "github.com/ethereum/go-ethereum/core/types" From 53ac85cfd3188f96bc595a131732bbdbd5d49687 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 11 Mar 2015 10:27:24 -0500 Subject: [PATCH 2/4] BlockHash must be a string --- rpc/args.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rpc/args.go b/rpc/args.go index ff41e501fd..26a61b1a10 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -40,7 +40,12 @@ func (args *GetBlockByHashArgs) UnmarshalJSON(b []byte) (err error) { if len(obj) < 1 { return errArguments } - args.BlockHash = obj[0].(string) + + argstr, ok := obj[0].(string) + if !ok { + return errDecodeArgs + } + args.BlockHash = argstr if len(obj) > 1 { args.Transactions = obj[1].(bool) From 9e89c803f124e98530067c409a67c03d7ab99ef3 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 11 Mar 2015 10:27:32 -0500 Subject: [PATCH 3/4] Get Uncles --- rpc/api.go | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/rpc/api.go b/rpc/api.go index 335f6cabd7..90d09d2811 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -627,8 +627,43 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error } *reply = v.Transactions[args.Index] case "eth_getUncleByBlockHashAndIndex": + args := new(HashIndexArgs) + if err := json.Unmarshal(req.Params, &args); err != nil { + return err + } + + v, err := p.GetBlockByHash(args.BlockHash, false) + if err != nil { + return err + } + if args.Index > int64(len(v.Uncles)) || args.Index < 0 { + return NewErrorWithMessage(errDecodeArgs, "Uncle index does not exist") + } + + uncle, err := p.GetBlockByHash(toHex(v.Uncles[args.Index]), false) + if err != nil { + return err + } + *reply = uncle case "eth_getUncleByBlockNumberAndIndex": - return errNotImplemented + 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.Index > int64(len(v.Uncles)) || args.Index < 0 { + return NewErrorWithMessage(errDecodeArgs, "Uncle index does not exist") + } + + uncle, err := p.GetBlockByHash(toHex(v.Uncles[args.Index]), false) + if err != nil { + return err + } + *reply = uncle case "eth_getCompilers": return p.GetCompilers(reply) case "eth_compileSolidity": From 90f34ed40a1b3c87073d7e2e13b5515cc4cb3940 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 11 Mar 2015 10:56:44 -0500 Subject: [PATCH 4/4] Rename Topic to Topics --- rpc/api.go | 2 +- rpc/args.go | 6 +++--- rpc/args_test.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rpc/api.go b/rpc/api.go index 90d09d2811..337611114a 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -400,7 +400,7 @@ func (self *EthereumApi) MessagesChanged(id int, reply *interface{}) error { } func (p *EthereumApi) WhisperPost(args *WhisperMessageArgs, reply *interface{}) error { - err := p.xeth().Whisper().Post(args.Payload, args.To, args.From, args.Topic, args.Priority, args.Ttl) + err := p.xeth().Whisper().Post(args.Payload, args.To, args.From, args.Topics, args.Priority, args.Ttl) if err != nil { return err } diff --git a/rpc/args.go b/rpc/args.go index 26a61b1a10..d4d8070608 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -367,7 +367,7 @@ type WhisperMessageArgs struct { Payload string To string From string - Topic []string + Topics []string Priority uint32 Ttl uint32 } @@ -377,7 +377,7 @@ func (args *WhisperMessageArgs) UnmarshalJSON(b []byte) (err error) { Payload string To string From string - Topic []string + Topics []string Priority string Ttl string } @@ -392,7 +392,7 @@ func (args *WhisperMessageArgs) UnmarshalJSON(b []byte) (err error) { args.Payload = obj[0].Payload args.To = obj[0].To args.From = obj[0].From - args.Topic = obj[0].Topic + args.Topics = obj[0].Topics args.Priority = uint32(ethutil.Big(obj[0].Priority).Int64()) args.Ttl = uint32(ethutil.Big(obj[0].Ttl).Int64()) diff --git a/rpc/args_test.go b/rpc/args_test.go index ec5400f3fc..0276245001 100644 --- a/rpc/args_test.go +++ b/rpc/args_test.go @@ -270,7 +270,7 @@ func TestFilterOptions(t *testing.T) { t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address) } - // if expected.Topic != args.Topic { + // if expected.Topics != args.Topics { // t.Errorf("Topic shoud be %#v but is %#v", expected.Topic, args.Topic) // } } @@ -316,7 +316,7 @@ func TestWhisperMessageArgs(t *testing.T) { expected.Payload = "0x68656c6c6f20776f726c64" expected.Priority = 100 expected.Ttl = 100 - expected.Topic = []string{"0x68656c6c6f20776f726c64"} + expected.Topics = []string{"0x68656c6c6f20776f726c64"} args := new(WhisperMessageArgs) if err := json.Unmarshal([]byte(input), &args); err != nil { @@ -343,7 +343,7 @@ func TestWhisperMessageArgs(t *testing.T) { t.Errorf("Priority shoud be %#v but is %#v", expected.Priority, args.Priority) } - // if expected.Topic != args.Topic { + // if expected.Topics != args.Topics { // t.Errorf("Topic shoud be %#v but is %#v", expected.Topic, args.Topic) // } }