diff options
author | Felix Lange <fjl@twurst.com> | 2016-03-03 08:09:16 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-04-12 21:58:01 +0800 |
commit | 46e8940b19fee9bc21767a1341c382fd9c9d572a (patch) | |
tree | 384b700810910857cd40e099aba0d5a525eec066 /cmd | |
parent | 2dc20963e789c85bcc9170e15c0483e51ca42bfc (diff) | |
download | dexon-46e8940b19fee9bc21767a1341c382fd9c9d572a.tar dexon-46e8940b19fee9bc21767a1341c382fd9c9d572a.tar.gz dexon-46e8940b19fee9bc21767a1341c382fd9c9d572a.tar.bz2 dexon-46e8940b19fee9bc21767a1341c382fd9c9d572a.tar.lz dexon-46e8940b19fee9bc21767a1341c382fd9c9d572a.tar.xz dexon-46e8940b19fee9bc21767a1341c382fd9c9d572a.tar.zst dexon-46e8940b19fee9bc21767a1341c382fd9c9d572a.zip |
accounts: streamline API
- Manager.Accounts no longer returns an error.
- Manager methods take Account instead of common.Address.
- All uses of Account with unkeyed fields are converted.
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/geth/accountcmd.go | 11 | ||||
-rw-r--r-- | cmd/geth/js.go | 4 | ||||
-rw-r--r-- | cmd/geth/js_test.go | 13 | ||||
-rw-r--r-- | cmd/gethrpctest/main.go | 2 | ||||
-rw-r--r-- | cmd/utils/flags.go | 18 |
5 files changed, 15 insertions, 33 deletions
diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index ec6de886f..b4c37cb86 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -23,7 +23,6 @@ import ( "github.com/codegangsta/cli" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/cmd/utils" - "github.com/ethereum/go-ethereum/common" ) var ( @@ -166,17 +165,13 @@ nodes. func accountList(ctx *cli.Context) { accman := utils.MakeAccountManager(ctx) - accts, err := accman.Accounts() - if err != nil { - utils.Fatalf("Could not list accounts: %v", err) - } - for i, acct := range accts { + for i, acct := range accman.Accounts() { fmt.Printf("Account #%d: %x\n", i, acct) } } // tries unlocking the specified account a few times. -func unlockAccount(ctx *cli.Context, accman *accounts.Manager, address string, i int, passwords []string) (common.Address, string) { +func unlockAccount(ctx *cli.Context, accman *accounts.Manager, address string, i int, passwords []string) (accounts.Account, string) { account, err := utils.MakeAddress(accman, address) if err != nil { utils.Fatalf("Could not list accounts: %v", err) @@ -190,7 +185,7 @@ func unlockAccount(ctx *cli.Context, accman *accounts.Manager, address string, i } // All trials expended to unlock account, bail out utils.Fatalf("Failed to unlock account: %s", address) - return common.Address{}, "" + return accounts.Account{}, "" } // getPassPhrase retrieves the passwor associated with an account, either fetched diff --git a/cmd/geth/js.go b/cmd/geth/js.go index 5178465d1..d5518f94b 100644 --- a/cmd/geth/js.go +++ b/cmd/geth/js.go @@ -27,6 +27,7 @@ import ( "strings" "github.com/codegangsta/cli" + "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/registrar" @@ -281,7 +282,8 @@ func (self *jsre) UnlockAccount(addr []byte) bool { if err := self.stack.Service(ðereum); err != nil { return false } - if err := ethereum.AccountManager().Unlock(common.BytesToAddress(addr), pass); err != nil { + a := accounts.Account{Address: common.BytesToAddress(addr)} + if err := ethereum.AccountManager().Unlock(a, pass); err != nil { return false } else { fmt.Println("Account is now unlocked for this session.") diff --git a/cmd/geth/js_test.go b/cmd/geth/js_test.go index 77e40bb9a..baf572359 100644 --- a/cmd/geth/js_test.go +++ b/cmd/geth/js_test.go @@ -61,17 +61,6 @@ type testjethre struct { client *httpclient.HTTPClient } -func (self *testjethre) UnlockAccount(acc []byte) bool { - var ethereum *eth.Ethereum - self.stack.Service(ðereum) - - err := ethereum.AccountManager().Unlock(common.BytesToAddress(acc), "") - if err != nil { - panic("unable to unlock") - } - return true -} - // Temporary disabled while natspec hasn't been migrated //func (self *testjethre) ConfirmTransaction(tx string) bool { // var ethereum *eth.Ethereum @@ -122,7 +111,7 @@ func testREPL(t *testing.T, config func(*eth.Config)) (string, *testjethre, *nod if err != nil { t.Fatal(err) } - if err := accman.Unlock(a.Address, ""); err != nil { + if err := accman.Unlock(a, ""); err != nil { t.Fatal(err) } // Start the node and assemble the REPL tester diff --git a/cmd/gethrpctest/main.go b/cmd/gethrpctest/main.go index e203b75a1..b25166f4f 100644 --- a/cmd/gethrpctest/main.go +++ b/cmd/gethrpctest/main.go @@ -116,7 +116,7 @@ func MakeSystemNode(keydir string, privkey string, test *tests.BlockTest) (*node if err != nil { return nil, err } - if err := accman.Unlock(a.Address, ""); err != nil { + if err := accman.Unlock(a, ""); err != nil { return nil, err } } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c87c2f76e..da29ceb09 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -564,27 +564,23 @@ func MakeAccountManager(ctx *cli.Context) *accounts.Manager { // MakeAddress converts an account specified directly as a hex encoded string or // a key index in the key store to an internal account representation. -func MakeAddress(accman *accounts.Manager, account string) (a common.Address, err error) { +func MakeAddress(accman *accounts.Manager, account string) (accounts.Account, error) { // If the specified account is a valid address, return it if common.IsHexAddress(account) { - return common.HexToAddress(account), nil + return accounts.Account{Address: common.HexToAddress(account)}, nil } // Otherwise try to interpret the account as a keystore index index, err := strconv.Atoi(account) if err != nil { - return a, fmt.Errorf("invalid account address or index %q", account) + return accounts.Account{}, fmt.Errorf("invalid account address or index %q", account) } - hex, err := accman.AddressByIndex(index) - if err != nil { - return a, fmt.Errorf("can't get account #%d (%v)", index, err) - } - return common.HexToAddress(hex), nil + return accman.AccountByIndex(index) } // MakeEtherbase retrieves the etherbase either from the directly specified // command line flags or from the keystore if CLI indexed. func MakeEtherbase(accman *accounts.Manager, ctx *cli.Context) common.Address { - accounts, _ := accman.Accounts() + accounts := accman.Accounts() if !ctx.GlobalIsSet(EtherbaseFlag.Name) && len(accounts) == 0 { glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default") return common.Address{} @@ -594,11 +590,11 @@ func MakeEtherbase(accman *accounts.Manager, ctx *cli.Context) common.Address { return common.Address{} } // If the specified etherbase is a valid address, return it - addr, err := MakeAddress(accman, etherbase) + account, err := MakeAddress(accman, etherbase) if err != nil { Fatalf("Option %q: %v", EtherbaseFlag.Name, err) } - return addr + return account.Address } // MakeMinerExtra resolves extradata for the miner from the set command line flags |