diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-07 19:39:52 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-07 19:39:52 +0800 |
commit | a2810c06d7cfc64e1636fe4ecfd5e35cc52b0d2b (patch) | |
tree | f9219d79707ce4a65177c5292478f971faa1d7c9 /cmd/ethereum | |
parent | d66f93cecdbae6a88bfb710e0d95d62340bf2460 (diff) | |
download | go-tangerine-a2810c06d7cfc64e1636fe4ecfd5e35cc52b0d2b.tar.gz go-tangerine-a2810c06d7cfc64e1636fe4ecfd5e35cc52b0d2b.tar.zst go-tangerine-a2810c06d7cfc64e1636fe4ecfd5e35cc52b0d2b.zip |
cmd/ethereum: add account commands
Diffstat (limited to 'cmd/ethereum')
-rw-r--r-- | cmd/ethereum/main.go | 79 |
1 files changed, 71 insertions, 8 deletions
diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index 1133bd6f7..f12616e17 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -21,6 +21,7 @@ package main import ( + "bufio" "fmt" "os" "runtime" @@ -34,6 +35,7 @@ import ( "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/state" + "github.com/peterh/liner" ) const ( @@ -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,8 +112,6 @@ runtime will execute the file and exit. app.Flags = []cli.Flag{ utils.BootnodesFlag, utils.DataDirFlag, - utils.KeyRingFlag, - utils.KeyStoreFlag, utils.ListenPortFlag, utils.LogFileFlag, utils.LogFormatFlag, @@ -166,6 +183,37 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) { } } +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) + 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.") @@ -201,12 +249,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 %v PV=%d @@ -216,3 +258,24 @@ GOPATH=%s GOROOT=%s `, ClientIdentifier, Version, eth.ProtocolVersion, runtime.GOOS, runtime.Version(), 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 +} |