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
68119d09
Commit
68119d09
authored
Sep 26, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed messages to use proper numbers
parent
9ed8dc73
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
55 deletions
+54
-55
block_chain.go
ethchain/block_chain.go
+10
-0
filter.go
ethchain/filter.go
+40
-55
value.go
ethutil/value.go
+4
-0
No files found.
ethchain/block_chain.go
View file @
68119d09
...
...
@@ -236,6 +236,16 @@ func (self *BlockChain) GetBlockByNumber(num uint64) *Block {
return
block
}
func
(
self
*
BlockChain
)
GetBlockBack
(
num
uint64
)
*
Block
{
block
:=
self
.
CurrentBlock
for
;
num
!=
0
&&
block
!=
nil
;
num
--
{
block
=
self
.
GetBlock
(
block
.
PrevHash
)
}
return
block
}
func
(
bc
*
BlockChain
)
BlockInfoByHash
(
hash
[]
byte
)
BlockInfo
{
bi
:=
BlockInfo
{}
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
(
append
(
hash
,
[]
byte
(
"Info"
)
...
))
...
...
ethchain/filter.go
View file @
68119d09
...
...
@@ -3,6 +3,7 @@ package ethchain
import
(
"bytes"
"fmt"
"math"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
...
...
@@ -16,8 +17,8 @@ type data struct {
// Filtering interface
type
Filter
struct
{
eth
EthManager
earliest
[]
byte
latest
[]
byte
earliest
int64
latest
int64
skip
int
from
,
to
[][]
byte
max
int
...
...
@@ -38,37 +39,33 @@ 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
)
}
val
:=
ethutil
.
NewValue
(
object
[
"earliest"
])
filter
.
SetEarliestBlock
(
val
.
Int
())
}
if
object
[
"latest"
]
!=
nil
{
latest
:=
object
[
"latest"
]
if
l
,
ok
:=
latest
.
(
string
);
ok
{
filter
.
SetLatestBlock
(
ethutil
.
Hex2Bytes
(
l
))
}
else
{
filter
.
SetLatestBlock
(
latest
)
}
val
:=
ethutil
.
NewValue
(
object
[
"latest"
])
filter
.
SetLatestBlock
(
val
.
Int
())
}
if
object
[
"to"
]
!=
nil
{
filter
.
AddTo
(
ethutil
.
Hex2Bytes
(
object
[
"to"
]
.
(
string
)))
val
:=
ethutil
.
NewValue
(
object
[
"to"
])
filter
.
AddTo
(
ethutil
.
Hex2Bytes
(
val
.
Str
()))
}
if
object
[
"from"
]
!=
nil
{
filter
.
AddFrom
(
ethutil
.
Hex2Bytes
(
object
[
"from"
]
.
(
string
)))
val
:=
ethutil
.
NewValue
(
object
[
"from"
])
filter
.
AddFrom
(
ethutil
.
Hex2Bytes
(
val
.
Str
()))
}
if
object
[
"max"
]
!=
nil
{
filter
.
SetMax
(
object
[
"max"
]
.
(
int
))
val
:=
ethutil
.
NewValue
(
object
[
"max"
])
filter
.
SetMax
(
int
(
val
.
Uint
()))
}
if
object
[
"skip"
]
!=
nil
{
filter
.
SetSkip
(
object
[
"skip"
]
.
(
int
))
val
:=
ethutil
.
NewValue
(
object
[
"skip"
])
filter
.
SetSkip
(
int
(
val
.
Uint
()))
}
if
object
[
"altered"
]
!=
nil
{
...
...
@@ -85,30 +82,12 @@ func (self *Filter) AddAltered(id, address []byte) {
// Set the earliest and latest block for filtering.
// -1 = latest block (i.e., the current block)
// hash = particular hash from-to
func
(
self
*
Filter
)
SetEarliestBlock
(
earliest
interface
{})
{
e
:=
ethutil
.
NewValue
(
earliest
)
// Check for -1 (latest) otherwise assume bytes
if
e
.
Int
()
==
-
1
{
self
.
earliest
=
self
.
eth
.
BlockChain
()
.
CurrentBlock
.
Hash
()
}
else
if
e
.
Len
()
>
0
{
self
.
earliest
=
e
.
Bytes
()
}
else
{
panic
(
fmt
.
Sprintf
(
"earliest has to be either -1 or a valid hash: %v (%T)"
,
e
,
e
.
Val
))
}
func
(
self
*
Filter
)
SetEarliestBlock
(
earliest
int64
)
{
self
.
earliest
=
earliest
}
func
(
self
*
Filter
)
SetLatestBlock
(
latest
interface
{})
{
l
:=
ethutil
.
NewValue
(
latest
)
// Check for -1 (latest) otherwise assume bytes
if
l
.
Int
()
==
-
1
{
self
.
latest
=
self
.
eth
.
BlockChain
()
.
CurrentBlock
.
Hash
()
}
else
if
l
.
Len
()
>
0
{
self
.
latest
=
l
.
Bytes
()
}
else
{
panic
(
fmt
.
Sprintf
(
"latest has to be either -1 or a valid hash: %v"
,
l
))
}
func
(
self
*
Filter
)
SetLatestBlock
(
latest
int64
)
{
self
.
latest
=
latest
}
func
(
self
*
Filter
)
SetFrom
(
addr
[][]
byte
)
{
...
...
@@ -137,23 +116,27 @@ func (self *Filter) SetSkip(skip int) {
// Run filters messages with the current parameters set
func
(
self
*
Filter
)
Find
()
[]
*
ethstate
.
Message
{
var
messages
[]
*
ethstate
.
Message
block
:=
self
.
eth
.
BlockChain
()
.
GetBlock
(
self
.
latest
)
// skip N blocks (useful for pagination)
if
self
.
skip
>
0
{
for
i
:=
0
;
i
<
i
;
i
++
{
block
=
self
.
eth
.
BlockChain
()
.
GetBlock
(
block
.
PrevHash
)
}
var
earliestBlockNo
uint64
=
uint64
(
self
.
earliest
)
if
self
.
earliest
==
-
1
{
earliestBlockNo
=
self
.
eth
.
BlockChain
()
.
CurrentBlock
.
Number
.
Uint64
()
}
var
latestBlockNo
uint64
=
uint64
(
self
.
latest
)
if
self
.
latest
==
-
1
{
latestBlockNo
=
self
.
eth
.
BlockChain
()
.
CurrentBlock
.
Number
.
Uint64
()
}
// Start block filtering
quit
:=
false
for
i
:=
1
;
!
quit
&&
block
!=
nil
;
i
++
{
// Mark last check
if
self
.
max
==
i
||
(
len
(
self
.
earliest
)
>
0
&&
bytes
.
Compare
(
block
.
Hash
(),
self
.
earliest
)
==
0
)
{
var
(
messages
[]
*
ethstate
.
Message
block
=
self
.
eth
.
BlockChain
()
.
GetBlockByNumber
(
latestBlockNo
)
quit
bool
)
for
i
:=
0
;
!
quit
&&
block
!=
nil
;
i
++
{
// Quit on latest
switch
{
case
block
.
Number
.
Uint64
()
==
earliestBlockNo
:
quit
=
true
case
self
.
max
<=
len
(
messages
)
:
break
}
// Use bloom filtering to see if this block is interesting given the
...
...
@@ -173,7 +156,9 @@ func (self *Filter) Find() []*ethstate.Message {
block
=
self
.
eth
.
BlockChain
()
.
GetBlock
(
block
.
PrevHash
)
}
return
messages
skip
:=
int
(
math
.
Min
(
float64
(
len
(
messages
)),
float64
(
self
.
skip
)))
return
messages
[
skip
:
]
}
func
includes
(
addresses
[][]
byte
,
a
[]
byte
)
(
found
bool
)
{
...
...
ethutil/value.go
View file @
68119d09
...
...
@@ -63,6 +63,10 @@ func (val *Value) Uint() uint64 {
return
uint64
(
Val
)
}
else
if
Val
,
ok
:=
val
.
Val
.
(
uint64
);
ok
{
return
Val
}
else
if
Val
,
ok
:=
val
.
Val
.
(
float32
);
ok
{
return
uint64
(
Val
)
}
else
if
Val
,
ok
:=
val
.
Val
.
(
float64
);
ok
{
return
uint64
(
Val
)
}
else
if
Val
,
ok
:=
val
.
Val
.
(
int
);
ok
{
return
uint64
(
Val
)
}
else
if
Val
,
ok
:=
val
.
Val
.
(
uint
);
ok
{
...
...
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