mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
fix: import/export for bor
This commit is contained in:
parent
087c44d4bc
commit
6cb5e62868
2 changed files with 88 additions and 2 deletions
75
cmd/utils/bor_flags.go
Normal file
75
cmd/utils/bor_flags.go
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/node"
|
||||||
|
"gopkg.in/urfave/cli.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
//
|
||||||
|
// Bor Specific flags
|
||||||
|
//
|
||||||
|
|
||||||
|
// HeimdallURLFlag flag for heimdall url
|
||||||
|
HeimdallURLFlag = cli.StringFlag{
|
||||||
|
Name: "bor.heimdall",
|
||||||
|
Usage: "URL of Heimdall service",
|
||||||
|
Value: "http://localhost:1317",
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithoutHeimdallFlag no heimdall (for testing purpose)
|
||||||
|
WithoutHeimdallFlag = cli.BoolFlag{
|
||||||
|
Name: "bor.withoutheimdall",
|
||||||
|
Usage: "Run without Heimdall service (for testing purpose)",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func getGenesis(genesisPath string) (*core.Genesis, error) {
|
||||||
|
log.Info("Reading genesis at ", "file", genesisPath)
|
||||||
|
file, err := os.Open(genesisPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
genesis := new(core.Genesis)
|
||||||
|
if err := json.NewDecoder(file).Decode(genesis); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return genesis, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func createBorEthereum(ctx *cli.Context, cfg *eth.Config) *eth.Ethereum {
|
||||||
|
workspace, err := ioutil.TempDir("", "bor-command-node-")
|
||||||
|
if err != nil {
|
||||||
|
Fatalf("failed to create temporary keystore: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a networkless protocol stack and start an Ethereum service within
|
||||||
|
stack, err := node.New(&node.Config{DataDir: workspace, UseLightweightKDF: true, Name: "bor-command-node"})
|
||||||
|
if err != nil {
|
||||||
|
Fatalf("failed to create node: %v", err)
|
||||||
|
}
|
||||||
|
ethereum, err := eth.New(stack, cfg)
|
||||||
|
if err != nil {
|
||||||
|
Fatalf("failed to register Ethereum protocol: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the node and assemble the JavaScript console around it
|
||||||
|
if err = stack.Start(); err != nil {
|
||||||
|
Fatalf("failed to start test stack: %v", err)
|
||||||
|
}
|
||||||
|
_, err = stack.Attach()
|
||||||
|
if err != nil {
|
||||||
|
Fatalf("failed to attach to node: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ethereum
|
||||||
|
}
|
||||||
|
|
@ -1801,15 +1801,26 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis {
|
||||||
|
|
||||||
// MakeChain creates a chain manager from set command line flags.
|
// MakeChain creates a chain manager from set command line flags.
|
||||||
func MakeChain(ctx *cli.Context, stack *node.Node, readOnly bool) (chain *core.BlockChain, chainDb ethdb.Database) {
|
func MakeChain(ctx *cli.Context, stack *node.Node, readOnly bool) (chain *core.BlockChain, chainDb ethdb.Database) {
|
||||||
var err error
|
// expecting the last argument to be the genesis file
|
||||||
|
genesis, err := getGenesis(ctx.Args().Get(len(ctx.Args()) - 1))
|
||||||
|
if err != nil {
|
||||||
|
Fatalf("Valid genesis file is required as argument: {}", err)
|
||||||
|
}
|
||||||
|
|
||||||
chainDb = MakeChainDatabase(ctx, stack)
|
chainDb = MakeChainDatabase(ctx, stack)
|
||||||
config, _, err := core.SetupGenesisBlock(chainDb, MakeGenesis(ctx))
|
config, _, err := core.SetupGenesisBlock(chainDb, genesis)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("%v", err)
|
Fatalf("%v", err)
|
||||||
}
|
}
|
||||||
var engine consensus.Engine
|
var engine consensus.Engine
|
||||||
if config.Clique != nil {
|
if config.Clique != nil {
|
||||||
engine = clique.New(config.Clique, chainDb)
|
engine = clique.New(config.Clique, chainDb)
|
||||||
|
} else if config.Bor != nil {
|
||||||
|
engine = createBorEthereum(ctx, ð.Config{
|
||||||
|
Genesis: genesis,
|
||||||
|
HeimdallURL: ctx.GlobalString(HeimdallURLFlag.Name),
|
||||||
|
WithoutHeimdall: ctx.GlobalBool(WithoutHeimdallFlag.Name),
|
||||||
|
}).Engine()
|
||||||
} else {
|
} else {
|
||||||
engine = ethash.NewFaker()
|
engine = ethash.NewFaker()
|
||||||
if !ctx.GlobalBool(FakePoWFlag.Name) {
|
if !ctx.GlobalBool(FakePoWFlag.Name) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue