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
0fcc6065
Commit
0fcc6065
authored
Aug 14, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new filter from map
parent
07cfb7b6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
18 deletions
+65
-18
filter.go
ethchain/filter.go
+65
-18
No files found.
ethchain/filter.go
View file @
0fcc6065
...
...
@@ -24,6 +24,46 @@ func NewFilter(eth EthManager) *Filter {
return
&
Filter
{
eth
:
eth
}
}
func
NewFilterFromMap
(
object
map
[
string
]
interface
{},
eth
EthManager
)
*
Filter
{
filter
:=
NewFilter
(
eth
)
if
object
[
"earliest"
]
!=
nil
{
earliest
:=
object
[
"earliest"
]
if
e
,
ok
:=
earliest
.
(
string
);
ok
{
filter
.
SetEarliestBlock
(
ethutil
.
Hex2Bytes
(
e
))
}
else
{
filter
.
SetEarliestBlock
(
earliest
)
}
}
if
object
[
"latest"
]
!=
nil
{
latest
:=
object
[
"latest"
]
if
l
,
ok
:=
latest
.
(
string
);
ok
{
filter
.
SetLatestBlock
(
ethutil
.
Hex2Bytes
(
l
))
}
else
{
filter
.
SetLatestBlock
(
latest
)
}
}
if
object
[
"to"
]
!=
nil
{
filter
.
AddTo
(
ethutil
.
Hex2Bytes
(
object
[
"to"
]
.
(
string
)))
}
if
object
[
"from"
]
!=
nil
{
filter
.
AddFrom
(
ethutil
.
Hex2Bytes
(
object
[
"from"
]
.
(
string
)))
}
if
object
[
"max"
]
!=
nil
{
filter
.
SetMax
(
object
[
"max"
]
.
(
int
))
}
if
object
[
"skip"
]
!=
nil
{
filter
.
SetSkip
(
object
[
"skip"
]
.
(
int
))
}
return
filter
}
// Set the earliest and latest block for filtering.
// -1 = latest block (i.e., the current block)
// hash = particular hash from-to
...
...
@@ -109,30 +149,37 @@ func (self *Filter) Find() []*ethstate.Message {
break
}
includes
:=
func
(
addresses
[][]
byte
,
a
[]
byte
)
(
found
bool
)
{
for
_
,
addr
:=
range
addresses
{
if
bytes
.
Compare
(
addr
,
a
)
==
0
{
return
true
}
}
messages
=
append
(
messages
,
self
.
FilterMessages
(
msgs
)
...
)
}
return
}
// Filter the messages for interesting stuff
for
_
,
message
:=
range
msgs
{
if
len
(
self
.
to
)
>
0
&&
!
includes
(
self
.
to
,
message
.
To
)
{
continue
}
block
=
self
.
eth
.
BlockChain
()
.
GetBlock
(
block
.
PrevHash
)
}
if
len
(
self
.
from
)
>
0
&&
!
includes
(
self
.
from
,
message
.
From
)
{
continue
}
return
messages
}
messages
=
append
(
messages
,
message
)
func
(
self
*
Filter
)
FilterMessages
(
msgs
[]
*
ethstate
.
Message
)
[]
*
ethstate
.
Message
{
var
messages
[]
*
ethstate
.
Message
includes
:=
func
(
addresses
[][]
byte
,
a
[]
byte
)
(
found
bool
)
{
for
_
,
addr
:=
range
addresses
{
if
bytes
.
Compare
(
addr
,
a
)
==
0
{
return
true
}
}
block
=
self
.
eth
.
BlockChain
()
.
GetBlock
(
block
.
PrevHash
)
return
}
// Filter the messages for interesting stuff
for
_
,
message
:=
range
msgs
{
if
len
(
self
.
to
)
>
0
&&
!
includes
(
self
.
to
,
message
.
To
)
{
continue
}
if
len
(
self
.
from
)
>
0
&&
!
includes
(
self
.
from
,
message
.
From
)
{
continue
}
messages
=
append
(
messages
,
message
)
}
return
messages
...
...
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