aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-31 21:53:17 +0800
committerobscuren <geffobscura@gmail.com>2015-06-04 04:39:17 +0800
commitb26f5e0bb7e8922c80bc3513d1ebce2c99a081f5 (patch)
tree941b22f81006fd88655fc3266debf9d2a556915d /core
parentfa4aefee44c5dd32fb7e0d02960c1550e9c8a330 (diff)
downloaddexon-b26f5e0bb7e8922c80bc3513d1ebce2c99a081f5.tar
dexon-b26f5e0bb7e8922c80bc3513d1ebce2c99a081f5.tar.gz
dexon-b26f5e0bb7e8922c80bc3513d1ebce2c99a081f5.tar.bz2
dexon-b26f5e0bb7e8922c80bc3513d1ebce2c99a081f5.tar.lz
dexon-b26f5e0bb7e8922c80bc3513d1ebce2c99a081f5.tar.xz
dexon-b26f5e0bb7e8922c80bc3513d1ebce2c99a081f5.tar.zst
dexon-b26f5e0bb7e8922c80bc3513d1ebce2c99a081f5.zip
types: block json unmarshal method added
Diffstat (limited to 'core')
-rw-r--r--core/genesis.go4
-rw-r--r--core/types/block.go24
2 files changed, 26 insertions, 2 deletions
diff --git a/core/genesis.go b/core/genesis.go
index e72834822..a9b7339f3 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -36,7 +36,7 @@ func GenesisBlock(db common.Database) *types.Block {
Balance string
Code string
}
- err := json.Unmarshal(GenesisData, &accounts)
+ err := json.Unmarshal(GenesisAccounts, &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 GenesisData = []byte(`{
+var GenesisAccounts = []byte(`{
"0000000000000000000000000000000000000001": {"balance": "1"},
"0000000000000000000000000000000000000002": {"balance": "1"},
"0000000000000000000000000000000000000003": {"balance": "1"},
diff --git a/core/types/block.go b/core/types/block.go
index c93452fa7..d7963981e 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -1,7 +1,9 @@
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)