aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/account_manager.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-07-03 11:56:20 +0800
committerzelig <viktor.tron@gmail.com>2015-07-03 14:52:37 +0800
commit1959346793bdee469f68841843dd383cf801aba1 (patch)
tree12d53e0974ae96fdc27f8ed0e217565c5530b143 /accounts/account_manager.go
parentfc17a527bc2bd07fc30e16d161059a441042d5f1 (diff)
downloadgo-tangerine-1959346793bdee469f68841843dd383cf801aba1.tar.gz
go-tangerine-1959346793bdee469f68841843dd383cf801aba1.tar.zst
go-tangerine-1959346793bdee469f68841843dd383cf801aba1.zip
account update: migrate or change password
* account.Update * KeyStore.Cleanup * fix dir rm for old format deleteKey
Diffstat (limited to 'accounts/account_manager.go')
-rw-r--r--accounts/account_manager.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go
index eb2672a7d..17b128e9e 100644
--- a/accounts/account_manager.go
+++ b/accounts/account_manager.go
@@ -36,6 +36,7 @@ import (
"crypto/ecdsa"
crand "crypto/rand"
"errors"
+ "fmt"
"os"
"sync"
"time"
@@ -158,6 +159,20 @@ func (am *Manager) NewAccount(auth string) (Account, error) {
return Account{Address: key.Address}, nil
}
+func (am *Manager) AddressByIndex(index int) (addr string, err error) {
+ var addrs []common.Address
+ addrs, err = am.keyStore.GetKeyAddresses()
+ if err != nil {
+ return
+ }
+ if index < 0 || index >= len(addrs) {
+ err = fmt.Errorf("index out of range: %d (should be 0-%d)", index, len(addrs)-1)
+ } else {
+ addr = addrs[index].Hex()
+ }
+ return
+}
+
func (am *Manager) Accounts() ([]Account, error) {
addresses, err := am.keyStore.GetKeyAddresses()
if os.IsNotExist(err) {
@@ -204,6 +219,19 @@ func (am *Manager) Import(path string, keyAuth string) (Account, error) {
return Account{Address: key.Address}, nil
}
+func (am *Manager) Update(addr common.Address, authFrom, authTo string) (err error) {
+ var key *crypto.Key
+ key, err = am.keyStore.GetKey(addr, authFrom)
+
+ if err == nil {
+ err = am.keyStore.StoreKey(key, authTo)
+ if err == nil {
+ am.keyStore.Cleanup(addr)
+ }
+ }
+ return
+}
+
func (am *Manager) ImportPreSaleKey(keyJSON []byte, password string) (acc Account, err error) {
var key *crypto.Key
key, err = crypto.ImportPreSaleKey(am.keyStore, keyJSON, password)