mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 22:56:43 +00:00
Add ability to parse legacy genesis file
This commit is contained in:
parent
3ae87c0d46
commit
4cec5f01c3
4 changed files with 109 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
)
|
||||
|
||||
type Chain struct {
|
||||
|
|
@ -59,5 +60,19 @@ func importChain(content []byte) (*Chain, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if chain.Genesis == nil {
|
||||
log.Info("Try reading as legacy genesis")
|
||||
var genesis core.Genesis
|
||||
if err := json.Unmarshal(content, &genesis); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if genesis.Config != nil {
|
||||
chain.Genesis = &genesis
|
||||
chain.NetworkId = genesis.Config.ChainID.Uint64()
|
||||
} else {
|
||||
return nil, fmt.Errorf("unable to parse chain config")
|
||||
}
|
||||
}
|
||||
|
||||
return chain, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,16 @@ func TestChain_ImportFromFile(t *testing.T) {
|
|||
args: args{filename: "test_files/chain_test.json"},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ImportFromFile correct legacy json file",
|
||||
args: args{filename: "test_files/chain_legacy_test.json"},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ImportFromFile wrong json file",
|
||||
args: args{filename: "test_files/wrong_chain.json"},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "ImportFromFile nonexistent json file",
|
||||
args: args{filename: "test_files/chain_test_nonexistent.json"},
|
||||
|
|
|
|||
83
internal/cli/server/chains/test_files/chain_legacy_test.json
Normal file
83
internal/cli/server/chains/test_files/chain_legacy_test.json
Normal file
File diff suppressed because one or more lines are too long
1
internal/cli/server/chains/test_files/wrong_chain.json
Normal file
1
internal/cli/server/chains/test_files/wrong_chain.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
Loading…
Reference in a new issue