mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 07:36:44 +00:00
* Limit state sync by gas * Added logging for state-sync total gas usage * Added number of event-records in log * Minor Changes * Minor Fix * Adding individual gasUsed * Minor Fix * it works * fix tests * log wiggle and delay with block number * log delays as numbers * linters * fix tests * restore linters for the project * fix linters * fix * fix * fix * linters * generation * fix tests * remove heimdall wrapper response * linters * remove possible collisions * remove possible collisions * remove possible collisions * tests for unique address generation * generalize set * bor miner tests got restored * fixes after CR * final step and mining test * fix * fix e2e * more tests for Heimdall requests * fix linters Co-authored-by: Ferran <ferranbt@protonmail.com> Co-authored-by: Shivam Sharma <shivam691999@gmail.com>
85 lines
1.6 KiB
Go
85 lines
1.6 KiB
Go
package chains
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/core"
|
|
"github.com/ethereum/go-ethereum/log"
|
|
)
|
|
|
|
type Chain struct {
|
|
Hash common.Hash
|
|
Genesis *core.Genesis
|
|
Bootnodes []string
|
|
NetworkId uint64
|
|
DNS []string
|
|
}
|
|
|
|
var chains = map[string]*Chain{
|
|
"mainnet": mainnetBor,
|
|
"mumbai": mumbaiTestnet,
|
|
}
|
|
|
|
func GetChain(name string) (*Chain, error) {
|
|
var (
|
|
chain *Chain
|
|
err error
|
|
)
|
|
|
|
if _, fileErr := os.Stat(name); fileErr == nil {
|
|
if chain, err = ImportFromFile(name); err != nil {
|
|
return nil, fmt.Errorf("error importing chain from file: %v", err)
|
|
}
|
|
|
|
return chain, nil
|
|
} else if errors.Is(fileErr, os.ErrNotExist) {
|
|
var ok bool
|
|
if chain, ok = chains[name]; !ok {
|
|
return nil, fmt.Errorf("chain %s not found", name)
|
|
}
|
|
|
|
return chain, nil
|
|
} else {
|
|
return nil, fileErr
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|