aboutsummaryrefslogtreecommitdiffstats
path: root/core/gen_genesis_account.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/gen_genesis_account.go')
-rw-r--r--core/gen_genesis_account.go36
1 files changed, 26 insertions, 10 deletions
diff --git a/core/gen_genesis_account.go b/core/gen_genesis_account.go
index bc5fc936b..15c9565a2 100644
--- a/core/gen_genesis_account.go
+++ b/core/gen_genesis_account.go
@@ -12,27 +12,37 @@ import (
"github.com/ethereum/go-ethereum/common/math"
)
+var _ = (*genesisAccountMarshaling)(nil)
+
func (g GenesisAccount) MarshalJSON() ([]byte, error) {
type GenesisAccount struct {
- Code hexutil.Bytes `json:"code,omitempty"`
- Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
- Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
- Nonce math.HexOrDecimal64 `json:"nonce,omitempty"`
+ Code hexutil.Bytes `json:"code,omitempty"`
+ Storage map[storageJSON]storageJSON `json:"storage,omitempty"`
+ Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
+ Nonce math.HexOrDecimal64 `json:"nonce,omitempty"`
+ PrivateKey hexutil.Bytes `json:"secretKey,omitempty"`
}
var enc GenesisAccount
enc.Code = g.Code
- enc.Storage = g.Storage
+ if g.Storage != nil {
+ enc.Storage = make(map[storageJSON]storageJSON, len(g.Storage))
+ for k, v := range g.Storage {
+ enc.Storage[storageJSON(k)] = storageJSON(v)
+ }
+ }
enc.Balance = (*math.HexOrDecimal256)(g.Balance)
enc.Nonce = math.HexOrDecimal64(g.Nonce)
+ enc.PrivateKey = g.PrivateKey
return json.Marshal(&enc)
}
func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
type GenesisAccount struct {
- Code hexutil.Bytes `json:"code,omitempty"`
- Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
- Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
- Nonce *math.HexOrDecimal64 `json:"nonce,omitempty"`
+ Code hexutil.Bytes `json:"code,omitempty"`
+ Storage map[storageJSON]storageJSON `json:"storage,omitempty"`
+ Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
+ Nonce *math.HexOrDecimal64 `json:"nonce,omitempty"`
+ PrivateKey hexutil.Bytes `json:"secretKey,omitempty"`
}
var dec GenesisAccount
if err := json.Unmarshal(input, &dec); err != nil {
@@ -42,7 +52,10 @@ func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
g.Code = dec.Code
}
if dec.Storage != nil {
- g.Storage = dec.Storage
+ g.Storage = make(map[common.Hash]common.Hash, len(dec.Storage))
+ for k, v := range dec.Storage {
+ g.Storage[common.Hash(k)] = common.Hash(v)
+ }
}
if dec.Balance == nil {
return errors.New("missing required field 'balance' for GenesisAccount")
@@ -51,5 +64,8 @@ func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
if dec.Nonce != nil {
g.Nonce = uint64(*dec.Nonce)
}
+ if dec.PrivateKey != nil {
+ g.PrivateKey = dec.PrivateKey
+ }
return nil
}