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
13ade2ed
Commit
13ade2ed
authored
Mar 16, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'conversion' of
https://github.com/ethereum/go-ethereum
parents
64490897
bfcd2cf1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
75 additions
and
37 deletions
+75
-37
block.go
core/types/block.go
+31
-30
block_test.go
core/types/block_test.go
+19
-0
bloom9.go
core/types/bloom9.go
+3
-3
common.go
core/types/common.go
+19
-0
derive_sha.go
core/types/derive_sha.go
+3
-3
dump.go
state/dump.go
+0
-1
No files found.
core/types/block.go
View file @
13ade2ed
...
...
@@ -27,7 +27,7 @@ type Header struct {
// Receipt sha
ReceiptHash
common
.
Hash
// Bloom
Bloom
[
256
]
byte
Bloom
Bloom
// Difficulty for the current block
Difficulty
*
big
.
Int
// The block number
...
...
@@ -73,28 +73,30 @@ func (self *Header) RlpData() interface{} {
return
self
.
rlpData
(
true
)
}
func
(
self
*
Header
)
Hash
()
[]
byte
{
return
c
rypto
.
Sha3
(
common
.
Encode
(
self
.
rlpData
(
true
)))
func
(
self
*
Header
)
Hash
()
common
.
Hash
{
return
c
ommon
.
BytesToHash
(
crypto
.
Sha3
(
common
.
Encode
(
self
.
rlpData
(
true
)
)))
}
func
(
self
*
Header
)
HashNoNonce
()
[]
byte
{
return
c
rypto
.
Sha3
(
common
.
Encode
(
self
.
rlpData
(
false
)))
func
(
self
*
Header
)
HashNoNonce
()
common
.
Hash
{
return
c
ommon
.
BytesToHash
(
crypto
.
Sha3
(
common
.
Encode
(
self
.
rlpData
(
false
)
)))
}
type
Block
struct
{
// Preset Hash for mock
HeaderHash
[]
byte
ParentHeaderHash
[]
byte
header
*
Header
uncles
[]
*
Header
transactions
Transactions
Td
*
big
.
Int
// Preset Hash for mock (Tests)
HeaderHash
common
.
Hash
ParentHeaderHash
common
.
Hash
// ^^^^ ignore ^^^^
header
*
Header
uncles
[]
*
Header
transactions
Transactions
Td
*
big
.
Int
receipts
Receipts
Reward
*
big
.
Int
}
func
NewBlock
(
parentHash
[]
byte
,
coinbase
[]
byte
,
root
[]
byte
,
difficulty
*
big
.
Int
,
nonce
uint64
,
extra
string
)
*
Block
{
func
NewBlock
(
parentHash
common
.
Hash
,
coinbase
common
.
Address
,
root
common
.
Hash
,
difficulty
*
big
.
Int
,
nonce
uint64
,
extra
string
)
*
Block
{
header
:=
&
Header
{
Root
:
root
,
ParentHash
:
parentHash
,
...
...
@@ -113,8 +115,7 @@ func NewBlock(parentHash []byte, coinbase []byte, root []byte, difficulty *big.I
}
func
(
self
*
Header
)
setNonce
(
nonce
uint64
)
{
self
.
Nonce
=
make
([]
byte
,
8
)
binary
.
BigEndian
.
PutUint64
(
self
.
Nonce
,
nonce
)
binary
.
BigEndian
.
PutUint64
(
self
.
Nonce
[
:
],
nonce
)
}
func
NewBlockWithHeader
(
header
*
Header
)
*
Block
{
...
...
@@ -148,7 +149,7 @@ func (self *Block) Uncles() []*Header {
func
(
self
*
Block
)
SetUncles
(
uncleHeaders
[]
*
Header
)
{
self
.
uncles
=
uncleHeaders
self
.
header
.
UncleHash
=
c
rypto
.
Sha3
(
common
.
Encode
(
uncleHeaders
))
self
.
header
.
UncleHash
=
c
ommon
.
BytesToHash
(
crypto
.
Sha3
(
common
.
Encode
(
uncleHeaders
)
))
}
func
(
self
*
Block
)
Transactions
()
Transactions
{
...
...
@@ -196,23 +197,23 @@ func (self *Block) RlpDataForStorage() interface{} {
}
// Header accessors (add as you need them)
func
(
self
*
Block
)
Number
()
*
big
.
Int
{
return
self
.
header
.
Number
}
func
(
self
*
Block
)
NumberU64
()
uint64
{
return
self
.
header
.
Number
.
Uint64
()
}
func
(
self
*
Block
)
MixDigest
()
[]
byte
{
return
self
.
header
.
MixDigest
}
func
(
self
*
Block
)
Number
()
*
big
.
Int
{
return
self
.
header
.
Number
}
func
(
self
*
Block
)
NumberU64
()
uint64
{
return
self
.
header
.
Number
.
Uint64
()
}
func
(
self
*
Block
)
MixDigest
()
common
.
Hash
{
return
self
.
header
.
MixDigest
}
func
(
self
*
Block
)
Nonce
()
uint64
{
return
binary
.
BigEndian
.
Uint64
(
self
.
header
.
Nonce
)
return
binary
.
BigEndian
.
Uint64
(
self
.
header
.
Nonce
[
:
]
)
}
func
(
self
*
Block
)
SetNonce
(
nonce
uint64
)
{
self
.
header
.
setNonce
(
nonce
)
}
func
(
self
*
Block
)
Bloom
()
[]
byte
{
return
self
.
header
.
Bloom
}
func
(
self
*
Block
)
Coinbase
()
[]
byte
{
return
self
.
header
.
Coinbase
}
func
(
self
*
Block
)
Bloom
()
Bloom
{
return
self
.
header
.
Bloom
}
func
(
self
*
Block
)
Coinbase
()
common
.
Address
{
return
self
.
header
.
Coinbase
}
func
(
self
*
Block
)
Time
()
int64
{
return
int64
(
self
.
header
.
Time
)
}
func
(
self
*
Block
)
GasLimit
()
*
big
.
Int
{
return
self
.
header
.
GasLimit
}
func
(
self
*
Block
)
GasUsed
()
*
big
.
Int
{
return
self
.
header
.
GasUsed
}
func
(
self
*
Block
)
Root
()
[]
byte
{
return
self
.
header
.
Root
}
func
(
self
*
Block
)
SetRoot
(
root
[]
byte
)
{
self
.
header
.
Root
=
root
}
func
(
self
*
Block
)
Root
()
common
.
Hash
{
return
self
.
header
.
Root
}
func
(
self
*
Block
)
SetRoot
(
root
common
.
Hash
)
{
self
.
header
.
Root
=
root
}
func
(
self
*
Block
)
Size
()
common
.
StorageSize
{
return
common
.
StorageSize
(
len
(
common
.
Encode
(
self
)))
}
func
(
self
*
Block
)
GetTransaction
(
i
int
)
*
Transaction
{
if
len
(
self
.
transactions
)
>
i
{
...
...
@@ -228,19 +229,19 @@ func (self *Block) GetUncle(i int) *Header {
}
// Implement pow.Block
func
(
self
*
Block
)
Difficulty
()
*
big
.
Int
{
return
self
.
header
.
Difficulty
}
func
(
self
*
Block
)
HashNoNonce
()
[]
byte
{
return
self
.
header
.
HashNoNonce
()
}
func
(
self
*
Block
)
Difficulty
()
*
big
.
Int
{
return
self
.
header
.
Difficulty
}
func
(
self
*
Block
)
HashNoNonce
()
common
.
Hash
{
return
self
.
header
.
HashNoNonce
()
}
func
(
self
*
Block
)
Hash
()
[]
byte
{
if
self
.
HeaderHash
!=
nil
{
func
(
self
*
Block
)
Hash
()
common
.
Hash
{
if
(
self
.
HeaderHash
!=
common
.
Hash
{})
{
return
self
.
HeaderHash
}
else
{
return
self
.
header
.
Hash
()
}
}
func
(
self
*
Block
)
ParentHash
()
[]
byte
{
if
self
.
ParentHeaderHash
!=
nil
{
func
(
self
*
Block
)
ParentHash
()
common
.
Hash
{
if
(
self
.
ParentHeaderHash
!=
common
.
Hash
{})
{
return
self
.
ParentHeaderHash
}
else
{
return
self
.
header
.
ParentHash
...
...
core/types/block_test.go
View file @
13ade2ed
package
types
import
(
"fmt"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common"
)
func
TestConversion
(
t
*
testing
.
T
)
{
var
(
parent
common
.
Hash
coinbase
common
.
Address
hash
common
.
Hash
)
block
:=
NewBlock
(
parent
,
coinbase
,
hash
,
big
.
NewInt
(
0
),
0
,
""
)
fmt
.
Println
(
block
)
}
core/types/bloom9.go
View file @
13ade2ed
...
...
@@ -3,18 +3,18 @@ package types
import
(
"math/big"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/state"
)
func
CreateBloom
(
receipts
Receipts
)
[]
byte
{
func
CreateBloom
(
receipts
Receipts
)
Bloom
{
bin
:=
new
(
big
.
Int
)
for
_
,
receipt
:=
range
receipts
{
bin
.
Or
(
bin
,
LogsBloom
(
receipt
.
logs
))
}
return
common
.
LeftPadBytes
(
bin
.
Bytes
(),
256
)
return
BytesToBloom
(
bin
.
Bytes
()
)
}
func
LogsBloom
(
logs
state
.
Logs
)
*
big
.
Int
{
...
...
core/types/common.go
View file @
13ade2ed
...
...
@@ -5,3 +5,22 @@ import "math/big"
type
BlockProcessor
interface
{
Process
(
*
Block
)
(
*
big
.
Int
,
error
)
}
type
Bloom
[
256
]
byte
func
BytesToBloom
(
b
[]
byte
)
Bloom
{
var
bloom
Bloom
bloom
.
SetBytes
(
b
)
return
bloom
}
func
(
b
*
Bloom
)
SetBytes
(
d
[]
byte
)
{
if
len
(
b
)
>
len
(
d
)
{
panic
(
"bloom bytes too big"
)
}
// reverse loop
for
i
:=
len
(
d
)
-
1
;
i
>=
0
;
i
--
{
b
[
i
]
=
b
[
i
]
}
}
core/types/derive_sha.go
View file @
13ade2ed
package
types
import
(
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/trie"
)
...
...
@@ -11,12 +11,12 @@ type DerivableList interface {
GetRlp
(
i
int
)
[]
byte
}
func
DeriveSha
(
list
DerivableList
)
[]
byte
{
func
DeriveSha
(
list
DerivableList
)
common
.
Hash
{
db
,
_
:=
ethdb
.
NewMemDatabase
()
trie
:=
trie
.
New
(
nil
,
db
)
for
i
:=
0
;
i
<
list
.
Len
();
i
++
{
trie
.
Update
(
common
.
Encode
(
i
),
list
.
GetRlp
(
i
))
}
return
trie
.
Root
(
)
return
common
.
BytesToHash
(
trie
.
Root
()
)
}
state/dump.go
View file @
13ade2ed
...
...
@@ -28,7 +28,6 @@ func (self *StateDB) RawDump() World {
it
:=
self
.
trie
.
Iterator
()
for
it
.
Next
()
{
fmt
.
Printf
(
"%x
\n
"
,
it
.
Key
,
len
(
it
.
Key
))
stateObject
:=
NewStateObjectFromBytes
(
common
.
BytesToAddress
(
it
.
Key
),
it
.
Value
,
self
.
db
)
account
:=
Account
{
Balance
:
stateObject
.
balance
.
String
(),
Nonce
:
stateObject
.
nonce
,
Root
:
common
.
Bytes2Hex
(
stateObject
.
Root
()),
CodeHash
:
common
.
Bytes2Hex
(
stateObject
.
codeHash
)}
...
...
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