aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/utils')
-rw-r--r--cmd/utils/cmd.go25
-rw-r--r--cmd/utils/flags.go39
2 files changed, 42 insertions, 22 deletions
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 983762db8..1fbd96dc8 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -21,8 +21,6 @@ import (
"bufio"
"fmt"
"io"
- "math"
- "math/big"
"os"
"os/signal"
"regexp"
@@ -34,7 +32,6 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
- "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/peterh/liner"
)
@@ -146,16 +143,6 @@ func StartEthereum(ethereum *eth.Ethereum) {
}()
}
-func InitOlympic() {
- params.DurationLimit = big.NewInt(8)
- params.GenesisGasLimit = big.NewInt(3141592)
- params.MinGasLimit = big.NewInt(125000)
- params.MaximumExtraDataSize = big.NewInt(1024)
- NetworkIdFlag.Value = 0
- core.BlockReward = big.NewInt(1.5e+18)
- core.ExpDiffPeriod = big.NewInt(math.MaxInt64)
-}
-
func FormatTransactionData(data string) []byte {
d := common.StringToByteFunc(data, func(s string) (ret []byte) {
slice := regexp.MustCompile("\\n|\\s").Split(s, 1000000000)
@@ -169,7 +156,7 @@ func FormatTransactionData(data string) []byte {
return d
}
-func ImportChain(chain *core.ChainManager, fn string) error {
+func ImportChain(chain *core.BlockChain, fn string) error {
// Watch for Ctrl-C while the import is running.
// If a signal is received, the import will stop at the next batch.
interrupt := make(chan os.Signal, 1)
@@ -244,7 +231,7 @@ func ImportChain(chain *core.ChainManager, fn string) error {
return nil
}
-func hasAllBlocks(chain *core.ChainManager, bs []*types.Block) bool {
+func hasAllBlocks(chain *core.BlockChain, bs []*types.Block) bool {
for _, b := range bs {
if !chain.HasBlock(b.Hash()) {
return false
@@ -253,21 +240,21 @@ func hasAllBlocks(chain *core.ChainManager, bs []*types.Block) bool {
return true
}
-func ExportChain(chainmgr *core.ChainManager, fn string) error {
+func ExportChain(blockchain *core.BlockChain, fn string) error {
glog.Infoln("Exporting blockchain to", fn)
fh, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
if err != nil {
return err
}
defer fh.Close()
- if err := chainmgr.Export(fh); err != nil {
+ if err := blockchain.Export(fh); err != nil {
return err
}
glog.Infoln("Exported blockchain to", fn)
return nil
}
-func ExportAppendChain(chainmgr *core.ChainManager, fn string, first uint64, last uint64) error {
+func ExportAppendChain(blockchain *core.BlockChain, fn string, first uint64, last uint64) error {
glog.Infoln("Exporting blockchain to", fn)
// TODO verify mode perms
fh, err := os.OpenFile(fn, os.O_CREATE|os.O_APPEND|os.O_WRONLY, os.ModePerm)
@@ -275,7 +262,7 @@ func ExportAppendChain(chainmgr *core.ChainManager, fn string, first uint64, las
return err
}
defer fh.Close()
- if err := chainmgr.ExportN(fh, first, last); err != nil {
+ if err := blockchain.ExportN(fh, first, last); err != nil {
return err
}
glog.Infoln("Exported blockchain to", fn)
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index a5395424a..ca9dd76fd 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -20,6 +20,7 @@ import (
"crypto/ecdsa"
"fmt"
"log"
+ "math"
"math/big"
"net"
"net/http"
@@ -42,6 +43,7 @@ import (
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p/nat"
+ "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc/api"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/comms"
@@ -125,6 +127,10 @@ var (
Name: "dev",
Usage: "Developer mode. This mode creates a private network and sets several debugging flags",
}
+ TestNetFlag = cli.BoolFlag{
+ Name: "testnet",
+ Usage: "Testnet mode. This enables your node to operate on the testnet",
+ }
IdentityFlag = cli.StringFlag{
Name: "identity",
Usage: "Custom node name",
@@ -458,6 +464,17 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name),
}
+ if ctx.GlobalBool(DevModeFlag.Name) && ctx.GlobalBool(TestNetFlag.Name) {
+ glog.Fatalf("%s and %s are mutually exclusive\n", DevModeFlag.Name, TestNetFlag.Name)
+ }
+
+ if ctx.GlobalBool(TestNetFlag.Name) {
+ // testnet is always stored in the testnet folder
+ cfg.DataDir += "/testnet"
+ cfg.NetworkId = 2
+ cfg.TestNet = true
+ }
+
if ctx.GlobalBool(DevModeFlag.Name) {
if !ctx.GlobalIsSet(VMDebugFlag.Name) {
cfg.VmDebug = true
@@ -494,6 +511,20 @@ func SetupLogger(ctx *cli.Context) {
glog.SetLogDir(ctx.GlobalString(LogFileFlag.Name))
}
+// SetupNetwork configures the system for either the main net or some test network.
+func SetupNetwork(ctx *cli.Context) {
+ switch {
+ case ctx.GlobalBool(OlympicFlag.Name):
+ params.DurationLimit = big.NewInt(8)
+ params.GenesisGasLimit = big.NewInt(3141592)
+ params.MinGasLimit = big.NewInt(125000)
+ params.MaximumExtraDataSize = big.NewInt(1024)
+ NetworkIdFlag.Value = 0
+ core.BlockReward = big.NewInt(1.5e+18)
+ core.ExpDiffPeriod = big.NewInt(math.MaxInt64)
+ }
+}
+
// SetupVM configured the VM package's global settings
func SetupVM(ctx *cli.Context) {
vm.EnableJit = ctx.GlobalBool(VMEnableJitFlag.Name)
@@ -514,7 +545,7 @@ func SetupEth(ctx *cli.Context) {
}
// MakeChain creates a chain manager from set command line flags.
-func MakeChain(ctx *cli.Context) (chain *core.ChainManager, chainDb ethdb.Database) {
+func MakeChain(ctx *cli.Context) (chain *core.BlockChain, chainDb ethdb.Database) {
datadir := MustDataDir(ctx)
cache := ctx.GlobalInt(CacheFlag.Name)
@@ -523,7 +554,6 @@ func MakeChain(ctx *cli.Context) (chain *core.ChainManager, chainDb ethdb.Databa
Fatalf("Could not open database: %v", err)
}
if ctx.GlobalBool(OlympicFlag.Name) {
- InitOlympic()
_, err := core.WriteTestNetGenesisBlock(chainDb, 42)
if err != nil {
glog.Fatalln(err)
@@ -533,7 +563,7 @@ func MakeChain(ctx *cli.Context) (chain *core.ChainManager, chainDb ethdb.Databa
eventMux := new(event.TypeMux)
pow := ethash.New()
//genesis := core.GenesisBlock(uint64(ctx.GlobalInt(GenesisNonceFlag.Name)), blockDB)
- chain, err = core.NewChainManager(chainDb, pow, eventMux)
+ chain, err = core.NewBlockChain(chainDb, pow, eventMux)
if err != nil {
Fatalf("Could not start chainmanager: %v", err)
}
@@ -546,6 +576,9 @@ func MakeChain(ctx *cli.Context) (chain *core.ChainManager, chainDb ethdb.Databa
// MakeChain creates an account manager from set command line flags.
func MakeAccountManager(ctx *cli.Context) *accounts.Manager {
dataDir := MustDataDir(ctx)
+ if ctx.GlobalBool(TestNetFlag.Name) {
+ dataDir += "/testnet"
+ }
ks := crypto.NewKeyStorePassphrase(filepath.Join(dataDir, "keystore"))
return accounts.NewManager(ks)
}