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
b26f5e0b
Commit
b26f5e0b
authored
May 31, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
types: block json unmarshal method added
parent
fa4aefee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
6 deletions
+30
-6
big.go
common/big.go
+4
-4
genesis.go
core/genesis.go
+2
-2
block.go
core/types/block.go
+24
-0
No files found.
common/big.go
View file @
b26f5e0b
...
...
@@ -36,16 +36,16 @@ func Big(num string) *big.Int {
return
n
}
// B
igD
// B
ytes2Big
//
// Shortcut for new(big.Int).SetBytes(...)
func
Bytes2Big
(
data
[]
byte
)
*
big
.
Int
{
func
BytesToBig
(
data
[]
byte
)
*
big
.
Int
{
n
:=
new
(
big
.
Int
)
n
.
SetBytes
(
data
)
return
n
}
func
BigD
(
data
[]
byte
)
*
big
.
Int
{
return
Bytes2Big
(
data
)
}
func
Bytes2Big
(
data
[]
byte
)
*
big
.
Int
{
return
BytesToBig
(
data
)
}
func
BigD
(
data
[]
byte
)
*
big
.
Int
{
return
BytesToBig
(
data
)
}
func
String2Big
(
num
string
)
*
big
.
Int
{
n
:=
new
(
big
.
Int
)
...
...
core/genesis.go
View file @
b26f5e0b
...
...
@@ -36,7 +36,7 @@ func GenesisBlock(db common.Database) *types.Block {
Balance
string
Code
string
}
err
:=
json
.
Unmarshal
(
Genesis
Data
,
&
accounts
)
err
:=
json
.
Unmarshal
(
Genesis
Accounts
,
&
accounts
)
if
err
!=
nil
{
fmt
.
Println
(
"enable to decode genesis json data:"
,
err
)
os
.
Exit
(
1
)
...
...
@@ -57,7 +57,7 @@ func GenesisBlock(db common.Database) *types.Block {
return
genesis
}
var
Genesis
Data
=
[]
byte
(
`{
var
Genesis
Accounts
=
[]
byte
(
`{
"0000000000000000000000000000000000000001": {"balance": "1"},
"0000000000000000000000000000000000000002": {"balance": "1"},
"0000000000000000000000000000000000000003": {"balance": "1"},
...
...
core/types/block.go
View file @
b26f5e0b
package
types
import
(
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"io"
"math/big"
...
...
@@ -80,6 +82,28 @@ func (self *Header) RlpData() interface{} {
return
self
.
rlpData
(
true
)
}
func
(
h
*
Header
)
UnmarshalJSON
(
data
[]
byte
)
error
{
var
ext
struct
{
ParentHash
string
Coinbase
string
Difficulty
string
GasLimit
string
Time
uint64
Extra
string
}
dec
:=
json
.
NewDecoder
(
bytes
.
NewReader
(
data
))
if
err
:=
dec
.
Decode
(
&
ext
);
err
!=
nil
{
return
err
}
h
.
ParentHash
=
common
.
HexToHash
(
ext
.
ParentHash
)
h
.
Coinbase
=
common
.
HexToAddress
(
ext
.
Coinbase
)
h
.
Difficulty
=
common
.
String2Big
(
ext
.
Difficulty
)
h
.
Time
=
ext
.
Time
h
.
Extra
=
[]
byte
(
ext
.
Extra
)
return
nil
}
func
rlpHash
(
x
interface
{})
(
h
common
.
Hash
)
{
hw
:=
sha3
.
NewKeccak256
()
rlp
.
Encode
(
hw
,
x
)
...
...
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