mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-13 23:43:47 +00:00
Add ability to run using chain json file
This commit is contained in:
parent
e10b10a3dd
commit
1ef2726beb
1 changed files with 28 additions and 2 deletions
|
|
@ -1,6 +1,9 @@
|
||||||
package chains
|
package chains
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
)
|
)
|
||||||
|
|
@ -19,6 +22,29 @@ var chains = map[string]*Chain{
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetChain(name string) (*Chain, bool) {
|
func GetChain(name string) (*Chain, bool) {
|
||||||
chain, ok := chains[name]
|
chain, err := ImportFromFile(name)
|
||||||
return chain, ok
|
if err != nil {
|
||||||
|
chain, ok := chains[name]
|
||||||
|
return chain, ok
|
||||||
|
}
|
||||||
|
return chain, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func ImportFromFile(filename string) (*Chain, error) {
|
||||||
|
data, err := ioutil.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return importChain(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func importChain(content []byte) (*Chain, error) {
|
||||||
|
var chain *Chain
|
||||||
|
|
||||||
|
if err := json.Unmarshal(content, &chain); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return chain, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue