aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/ethereum/main.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-11 08:08:42 +0800
committerobscuren <geffobscura@gmail.com>2015-03-11 08:08:42 +0800
commit7e0ccc9de53e788ddc1879248bceb33a9ccdbae0 (patch)
tree816ff2e06aaa78721a22eee7f2c8493fbf313fb4 /cmd/ethereum/main.go
parentce595b9266d658a5eae626d78aec7f47c04222ca (diff)
parenteba4f389a6c494bc3e15b3bbc6516b51a5e61236 (diff)
downloadgo-tangerine-7e0ccc9de53e788ddc1879248bceb33a9ccdbae0.tar.gz
go-tangerine-7e0ccc9de53e788ddc1879248bceb33a9ccdbae0.tar.zst
go-tangerine-7e0ccc9de53e788ddc1879248bceb33a9ccdbae0.zip
Merge branch 'develop' into rpcfrontier
Conflicts: rpc/api.go rpc/args.go
Diffstat (limited to 'cmd/ethereum/main.go')
-rw-r--r--cmd/ethereum/main.go141
1 files changed, 117 insertions, 24 deletions
diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go
index 12e205f37..c9f620142 100644
--- a/cmd/ethereum/main.go
+++ b/cmd/ethereum/main.go
@@ -21,19 +21,23 @@
package main
import (
+ "bufio"
"fmt"
"os"
"runtime"
"strconv"
+ "strings"
"time"
"github.com/codegangsta/cli"
+ "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
+ "github.com/peterh/liner"
)
const (
@@ -43,12 +47,10 @@ const (
var (
clilogger = logger.NewLogger("CLI")
- app = cli.NewApp()
+ app = utils.NewApp(Version, "the go-ethereum command line interface")
)
func init() {
- app.Version = Version
- app.Usage = "the go-ethereum command-line client"
app.Action = run
app.HideVersion = true // we have a command to print the version
app.Commands = []cli.Command{
@@ -61,6 +63,23 @@ The output of this command is supposed to be machine-readable.
`,
},
{
+ Action: accountList,
+ Name: "account",
+ Usage: "manage accounts",
+ Subcommands: []cli.Command{
+ {
+ Action: accountList,
+ Name: "list",
+ Usage: "print account addresses",
+ },
+ {
+ Action: accountCreate,
+ Name: "new",
+ Usage: "create a new account",
+ },
+ },
+ },
+ {
Action: dump,
Name: "dump",
Usage: `dump a specific block from storage`,
@@ -93,13 +112,10 @@ runtime will execute the file and exit.
Usage: `export blockchain into file`,
},
}
- app.Author = ""
- app.Email = ""
app.Flags = []cli.Flag{
+ utils.UnlockedAccountFlag,
utils.BootnodesFlag,
utils.DataDirFlag,
- utils.KeyRingFlag,
- utils.KeyStoreFlag,
utils.ListenPortFlag,
utils.LogFileFlag,
utils.LogFormatFlag,
@@ -140,38 +156,100 @@ func main() {
func run(ctx *cli.Context) {
fmt.Printf("Welcome to the FRONTIER\n")
utils.HandleInterrupt()
- eth := utils.GetEthereum(ClientIdentifier, Version, ctx)
+ eth, err := utils.GetEthereum(ClientIdentifier, Version, ctx)
+ if err == accounts.ErrNoKeys {
+ utils.Fatalf(`No accounts configured.
+Please run 'ethereum account new' to create a new account.`)
+ } else if err != nil {
+ utils.Fatalf("%v", err)
+ }
+
startEth(ctx, eth)
// this blocks the thread
eth.WaitForShutdown()
}
func runjs(ctx *cli.Context) {
- eth := utils.GetEthereum(ClientIdentifier, Version, ctx)
+ eth, err := utils.GetEthereum(ClientIdentifier, Version, ctx)
+ if err == accounts.ErrNoKeys {
+ utils.Fatalf(`No accounts configured.
+Please run 'ethereum account new' to create a new account.`)
+ } else if err != nil {
+ utils.Fatalf("%v", err)
+ }
+
startEth(ctx, eth)
+ repl := newJSRE(eth)
if len(ctx.Args()) == 0 {
- runREPL(eth)
- eth.Stop()
- eth.WaitForShutdown()
- } else if len(ctx.Args()) == 1 {
- execJsFile(eth, ctx.Args()[0])
+ repl.interactive()
} else {
- utils.Fatalf("This command can handle at most one argument.")
+ for _, file := range ctx.Args() {
+ repl.exec(file)
+ }
}
+ eth.Stop()
+ eth.WaitForShutdown()
}
func startEth(ctx *cli.Context, eth *eth.Ethereum) {
utils.StartEthereum(eth)
+
+ // Load startup keys. XXX we are going to need a different format
+ account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
+ if len(account) > 0 {
+ split := strings.Split(account, ":")
+ if len(split) != 2 {
+ utils.Fatalf("Illegal 'unlock' format (address:password)")
+ }
+ am := utils.GetAccountManager(ctx)
+ // Attempt to unlock the account
+ err := am.Unlock(ethutil.Hex2Bytes(split[0]), split[1])
+ if err != nil {
+ utils.Fatalf("Unlock account failed '%v'", err)
+ }
+ }
+ // Start auxiliary services if enabled.
if ctx.GlobalBool(utils.RPCEnabledFlag.Name) {
- addr := ctx.GlobalString(utils.RPCListenAddrFlag.Name)
- port := ctx.GlobalInt(utils.RPCPortFlag.Name)
- utils.StartRpc(eth, addr, port)
+ utils.StartRPC(eth, ctx)
}
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) {
eth.Miner().Start()
}
}
+func accountList(ctx *cli.Context) {
+ am := utils.GetAccountManager(ctx)
+ accts, err := am.Accounts()
+ if err != nil {
+ utils.Fatalf("Could not list accounts: %v", err)
+ }
+ for _, acct := range accts {
+ fmt.Printf("Address: %#x\n", acct)
+ }
+}
+
+func accountCreate(ctx *cli.Context) {
+ am := utils.GetAccountManager(ctx)
+ fmt.Println("The new account will be encrypted with a passphrase.")
+ fmt.Println("Please enter a passphrase now.")
+ auth, err := readPassword("Passphrase: ", true)
+ if err != nil {
+ utils.Fatalf("%v", err)
+ }
+ confirm, err := readPassword("Repeat Passphrase: ", false)
+ if err != nil {
+ utils.Fatalf("%v", err)
+ }
+ if auth != confirm {
+ utils.Fatalf("Passphrases did not match.")
+ }
+ acct, err := am.NewAccount(auth)
+ if err != nil {
+ utils.Fatalf("Could not create the account: %v", err)
+ }
+ fmt.Printf("Address: %#x\n", acct.Address)
+}
+
func importchain(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
utils.Fatalf("This command requires an argument.")
@@ -221,12 +299,6 @@ func dump(ctx *cli.Context) {
}
}
-// hashish returns true for strings that look like hashes.
-func hashish(x string) bool {
- _, err := strconv.Atoi(x)
- return err != nil
-}
-
func version(c *cli.Context) {
fmt.Printf(`%v
Version: %v
@@ -238,3 +310,24 @@ GOPATH=%s
GOROOT=%s
`, ClientIdentifier, Version, eth.ProtocolVersion, eth.NetworkId, runtime.Version(), runtime.GOOS, os.Getenv("GOPATH"), runtime.GOROOT())
}
+
+// hashish returns true for strings that look like hashes.
+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
+}