Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
5757f547
Commit
5757f547
authored
Mar 16, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow latest/pending in filter options
parent
3cf51d54
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
40 deletions
+45
-40
args.go
rpc/args.go
+22
-40
args_test.go
rpc/args_test.go
+23
-0
No files found.
rpc/args.go
View file @
5757f547
...
...
@@ -331,42 +331,6 @@ func (args *Sha3Args) UnmarshalJSON(b []byte) (err error) {
return
nil
}
// type FilterArgs struct {
// FromBlock uint64
// ToBlock uint64
// Limit uint64
// Offset uint64
// Address string
// Topics []string
// }
// func (args *FilterArgs) UnmarshalJSON(b []byte) (err error) {
// var obj []struct {
// FromBlock string `json:"fromBlock"`
// ToBlock string `json:"toBlock"`
// Limit string `json:"limit"`
// Offset string `json:"offset"`
// Address string `json:"address"`
// Topics []string `json:"topics"`
// }
// if err = json.Unmarshal(b, &obj); err != nil {
// return errDecodeArgs
// }
// if len(obj) < 1 {
// return errArguments
// }
// args.FromBlock = uint64(common.Big(obj[0].FromBlock).Int64())
// args.ToBlock = uint64(common.Big(obj[0].ToBlock).Int64())
// args.Limit = uint64(common.Big(obj[0].Limit).Int64())
// args.Offset = uint64(common.Big(obj[0].Offset).Int64())
// args.Address = obj[0].Address
// args.Topics = obj[0].Topics
// return nil
// }
type
FilterOptions
struct
{
Earliest
int64
Latest
int64
...
...
@@ -378,8 +342,8 @@ type FilterOptions struct {
func
(
args
*
FilterOptions
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
struct
{
FromBlock
string
`json:"fromBlock"`
ToBlock
string
`json:"toBlock"`
FromBlock
interface
{}
`json:"fromBlock"`
ToBlock
interface
{}
`json:"toBlock"`
Limit
string
`json:"limit"`
Offset
string
`json:"offset"`
Address
string
`json:"address"`
...
...
@@ -394,8 +358,26 @@ func (args *FilterOptions) UnmarshalJSON(b []byte) (err error) {
return
NewInsufficientParamsError
(
len
(
obj
),
1
)
}
args
.
Earliest
=
int64
(
common
.
Big
(
obj
[
0
]
.
FromBlock
)
.
Int64
())
args
.
Latest
=
int64
(
common
.
Big
(
obj
[
0
]
.
ToBlock
)
.
Int64
())
fromstr
,
ok
:=
obj
[
0
]
.
FromBlock
.
(
string
)
if
ok
{
if
fromstr
==
"latest"
{
args
.
Earliest
=
0
}
else
{
args
.
Earliest
=
int64
(
common
.
Big
(
obj
[
0
]
.
FromBlock
.
(
string
))
.
Int64
())
}
}
tostr
,
ok
:=
obj
[
0
]
.
ToBlock
.
(
string
)
if
ok
{
if
tostr
==
"latest"
{
args
.
Latest
=
0
}
else
if
tostr
==
"pending"
{
args
.
Latest
=
-
1
}
else
{
args
.
Latest
=
int64
(
common
.
Big
(
obj
[
0
]
.
ToBlock
.
(
string
))
.
Int64
())
}
}
args
.
Max
=
int
(
common
.
Big
(
obj
[
0
]
.
Limit
)
.
Int64
())
args
.
Skip
=
int
(
common
.
Big
(
obj
[
0
]
.
Offset
)
.
Int64
())
args
.
Address
=
obj
[
0
]
.
Address
...
...
rpc/args_test.go
View file @
5757f547
...
...
@@ -286,6 +286,29 @@ func TestFilterOptions(t *testing.T) {
// }
}
func
TestFilterOptionsWords
(
t
*
testing
.
T
)
{
input
:=
`[{
"fromBlock": "latest",
"toBlock": "pending"
}]`
expected
:=
new
(
FilterOptions
)
expected
.
Earliest
=
0
expected
.
Latest
=
-
1
args
:=
new
(
FilterOptions
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
expected
.
Earliest
!=
args
.
Earliest
{
t
.
Errorf
(
"Earliest shoud be %#v but is %#v"
,
expected
.
Earliest
,
args
.
Earliest
)
}
if
expected
.
Latest
!=
args
.
Latest
{
t
.
Errorf
(
"Latest shoud be %#v but is %#v"
,
expected
.
Latest
,
args
.
Latest
)
}
}
func
TestDbArgs
(
t
*
testing
.
T
)
{
input
:=
`["0x74657374","0x6b6579","0x6d79537472696e67"]`
expected
:=
new
(
DbArgs
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment