diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-07 19:38:33 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-07 19:38:33 +0800 |
commit | d66f93cecdbae6a88bfb710e0d95d62340bf2460 (patch) | |
tree | 8e270614345c87d3ea724387ba3baf2acdfa8972 /accounts | |
parent | bc45e5c6de3052a4c853387dea0af5cd9207f1f7 (diff) | |
download | go-tangerine-d66f93cecdbae6a88bfb710e0d95d62340bf2460.tar.gz go-tangerine-d66f93cecdbae6a88bfb710e0d95d62340bf2460.tar.zst go-tangerine-d66f93cecdbae6a88bfb710e0d95d62340bf2460.zip |
accounts, core, eth, xeth: use account manager for everything
The account manager is now responsible for picking the
default account and the coinbase.
Diffstat (limited to 'accounts')
-rw-r--r-- | accounts/account_manager.go | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go index 3e9fa7799..3b7785231 100644 --- a/accounts/account_manager.go +++ b/accounts/account_manager.go @@ -42,7 +42,10 @@ import ( "github.com/ethereum/go-ethereum/crypto" ) -var ErrLocked = errors.New("account is locked; please request passphrase") +var ( + ErrLocked = errors.New("account is locked") + ErrNoKeys = errors.New("no keys in store") +) // TODO: better name for this struct? type Account struct { @@ -56,17 +59,39 @@ type AccountManager struct { mutex sync.RWMutex } -func NewAccountManager(keyStore crypto.KeyStore2, unlockMilliseconds time.Duration) AccountManager { - keysMap := make(map[string]crypto.Key) - am := &AccountManager{ +func NewAccountManager(keyStore crypto.KeyStore2, unlockMilliseconds time.Duration) *AccountManager { + return &AccountManager{ keyStore: keyStore, - unlockedKeys: keysMap, + unlockedKeys: make(map[string]crypto.Key), unlockMilliseconds: unlockMilliseconds, } - return *am } -func (am AccountManager) DeleteAccount(address []byte, auth string) error { +// Coinbase returns the account address that mining rewards are sent to. +func (am *AccountManager) Coinbase() (addr []byte, err error) { + // TODO: persist coinbase address on disk + return am.firstAddr() +} + +// MainAccount returns the primary account used for transactions. +func (am *AccountManager) Default() (*Account, error) { + // TODO: persist main account address on disk + addr, err := am.firstAddr() + return &Account{Address: addr}, err +} + +func (am *AccountManager) firstAddr() ([]byte, error) { + addrs, err := am.keyStore.GetKeyAddresses() + if err != nil { + return nil, err + } + if len(addrs) == 0 { + return nil, ErrNoKeys + } + return addrs[0], nil +} + +func (am *AccountManager) DeleteAccount(address []byte, auth string) error { return am.keyStore.DeleteKey(address, auth) } |