@ -188,15 +188,34 @@ nodes.
}
)
// makeAccountManager creates an account manager with backends
func makeAccountManager ( ctx * cli . Context ) * accounts . Manager {
cfg := loadBaseConfig ( ctx )
am := accounts . NewManager ( & accounts . Config { InsecureUnlockAllowed : cfg . Node . InsecureUnlockAllowed } )
keydir , isEphemeral , err := cfg . Node . GetKeyStoreDir ( )
if err != nil {
utils . Fatalf ( "Failed to get the keystore directory: %v" , err )
}
if isEphemeral {
utils . Fatalf ( "Can't use ephemeral directory as keystore path" )
}
if err := setAccountManagerBackends ( & cfg . Node , am , keydir ) ; err != nil {
utils . Fatalf ( "Failed to set account manager backends: %v" , err )
}
return am
}
func accountList ( ctx * cli . Context ) error {
stack , _ := makeConfigNode ( ctx )
am := makeAccountManager ( ctx )
var index int
for _ , wallet := range stack . AccountManager ( ) . Wallets ( ) {
for _ , wallet := range am . Wallets ( ) {
for _ , account := range wallet . Accounts ( ) {
fmt . Printf ( "Account #%d: {%x} %s\n" , index , account . Address , & account . URL )
index ++
}
}
return nil
}
@ -258,17 +277,13 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr
// accountCreate creates a new account into the keystore defined by the CLI flags.
func accountCreate ( ctx * cli . Context ) error {
cfg := gethConfig { Node : defaultNodeConfig ( ) }
// Load config file.
if file := ctx . String ( configFileFlag . Name ) ; file != "" {
if err := loadConfig ( file , & cfg ) ; err != nil {
utils . Fatalf ( "%v" , err )
}
}
utils . SetNodeConfig ( ctx , & cfg . Node )
keydir , err := cfg . Node . KeyDirConfig ( )
cfg := loadBaseConfig ( ctx )
keydir , isEphemeral , err := cfg . Node . GetKeyStoreDir ( )
if err != nil {
utils . Fatalf ( "Failed to read configuration: %v" , err )
utils . Fatalf ( "Failed to get the keystore directory: %v" , err )
}
if isEphemeral {
utils . Fatalf ( "Can't use ephemeral directory as keystore path" )
}
scryptN := keystore . StandardScryptN
scryptP := keystore . StandardScryptP
@ -300,8 +315,8 @@ func accountUpdate(ctx *cli.Context) error {
if ctx . Args ( ) . Len ( ) == 0 {
utils . Fatalf ( "No accounts specified to update" )
}
stack , _ := makeConfigNode ( ctx )
backends := stack . AccountManager ( ) . Backends ( keystore . KeyStoreType )
am := makeAccountManager ( ctx )
backends := am . Backends ( keystore . KeyStoreType )
if len ( backends ) == 0 {
utils . Fatalf ( "Keystore is not available" )
}
@ -327,14 +342,14 @@ func importWallet(ctx *cli.Context) error {
utils . Fatalf ( "Could not read wallet file: %v" , err )
}
stack , _ := makeConfigNode ( ctx )
passphrase := utils . GetPassPhraseWithList ( "" , false , 0 , utils . MakePasswordList ( ctx ) )
backends := stack . AccountManager ( ) . Backends ( keystore . KeyStoreType )
am := makeAccountManager ( ctx )
backends := am . Backends ( keystore . KeyStoreType )
if len ( backends ) == 0 {
utils . Fatalf ( "Keystore is not available" )
}
ks := backends [ 0 ] . ( * keystore . KeyStore )
passphrase := utils . GetPassPhraseWithList ( "" , false , 0 , utils . MakePasswordList ( ctx ) )
acct , err := ks . ImportPreSaleKey ( keyJSON , passphrase )
if err != nil {
utils . Fatalf ( "%v" , err )
@ -352,14 +367,14 @@ func accountImport(ctx *cli.Context) error {
if err != nil {
utils . Fatalf ( "Failed to load the private key: %v" , err )
}
stack , _ := makeConfigNode ( ctx )
passphrase := utils . GetPassPhraseWithList ( "Your new account is locked with a password. Please give a password. Do not forget this password." , true , 0 , utils . MakePasswordList ( ctx ) )
backends := stack . AccountManager ( ) . Backends ( keystore . KeyStoreType )
am := makeAccountManager ( ctx )
backends := am . Backends ( keystore . KeyStoreType )
if len ( backends ) == 0 {
utils . Fatalf ( "Keystore is not available" )
}
ks := backends [ 0 ] . ( * keystore . KeyStore )
passphrase := utils . GetPassPhraseWithList ( "Your new account is locked with a password. Please give a password. Do not forget this password." , true , 0 , utils . MakePasswordList ( ctx ) )
acct , err := ks . ImportECDSA ( key , passphrase )
if err != nil {
utils . Fatalf ( "Could not create the account: %v" , err )