diff options
author | obscuren <geffobscura@gmail.com> | 2015-05-22 00:58:57 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-05-22 00:58:57 +0800 |
commit | 2c1c78a6d9e59de1d4cdeb32737d281814d690f7 (patch) | |
tree | 05471c7e1862733478b08e18bd7ed9419f7f7297 /cmd | |
parent | 915fc0e581c042a8d4896880d45e680003809254 (diff) | |
parent | 3ea9868b656077c38af5ea8590761c3218ce558e (diff) | |
download | dexon-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.tar dexon-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.tar.gz dexon-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.tar.bz2 dexon-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.tar.lz dexon-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.tar.xz dexon-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.tar.zst dexon-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.zip |
Merge branch 'release/0.9.23'
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/geth/admin.go | 63 | ||||
-rw-r--r-- | cmd/geth/info_test.json | 2 | ||||
-rw-r--r-- | cmd/geth/js.go | 3 | ||||
-rw-r--r-- | cmd/geth/js_test.go | 46 | ||||
-rw-r--r-- | cmd/geth/main.go | 94 | ||||
-rw-r--r-- | cmd/utils/cmd.go | 52 | ||||
-rw-r--r-- | cmd/utils/flags.go | 8 |
7 files changed, 197 insertions, 71 deletions
diff --git a/cmd/geth/admin.go b/cmd/geth/admin.go index ebdf3512a..4c8f110e4 100644 --- a/cmd/geth/admin.go +++ b/cmd/geth/admin.go @@ -8,6 +8,7 @@ import ( "strconv" "time" + "github.com/ethereum/ethash" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" @@ -35,6 +36,7 @@ func (js *jsre) adminBindings() { eth := ethO.Object() eth.Set("pendingTransactions", js.pendingTransactions) eth.Set("resend", js.resend) + eth.Set("sign", js.sign) js.re.Set("admin", struct{}{}) t, _ := js.re.Get("admin") @@ -72,6 +74,9 @@ func (js *jsre) adminBindings() { miner.Set("hashrate", js.hashrate) miner.Set("setExtra", js.setExtra) miner.Set("setGasPrice", js.setGasPrice) + miner.Set("startAutoDAG", js.startAutoDAG) + miner.Set("stopAutoDAG", js.stopAutoDAG) + miner.Set("makeDAG", js.makeDAG) admin.Set("debug", struct{}{}) t, _ = admin.Get("debug") @@ -177,6 +182,30 @@ func (js *jsre) resend(call otto.FunctionCall) otto.Value { return otto.FalseValue() } +func (js *jsre) sign(call otto.FunctionCall) otto.Value { + if len(call.ArgumentList) != 2 { + fmt.Println("requires 2 arguments: eth.sign(signer, data)") + return otto.UndefinedValue() + } + signer, err := call.Argument(0).ToString() + if err != nil { + fmt.Println(err) + return otto.UndefinedValue() + } + + data, err := call.Argument(1).ToString() + if err != nil { + fmt.Println(err) + return otto.UndefinedValue() + } + v, err := js.xeth.Sign(signer, data, false) + if err != nil { + fmt.Println(err) + return otto.UndefinedValue() + } + return js.re.ToVal(v) +} + func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value { block, err := js.getBlock(call) if err != nil { @@ -253,6 +282,30 @@ func (js *jsre) hashrate(otto.FunctionCall) otto.Value { return js.re.ToVal(js.ethereum.Miner().HashRate()) } +func (js *jsre) makeDAG(call otto.FunctionCall) otto.Value { + blockNumber, err := call.Argument(1).ToInteger() + if err != nil { + fmt.Println(err) + return otto.FalseValue() + } + + err = ethash.MakeDAG(uint64(blockNumber), "") + if err != nil { + return otto.FalseValue() + } + return otto.TrueValue() +} + +func (js *jsre) startAutoDAG(otto.FunctionCall) otto.Value { + js.ethereum.StartAutoDAG() + return otto.TrueValue() +} + +func (js *jsre) stopAutoDAG(otto.FunctionCall) otto.Value { + js.ethereum.StopAutoDAG() + return otto.TrueValue() +} + func (js *jsre) backtrace(call otto.FunctionCall) otto.Value { tracestr, err := call.Argument(0).ToString() if err != nil { @@ -291,6 +344,9 @@ func (js *jsre) startMining(call otto.FunctionCall) otto.Value { threads = int64(js.ethereum.MinerThreads) } + // switch on DAG autogeneration when miner starts + js.ethereum.StartAutoDAG() + err = js.ethereum.StartMining(int(threads)) if err != nil { fmt.Println(err) @@ -302,6 +358,7 @@ func (js *jsre) startMining(call otto.FunctionCall) otto.Value { func (js *jsre) stopMining(call otto.FunctionCall) otto.Value { js.ethereum.StopMining() + js.ethereum.StopAutoDAG() return otto.TrueValue() } @@ -383,7 +440,7 @@ func (js *jsre) unlock(call otto.FunctionCall) otto.Value { var passphrase string if arg.IsUndefined() { fmt.Println("Please enter a passphrase now.") - passphrase, err = readPassword("Passphrase: ", true) + passphrase, err = utils.PromptPassword("Passphrase: ", true) if err != nil { fmt.Println(err) return otto.FalseValue() @@ -410,12 +467,12 @@ func (js *jsre) newAccount(call otto.FunctionCall) otto.Value { if arg.IsUndefined() { fmt.Println("The new account will be encrypted with a passphrase.") fmt.Println("Please enter a passphrase now.") - auth, err := readPassword("Passphrase: ", true) + auth, err := utils.PromptPassword("Passphrase: ", true) if err != nil { fmt.Println(err) return otto.FalseValue() } - confirm, err := readPassword("Repeat Passphrase: ", false) + confirm, err := utils.PromptPassword("Repeat Passphrase: ", false) if err != nil { fmt.Println(err) return otto.FalseValue() diff --git a/cmd/geth/info_test.json b/cmd/geth/info_test.json index 1e0c271ac..63f2163a9 100644 --- a/cmd/geth/info_test.json +++ b/cmd/geth/info_test.json @@ -1 +1 @@ -{"code":"605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056","info":{"abiDefinition":[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}],"compilerVersion":"0.9.17","developerDoc":{"methods":{}},"language":"Solidity","languageVersion":"0","source":"contract test {\n /// @notice Will multiply `a` by 7.\n function multiply(uint a) returns(uint d) {\n return a * 7;\n }\n}\n","userDoc":{"methods":{"multiply(uint256)":{"notice":"Will multiply `a` by 7."}}}}}
\ No newline at end of file +{"code":"0x605880600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b603d6004803590602001506047565b8060005260206000f35b60006007820290506053565b91905056","info":{"abiDefinition":[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}],"compilerVersion":"0.9.23","developerDoc":{"methods":{}},"language":"Solidity","languageVersion":"0","source":"contract test {\n /// @notice Will multiply `a` by 7.\n function multiply(uint a) returns(uint d) {\n return a * 7;\n }\n}\n","userDoc":{"methods":{"multiply(uint256)":{"notice":"Will multiply `a` by 7."}}}}}
\ No newline at end of file diff --git a/cmd/geth/js.go b/cmd/geth/js.go index 4ddb3bd9c..f99051a1e 100644 --- a/cmd/geth/js.go +++ b/cmd/geth/js.go @@ -71,7 +71,7 @@ type jsre struct { prompter } -func newJSRE(ethereum *eth.Ethereum, libPath, solcPath, corsDomain string, interactive bool, f xeth.Frontend) *jsre { +func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, interactive bool, f xeth.Frontend) *jsre { js := &jsre{ethereum: ethereum, ps1: "> "} // set default cors domain used by startRpc from CLI flag js.corsDomain = corsDomain @@ -81,7 +81,6 @@ func newJSRE(ethereum *eth.Ethereum, libPath, solcPath, corsDomain string, inter js.xeth = xeth.New(ethereum, f) js.wait = js.xeth.UpdateState() // update state in separare forever blocks - js.xeth.SetSolc(solcPath) js.re = re.New(libPath) js.apiBindings(f) js.adminBindings() diff --git a/cmd/geth/js_test.go b/cmd/geth/js_test.go index e02e8f704..41e1034e9 100644 --- a/cmd/geth/js_test.go +++ b/cmd/geth/js_test.go @@ -24,7 +24,7 @@ import ( const ( testSolcPath = "" - solcVersion = "0.9.17" + solcVersion = "0.9.23" testKey = "e6fab74a43941f82d89cb7faa408e227cdad3153c4720e540e855c19b15e6674" testAddress = "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182" @@ -34,6 +34,7 @@ const ( ) var ( + versionRE = regexp.MustCompile(strconv.Quote(`"compilerVersion":"` + solcVersion + `"`)) testGenesis = `{"` + testAddress[2:] + `": {"balance": "` + testBalance + `"}}` ) @@ -75,6 +76,7 @@ func testJEthRE(t *testing.T) (string, *testjethre, *eth.Ethereum) { AccountManager: am, MaxPeers: 0, Name: "test", + SolcPath: testSolcPath, }) if err != nil { t.Fatal("%v", err) @@ -101,7 +103,7 @@ func testJEthRE(t *testing.T) (string, *testjethre, *eth.Ethereum) { t.Errorf("Error creating DocServer: %v", err) } tf := &testjethre{ds: ds, stateDb: ethereum.ChainManager().State().Copy()} - repl := newJSRE(ethereum, assetPath, testSolcPath, "", false, tf) + repl := newJSRE(ethereum, assetPath, "", false, tf) tf.jsre = repl return tmp, tf, ethereum } @@ -172,6 +174,8 @@ func TestBlockChain(t *testing.T) { tmpfile := filepath.Join(extmp, "export.chain") tmpfileq := strconv.Quote(tmpfile) + ethereum.ChainManager().Reset() + checkEvalJSON(t, repl, `admin.export(`+tmpfileq+`)`, `true`) if _, err := os.Stat(tmpfile); err != nil { t.Fatal(err) @@ -226,11 +230,11 @@ func TestSignature(t *testing.T) { defer ethereum.Stop() defer os.RemoveAll(tmp) - val, err := repl.re.Run(`eth.sign({from: "` + testAddress + `", data: "` + testHash + `"})`) + val, err := repl.re.Run(`eth.sign("` + testAddress + `", "` + testHash + `")`) // This is a very preliminary test, lacking actual signature verification if err != nil { - t.Errorf("Error runnig js: %v", err) + t.Errorf("Error running js: %v", err) return } output := val.String() @@ -244,7 +248,6 @@ func TestSignature(t *testing.T) { } func TestContract(t *testing.T) { - t.Skip() tmp, repl, ethereum := testJEthRE(t) if err := ethereum.Start(); err != nil { @@ -257,7 +260,9 @@ func TestContract(t *testing.T) { var txc uint64 coinbase := common.HexToAddress(testAddress) resolver.New(repl.xeth).CreateContracts(coinbase) + // time.Sleep(1000 * time.Millisecond) + // checkEvalJSON(t, repl, `eth.getBlock("pending", true).transactions.length`, `2`) source := `contract test {\n` + " /// @notice Will multiply `a` by 7." + `\n` + ` function multiply(uint a) returns(uint d) {\n` + @@ -277,10 +282,9 @@ func TestContract(t *testing.T) { // if solc is found with right version, test it, otherwise read from file sol, err := compiler.New("") if err != nil { - t.Logf("solc not found: skipping compiler test") + t.Logf("solc not found: mocking contract compilation step") } else if sol.Version() != solcVersion { - err = fmt.Errorf("solc wrong version found (%v, expect %v): skipping compiler test", sol.Version(), solcVersion) - t.Log(err) + t.Logf("WARNING: solc different version found (%v, test written for %v, may need to update)", sol.Version(), solcVersion) } if err != nil { @@ -293,10 +297,10 @@ func TestContract(t *testing.T) { t.Errorf("%v", err) } } else { - checkEvalJSON(t, repl, `contract = eth.compile.solidity(source)`, string(contractInfo)) + checkEvalJSON(t, repl, `contract = eth.compile.solidity(source).test`, string(contractInfo)) } - checkEvalJSON(t, repl, `contract.code`, `"605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056"`) + checkEvalJSON(t, repl, `contract.code`, `"0x605880600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b603d6004803590602001506047565b8060005260206000f35b60006007820290506053565b91905056"`) checkEvalJSON( t, repl, @@ -306,15 +310,16 @@ func TestContract(t *testing.T) { callSetup := `abiDef = JSON.parse('[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"type":"function"}]'); Multiply7 = eth.contract(abiDef); -multiply7 = new Multiply7(contractaddress); +multiply7 = Multiply7.at(contractaddress); ` - + // time.Sleep(1500 * time.Millisecond) _, err = repl.re.Run(callSetup) if err != nil { - t.Errorf("unexpected error registering, got %v", err) + t.Errorf("unexpected error setting up contract, got %v", err) } - // updatespec + // checkEvalJSON(t, repl, `eth.getBlock("pending", true).transactions.length`, `3`) + // why is this sometimes failing? // checkEvalJSON(t, repl, `multiply7.multiply.call(6)`, `42`) expNotice := "" @@ -322,20 +327,23 @@ multiply7 = new Multiply7(contractaddress); t.Errorf("incorrect confirmation message: expected %v, got %v", expNotice, repl.lastConfirm) } - // why 0? - checkEvalJSON(t, repl, `eth.getBlock("pending", true).transactions.length`, `0`) - txc, repl.xeth = repl.xeth.ApplyTestTxs(repl.stateDb, coinbase, txc) checkEvalJSON(t, repl, `admin.contractInfo.start()`, `true`) checkEvalJSON(t, repl, `multiply7.multiply.sendTransaction(6, { from: primary, gas: "1000000", gasPrice: "100000" })`, `undefined`) - expNotice = `About to submit transaction (no NatSpec info found for contract: content hash not found for '0x4a6c99e127191d2ee302e42182c338344b39a37a47cdbb17ab0f26b6802eb4d1'): {"params":[{"to":"0x5dcaace5982778b409c524873b319667eba5d074","data": "0xc6888fa10000000000000000000000000000000000000000000000000000000000000006"}]}` + expNotice = `About to submit transaction (no NatSpec info found for contract: content hash not found for '0x87e2802265838c7f14bb69eecd2112911af6767907a702eeaa445239fb20711b'): {"params":[{"to":"0x5dcaace5982778b409c524873b319667eba5d074","data": "0xc6888fa10000000000000000000000000000000000000000000000000000000000000006"}]}` if repl.lastConfirm != expNotice { t.Errorf("incorrect confirmation message: expected %v, got %v", expNotice, repl.lastConfirm) } + var contenthash = `"0x86d2b7cf1e72e9a7a3f8d96601f0151742a2f780f1526414304fbe413dc7f9bd"` + if sol != nil { + modContractInfo := versionRE.ReplaceAll(contractInfo, []byte(`"compilerVersion":"`+sol.Version()+`"`)) + _ = modContractInfo + // contenthash = crypto.Sha3(modContractInfo) + } checkEvalJSON(t, repl, `filename = "/tmp/info.json"`, `"/tmp/info.json"`) - checkEvalJSON(t, repl, `contenthash = admin.contractInfo.register(primary, contractaddress, contract, filename)`, `"0x0d067e2dd99a4d8f0c0279738b17130dd415a89f24a23f0e7cf68c546ae3089d"`) + checkEvalJSON(t, repl, `contenthash = admin.contractInfo.register(primary, contractaddress, contract, filename)`, contenthash) checkEvalJSON(t, repl, `admin.contractInfo.registerUrl(primary, contenthash, "file://"+filename)`, `true`) if err != nil { t.Errorf("unexpected error registering, got %v", err) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 3f3af2b64..513b405ff 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -21,7 +21,6 @@ package main import ( - "bufio" "fmt" "io" "io/ioutil" @@ -44,13 +43,12 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/mattn/go-colorable" "github.com/mattn/go-isatty" - "github.com/peterh/liner" ) import _ "net/http/pprof" const ( ClientIdentifier = "Geth" - Version = "0.9.22" + Version = "0.9.23" ) var ( @@ -101,7 +99,15 @@ The output of this command is supposed to be machine-readable. Usage: "import ethereum presale wallet", }, }, - }, + Description: ` + + get wallet import /path/to/my/presale.wallet + +will prompt for your password and imports your ether presale account. +It can be used non-interactively with the --password option taking a +passwordfile as argument containing the wallet password in plaintext. + +`}, { Action: accountList, Name: "account", @@ -111,7 +117,7 @@ The output of this command is supposed to be machine-readable. Manage accounts lets you create new accounts, list all existing accounts, import a private key into a new account. -'account help' shows a list of subcommands or help for one subcommand. +' help' shows a list of subcommands or help for one subcommand. It supports interactive mode, when you are prompted for password as well as non-interactive mode where passwords are supplied via a given password file. @@ -230,6 +236,11 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso Name: "upgradedb", Usage: "upgrade chainblock database", }, + { + Action: removeDb, + Name: "removedb", + Usage: "Remove blockchain and state databases", + }, } app.Flags = []cli.Flag{ utils.IdentityFlag, @@ -246,6 +257,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.GasPriceFlag, utils.MinerThreadsFlag, utils.MiningEnabledFlag, + utils.AutoDAGFlag, utils.NATFlag, utils.NatspecEnabledFlag, utils.NodeKeyFileFlag, @@ -323,7 +335,6 @@ func console(ctx *cli.Context) { repl := newJSRE( ethereum, ctx.String(utils.JSpathFlag.Name), - ctx.String(utils.SolcPathFlag.Name), ctx.GlobalString(utils.RPCCORSDomainFlag.Name), true, nil, @@ -345,7 +356,6 @@ func execJSFiles(ctx *cli.Context) { repl := newJSRE( ethereum, ctx.String(utils.JSpathFlag.Name), - ctx.String(utils.SolcPathFlag.Name), ctx.GlobalString(utils.RPCCORSDomainFlag.Name), false, nil, @@ -361,12 +371,20 @@ func execJSFiles(ctx *cli.Context) { func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (passphrase string) { var err error // Load startup keys. XXX we are going to need a different format - // Attempt to unlock the account - passphrase = getPassPhrase(ctx, "", false) + if len(account) == 0 { utils.Fatalf("Invalid account address '%s'", account) } - err = am.Unlock(common.HexToAddress(account), passphrase) + // Attempt to unlock the account 3 times + attempts := 3 + for tries := 0; tries < attempts; tries++ { + msg := fmt.Sprintf("Unlocking account %s...%s | Attempt %d/%d", account[:8], account[len(account)-6:], tries+1, attempts) + passphrase = getPassPhrase(ctx, msg, false) + err = am.Unlock(common.HexToAddress(account), passphrase) + if err == nil { + break + } + } if err != nil { utils.Fatalf("Unlock account failed '%v'", err) } @@ -381,15 +399,18 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) { am := eth.AccountManager() account := ctx.GlobalString(utils.UnlockedAccountFlag.Name) - if len(account) > 0 { - if account == "primary" { - primaryAcc, err := am.Primary() - if err != nil { - utils.Fatalf("no primary account: %v", err) + accounts := strings.Split(account, " ") + for _, account := range accounts { + if len(account) > 0 { + if account == "primary" { + primaryAcc, err := am.Primary() + if err != nil { + utils.Fatalf("no primary account: %v", err) + } + account = primaryAcc.Hex() } - account = primaryAcc.Hex() + unlockAccount(ctx, am, account) } - unlockAccount(ctx, am, account) } // Start auxiliary services if enabled. if ctx.GlobalBool(utils.RPCEnabledFlag.Name) { @@ -421,12 +442,12 @@ func getPassPhrase(ctx *cli.Context, desc string, confirmation bool) (passphrase passfile := ctx.GlobalString(utils.PasswordFileFlag.Name) if len(passfile) == 0 { fmt.Println(desc) - auth, err := readPassword("Passphrase: ", true) + auth, err := utils.PromptPassword("Passphrase: ", true) if err != nil { utils.Fatalf("%v", err) } if confirmation { - confirm, err := readPassword("Repeat Passphrase: ", false) + confirm, err := utils.PromptPassword("Repeat Passphrase: ", false) if err != nil { utils.Fatalf("%v", err) } @@ -543,6 +564,25 @@ func exportchain(ctx *cli.Context) { return } +func removeDb(ctx *cli.Context) { + confirm, err := utils.PromptConfirm("Remove local databases?") + if err != nil { + utils.Fatalf("%v", err) + } + + if confirm { + fmt.Println("Removing chain and state databases...") + start := time.Now() + + os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "blockchain")) + os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "state")) + + fmt.Printf("Removed in %v\n", time.Since(start)) + } else { + fmt.Println("Operation aborted") + } +} + func upgradeDb(ctx *cli.Context) { fmt.Println("Upgrade blockchain DB") @@ -574,6 +614,7 @@ func upgradeDb(ctx *cli.Context) { ethereum.ExtraDb().Close() os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "blockchain")) + os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "state")) ethereum, err = eth.New(cfg) if err != nil { @@ -665,18 +706,3 @@ func hashish(x string) bool { _, err := strconv.Atoi(x) return err != nil } - -func readPassword(prompt string, warnTerm bool) (string, error) { - if liner.TerminalSupported() { - lr := liner.NewLiner() - defer lr.Close() - return lr.PasswordPrompt(prompt) - } - if warnTerm { - fmt.Println("!! Unsupported terminal, password will be echoed.") - } - fmt.Print(prompt) - input, err := bufio.NewReader(os.Stdin).ReadString('\n') - fmt.Println() - return input, err -} diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index fb55a64af..39b4e46da 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -22,11 +22,13 @@ package utils import ( + "bufio" "fmt" "io" "os" "os/signal" "regexp" + "strings" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" @@ -35,6 +37,7 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/rlp" + "github.com/peterh/liner" ) var interruptCallbacks = []func(os.Signal){} @@ -71,18 +74,45 @@ func openLogFile(Datadir string, filename string) *os.File { return file } -func confirm(message string) bool { - fmt.Println(message, "Are you sure? (y/n)") - var r string - fmt.Scanln(&r) - for ; ; fmt.Scanln(&r) { - if r == "n" || r == "y" { - break - } else { - fmt.Printf("Yes or no? (%s)", r) - } +func PromptConfirm(prompt string) (bool, error) { + var ( + input string + err error + ) + prompt = prompt + " [y/N] " + + if liner.TerminalSupported() { + lr := liner.NewLiner() + defer lr.Close() + input, err = lr.Prompt(prompt) + } else { + fmt.Print(prompt) + input, err = bufio.NewReader(os.Stdin).ReadString('\n') + fmt.Println() + } + + if len(input) > 0 && strings.ToUpper(input[:1]) == "Y" { + return true, nil + } else { + return false, nil + } + + return false, err +} + +func PromptPassword(prompt string, warnTerm bool) (string, error) { + if liner.TerminalSupported() { + lr := liner.NewLiner() + defer lr.Close() + return lr.PasswordPrompt(prompt) + } + if warnTerm { + fmt.Println("!! Unsupported terminal, password will be echoed.") } - return r == "y" + fmt.Print(prompt) + input, err := bufio.NewReader(os.Stdin).ReadString('\n') + fmt.Println() + return input, err } func initDataDir(Datadir string) { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 6ec4fdc55..cb774aa5b 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -112,6 +112,10 @@ var ( Name: "mine", Usage: "Enable mining", } + AutoDAGFlag = cli.BoolFlag{ + Name: "autodag", + Usage: "Enable automatic DAG pregeneration", + } EtherbaseFlag = cli.StringFlag{ Name: "etherbase", Usage: "Public address for block mining rewards. By default the address of your primary account is used", @@ -313,6 +317,8 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config { Dial: true, BootNodes: ctx.GlobalString(BootnodesFlag.Name), GasPrice: common.String2Big(ctx.GlobalString(GasPriceFlag.Name)), + SolcPath: ctx.GlobalString(SolcPathFlag.Name), + AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name), } } @@ -336,8 +342,8 @@ func GetChain(ctx *cli.Context) (*core.ChainManager, common.Database, common.Dat } eventMux := new(event.TypeMux) - chainManager := core.NewChainManager(blockDb, stateDb, eventMux) pow := ethash.New() + chainManager := core.NewChainManager(blockDb, stateDb, pow, eventMux) txPool := core.NewTxPool(eventMux, chainManager.State, chainManager.GasLimit) blockProcessor := core.NewBlockProcessor(stateDb, extraDb, pow, txPool, chainManager, eventMux) chainManager.SetProcessor(blockProcessor) |