|
|
@ -277,7 +277,11 @@ func (s *PrivateAccountAPI) DeriveAccount(url string, path string, pin *bool) (a |
|
|
|
|
|
|
|
|
|
|
|
// NewAccount will create a new account and returns the address for the new account.
|
|
|
|
// NewAccount will create a new account and returns the address for the new account.
|
|
|
|
func (s *PrivateAccountAPI) NewAccount(password string) (common.Address, error) { |
|
|
|
func (s *PrivateAccountAPI) NewAccount(password string) (common.Address, error) { |
|
|
|
acc, err := fetchKeystore(s.am).NewAccount(password) |
|
|
|
ks, err := fetchKeystore(s.am) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return common.Address{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
acc, err := ks.NewAccount(password) |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
log.Info("Your new key was generated", "address", acc.Address) |
|
|
|
log.Info("Your new key was generated", "address", acc.Address) |
|
|
|
log.Warn("Please backup your key file!", "path", acc.URL.Path) |
|
|
|
log.Warn("Please backup your key file!", "path", acc.URL.Path) |
|
|
@ -288,8 +292,11 @@ func (s *PrivateAccountAPI) NewAccount(password string) (common.Address, error) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// fetchKeystore retrieves the encrypted keystore from the account manager.
|
|
|
|
// fetchKeystore retrieves the encrypted keystore from the account manager.
|
|
|
|
func fetchKeystore(am *accounts.Manager) *keystore.KeyStore { |
|
|
|
func fetchKeystore(am *accounts.Manager) (*keystore.KeyStore, error) { |
|
|
|
return am.Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) |
|
|
|
if ks := am.Backends(keystore.KeyStoreType); len(ks) > 0 { |
|
|
|
|
|
|
|
return ks[0].(*keystore.KeyStore), nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return nil, errors.New("local keystore not used") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ImportRawKey stores the given hex encoded ECDSA key into the key directory,
|
|
|
|
// ImportRawKey stores the given hex encoded ECDSA key into the key directory,
|
|
|
@ -299,7 +306,11 @@ func (s *PrivateAccountAPI) ImportRawKey(privkey string, password string) (commo |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return common.Address{}, err |
|
|
|
return common.Address{}, err |
|
|
|
} |
|
|
|
} |
|
|
|
acc, err := fetchKeystore(s.am).ImportECDSA(key, password) |
|
|
|
ks, err := fetchKeystore(s.am) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return common.Address{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
acc, err := ks.ImportECDSA(key, password) |
|
|
|
return acc.Address, err |
|
|
|
return acc.Address, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -323,7 +334,11 @@ func (s *PrivateAccountAPI) UnlockAccount(ctx context.Context, addr common.Addre |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
d = time.Duration(*duration) * time.Second |
|
|
|
d = time.Duration(*duration) * time.Second |
|
|
|
} |
|
|
|
} |
|
|
|
err := fetchKeystore(s.am).TimedUnlock(accounts.Account{Address: addr}, password, d) |
|
|
|
ks, err := fetchKeystore(s.am) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return false, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
err = ks.TimedUnlock(accounts.Account{Address: addr}, password, d) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Warn("Failed account unlock attempt", "address", addr, "err", err) |
|
|
|
log.Warn("Failed account unlock attempt", "address", addr, "err", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -332,7 +347,10 @@ func (s *PrivateAccountAPI) UnlockAccount(ctx context.Context, addr common.Addre |
|
|
|
|
|
|
|
|
|
|
|
// LockAccount will lock the account associated with the given address when it's unlocked.
|
|
|
|
// LockAccount will lock the account associated with the given address when it's unlocked.
|
|
|
|
func (s *PrivateAccountAPI) LockAccount(addr common.Address) bool { |
|
|
|
func (s *PrivateAccountAPI) LockAccount(addr common.Address) bool { |
|
|
|
return fetchKeystore(s.am).Lock(addr) == nil |
|
|
|
if ks, err := fetchKeystore(s.am); err == nil { |
|
|
|
|
|
|
|
return ks.Lock(addr) == nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// signTransaction sets defaults and signs the given transaction
|
|
|
|
// signTransaction sets defaults and signs the given transaction
|
|
|
|