mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
core: add 'codeFilePath' optional field to allow loading predefined account code from a file
This commit is contained in:
parent
a063fe9b2d
commit
471b46d8c0
1 changed files with 17 additions and 5 deletions
|
|
@ -5,6 +5,8 @@ package core
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
|
@ -39,6 +41,7 @@ func (g GenesisAccount) MarshalJSON() ([]byte, error) {
|
|||
func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
|
||||
type GenesisAccount struct {
|
||||
Code *hexutil.Bytes `json:"code,omitempty"`
|
||||
CodeFilePath *string `json:"codeFilePath,omitempty"`
|
||||
Storage map[storageJSON]storageJSON `json:"storage,omitempty"`
|
||||
Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
|
||||
Nonce *math.HexOrDecimal64 `json:"nonce,omitempty"`
|
||||
|
|
@ -50,6 +53,15 @@ func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
|
|||
}
|
||||
if dec.Code != nil {
|
||||
g.Code = *dec.Code
|
||||
} else if dec.CodeFilePath != nil {
|
||||
// Check that the file exists
|
||||
// create an io.Reader with the content of the file and get it as []byte
|
||||
code, err := ioutil.ReadFile(*dec.CodeFilePath)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Could not open file: %v", err))
|
||||
}
|
||||
|
||||
g.Code = code
|
||||
}
|
||||
if dec.Storage != nil {
|
||||
g.Storage = make(map[common.Hash]common.Hash, len(dec.Storage))
|
||||
|
|
|
|||
Loading…
Reference in a new issue