Skip to content

Commit 048d4ec

Browse files
committed
Merge branch 'rpcfrontier' into develop
2 parents 53104b0 + 917050d commit 048d4ec

6 files changed

Lines changed: 179 additions & 42 deletions

File tree

‎rpc/api.go‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
"sync"
1010
"time"
1111

12+
"github.com/ethereum/go-ethereum/common"
1213
"github.com/ethereum/go-ethereum/core"
1314
"github.com/ethereum/go-ethereum/core/types"
1415
"github.com/ethereum/go-ethereum/crypto"
1516
"github.com/ethereum/go-ethereum/ethdb"
16-
"github.com/ethereum/go-ethereum/common"
1717
"github.com/ethereum/go-ethereum/event"
1818
"github.com/ethereum/go-ethereum/event/filter"
1919
"github.com/ethereum/go-ethereum/state"
@@ -371,6 +371,11 @@ func (p *EthereumApi) NewWhisperIdentity(reply *interface{}) error {
371371
return nil
372372
}
373373

374+
// func (p *EthereumApi) RemoveWhisperIdentity(args *WhisperIdentityArgs, reply *interface{}) error {
375+
// *reply = p.xeth().Whisper().RemoveIdentity(args.Identity)
376+
// return nil
377+
// }
378+
374379
func (p *EthereumApi) NewWhisperFilter(args *WhisperFilterArgs, reply *interface{}) error {
375380
var id int
376381
opts := new(xeth.Options)
@@ -751,6 +756,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
751756
return p.WhisperPost(args, reply)
752757
case "shh_newIdentity":
753758
return p.NewWhisperIdentity(reply)
759+
// case "shh_removeIdentity":
760+
// args := new(WhisperIdentityArgs)
761+
// if err := json.Unmarshal(req.Params, &args); err != nil {
762+
// return err
763+
// }
764+
// return p.RemoveWhisperIdentity(args, reply)
754765
case "shh_hasIdentity":
755766
args := new(WhisperIdentityArgs)
756767
if err := json.Unmarshal(req.Params, &args); err != nil {

‎rpc/args.go‎

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -331,42 +331,6 @@ func (args *Sha3Args) UnmarshalJSON(b []byte) (err error) {
331331
return nil
332332
}
333333

334-
// type FilterArgs struct {
335-
// FromBlock uint64
336-
// ToBlock uint64
337-
// Limit uint64
338-
// Offset uint64
339-
// Address string
340-
// Topics []string
341-
// }
342-
343-
// func (args *FilterArgs) UnmarshalJSON(b []byte) (err error) {
344-
// var obj []struct {
345-
// FromBlock string `json:"fromBlock"`
346-
// ToBlock string `json:"toBlock"`
347-
// Limit string `json:"limit"`
348-
// Offset string `json:"offset"`
349-
// Address string `json:"address"`
350-
// Topics []string `json:"topics"`
351-
// }
352-
353-
// if err = json.Unmarshal(b, &obj); err != nil {
354-
// return errDecodeArgs
355-
// }
356-
357-
// if len(obj) < 1 {
358-
// return errArguments
359-
// }
360-
// args.FromBlock = uint64(common.Big(obj[0].FromBlock).Int64())
361-
// args.ToBlock = uint64(common.Big(obj[0].ToBlock).Int64())
362-
// args.Limit = uint64(common.Big(obj[0].Limit).Int64())
363-
// args.Offset = uint64(common.Big(obj[0].Offset).Int64())
364-
// args.Address = obj[0].Address
365-
// args.Topics = obj[0].Topics
366-
367-
// return nil
368-
// }
369-
370334
type FilterOptions struct {
371335
Earliest int64
372336
Latest int64
@@ -378,8 +342,8 @@ type FilterOptions struct {
378342

379343
func (args *FilterOptions) UnmarshalJSON(b []byte) (err error) {
380344
var obj []struct {
381-
FromBlock string `json:"fromBlock"`
382-
ToBlock string `json:"toBlock"`
345+
FromBlock interface{} `json:"fromBlock"`
346+
ToBlock interface{} `json:"toBlock"`
383347
Limit string `json:"limit"`
384348
Offset string `json:"offset"`
385349
Address string `json:"address"`
@@ -394,8 +358,32 @@ func (args *FilterOptions) UnmarshalJSON(b []byte) (err error) {
394358
return NewInsufficientParamsError(len(obj), 1)
395359
}
396360

397-
args.Earliest = int64(common.Big(obj[0].FromBlock).Int64())
398-
args.Latest = int64(common.Big(obj[0].ToBlock).Int64())
361+
fromstr, ok := obj[0].FromBlock.(string)
362+
if !ok {
363+
return NewDecodeParamError("FromBlock is not a string")
364+
}
365+
366+
switch fromstr {
367+
case "latest":
368+
args.Earliest = 0
369+
default:
370+
args.Earliest = int64(common.Big(obj[0].FromBlock.(string)).Int64())
371+
}
372+
373+
tostr, ok := obj[0].ToBlock.(string)
374+
if !ok {
375+
return NewDecodeParamError("ToBlock is not a string")
376+
}
377+
378+
switch tostr {
379+
case "latest":
380+
args.Latest = 0
381+
case "pending":
382+
args.Latest = -1
383+
default:
384+
args.Latest = int64(common.Big(obj[0].ToBlock.(string)).Int64())
385+
}
386+
399387
args.Max = int(common.Big(obj[0].Limit).Int64())
400388
args.Skip = int(common.Big(obj[0].Offset).Int64())
401389
args.Address = obj[0].Address

‎rpc/args_test.go‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ func TestGetBlockByHashArgs(t *testing.T) {
7474
}
7575
}
7676

77+
func TestGetBlockByHashEmpty(t *testing.T) {
78+
input := `[]`
79+
80+
args := new(GetBlockByHashArgs)
81+
err := json.Unmarshal([]byte(input), &args)
82+
if err == nil {
83+
t.Error("Expected error but didn't get one")
84+
}
85+
}
86+
7787
func TestGetBlockByNumberArgs(t *testing.T) {
7888
input := `["0x1b4", false]`
7989
expected := new(GetBlockByNumberArgs)
@@ -94,6 +104,16 @@ func TestGetBlockByNumberArgs(t *testing.T) {
94104
}
95105
}
96106

107+
func TestGetBlockByNumberEmpty(t *testing.T) {
108+
input := `[]`
109+
110+
args := new(GetBlockByNumberArgs)
111+
err := json.Unmarshal([]byte(input), &args)
112+
if err == nil {
113+
t.Error("Expected error but didn't get one")
114+
}
115+
}
116+
97117
func TestNewTxArgs(t *testing.T) {
98118
input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
99119
"to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
@@ -139,6 +159,16 @@ func TestNewTxArgs(t *testing.T) {
139159
}
140160
}
141161

162+
func TestNewTxArgsEmpty(t *testing.T) {
163+
input := `[]`
164+
165+
args := new(NewTxArgs)
166+
err := json.Unmarshal([]byte(input), &args)
167+
if err == nil {
168+
t.Error("Expected error but didn't get one")
169+
}
170+
}
171+
142172
func TestGetStorageArgs(t *testing.T) {
143173
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
144174
expected := new(GetStorageArgs)
@@ -163,6 +193,16 @@ func TestGetStorageArgs(t *testing.T) {
163193
}
164194
}
165195

196+
func TestGetStorageEmptyArgs(t *testing.T) {
197+
input := `[]`
198+
199+
args := new(GetStorageArgs)
200+
err := json.Unmarshal([]byte(input), &args)
201+
if err == nil {
202+
t.Error("Expected error but didn't get one")
203+
}
204+
}
205+
166206
func TestGetStorageAtArgs(t *testing.T) {
167207
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x0", "0x2"]`
168208
expected := new(GetStorageAtArgs)
@@ -192,6 +232,16 @@ func TestGetStorageAtArgs(t *testing.T) {
192232
}
193233
}
194234

235+
func TestGetStorageAtEmptyArgs(t *testing.T) {
236+
input := `[]`
237+
238+
args := new(GetStorageAtArgs)
239+
err := json.Unmarshal([]byte(input), &args)
240+
if err == nil {
241+
t.Error("Expected error but didn't get one")
242+
}
243+
}
244+
195245
func TestGetTxCountArgs(t *testing.T) {
196246
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
197247
expected := new(GetTxCountArgs)
@@ -216,6 +266,16 @@ func TestGetTxCountArgs(t *testing.T) {
216266
}
217267
}
218268

269+
func TestGetTxCountEmptyArgs(t *testing.T) {
270+
input := `[]`
271+
272+
args := new(GetTxCountArgs)
273+
err := json.Unmarshal([]byte(input), &args)
274+
if err == nil {
275+
t.Error("Expected error but didn't get one")
276+
}
277+
}
278+
219279
func TestGetDataArgs(t *testing.T) {
220280
input := `["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8", "latest"]`
221281
expected := new(GetDataArgs)
@@ -240,6 +300,16 @@ func TestGetDataArgs(t *testing.T) {
240300
}
241301
}
242302

303+
func TestGetDataEmptyArgs(t *testing.T) {
304+
input := `[]`
305+
306+
args := new(GetDataArgs)
307+
err := json.Unmarshal([]byte(input), &args)
308+
if err == nil {
309+
t.Error("Expected error but didn't get one")
310+
}
311+
}
312+
243313
func TestFilterOptions(t *testing.T) {
244314
input := `[{
245315
"fromBlock": "0x1",
@@ -286,6 +356,56 @@ func TestFilterOptions(t *testing.T) {
286356
// }
287357
}
288358

359+
func TestFilterOptionsWords(t *testing.T) {
360+
input := `[{
361+
"fromBlock": "latest",
362+
"toBlock": "pending"
363+
}]`
364+
expected := new(FilterOptions)
365+
expected.Earliest = 0
366+
expected.Latest = -1
367+
368+
args := new(FilterOptions)
369+
if err := json.Unmarshal([]byte(input), &args); err != nil {
370+
t.Error(err)
371+
}
372+
373+
if expected.Earliest != args.Earliest {
374+
t.Errorf("Earliest shoud be %#v but is %#v", expected.Earliest, args.Earliest)
375+
}
376+
377+
if expected.Latest != args.Latest {
378+
t.Errorf("Latest shoud be %#v but is %#v", expected.Latest, args.Latest)
379+
}
380+
}
381+
382+
func TestFilterOptionsNums(t *testing.T) {
383+
input := `[{
384+
"fromBlock": 2,
385+
"toBlock": 3
386+
}]`
387+
388+
args := new(FilterOptions)
389+
err := json.Unmarshal([]byte(input), &args)
390+
switch err.(type) {
391+
case *DecodeParamError:
392+
break
393+
default:
394+
t.Errorf("Should have *DecodeParamError but instead have %T", err)
395+
}
396+
397+
}
398+
399+
func TestFilterOptionsEmptyArgs(t *testing.T) {
400+
input := `[]`
401+
402+
args := new(FilterOptions)
403+
err := json.Unmarshal([]byte(input), &args)
404+
if err == nil {
405+
t.Error("Expected error but didn't get one")
406+
}
407+
}
408+
289409
func TestDbArgs(t *testing.T) {
290410
input := `["0x74657374","0x6b6579","0x6d79537472696e67"]`
291411
expected := new(DbArgs)

‎rpc/util.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ func UnmarshalRawMessages(b []byte, iface interface{}, number *int64) (err error
4545
return NewDecodeParamError(err.Error())
4646
}
4747

48+
// Hrm... Occurs when no params
49+
if len(data) == 0 {
50+
return NewDecodeParamError("No data")
51+
}
52+
4853
// Number index determines the index in the array for a possible block number
4954
numberIndex := 0
5055

‎whisper/whisper.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ func (self *Whisper) GetIdentity(key *ecdsa.PublicKey) *ecdsa.PrivateKey {
116116
return self.keys[string(crypto.FromECDSAPub(key))]
117117
}
118118

119+
// func (self *Whisper) RemoveIdentity(key *ecdsa.PublicKey) bool {
120+
// k := string(crypto.FromECDSAPub(key))
121+
// if _, ok := self.keys[k]; ok {
122+
// delete(self.keys, k)
123+
// return true
124+
// }
125+
// return false
126+
// }
127+
119128
func (self *Whisper) Watch(opts Filter) int {
120129
return self.filters.Install(filter.Generic{
121130
Str1: string(crypto.FromECDSAPub(opts.To)),

‎xeth/whisper.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"errors"
55
"time"
66

7-
"github.com/ethereum/go-ethereum/crypto"
87
"github.com/ethereum/go-ethereum/common"
8+
"github.com/ethereum/go-ethereum/crypto"
99
"github.com/ethereum/go-ethereum/logger"
1010
"github.com/ethereum/go-ethereum/whisper"
1111
)
@@ -63,6 +63,10 @@ func (self *Whisper) HasIdentity(key string) bool {
6363
return self.Whisper.HasIdentity(crypto.ToECDSAPub(common.FromHex(key)))
6464
}
6565

66+
// func (self *Whisper) RemoveIdentity(key string) bool {
67+
// return self.Whisper.RemoveIdentity(crypto.ToECDSAPub(common.FromHex(key)))
68+
// }
69+
6670
func (self *Whisper) Watch(opts *Options) int {
6771
filter := whisper.Filter{
6872
To: crypto.ToECDSAPub(common.FromHex(opts.To)),

0 commit comments

Comments
 (0)