aboutsummaryrefslogtreecommitdiffstats
path: root/accounts
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-08 07:18:13 +0800
committerFelix Lange <fjl@twurst.com>2015-03-08 07:18:13 +0800
commitfda7b4c79d070f1cb4f5d7ef5b4d077d9dcf2774 (patch)
treea553908665c48fca0263f4c8c1b3ef8d3ed7e071 /accounts
parenta2810c06d7cfc64e1636fe4ecfd5e35cc52b0d2b (diff)
downloaddexon-fda7b4c79d070f1cb4f5d7ef5b4d077d9dcf2774.tar
dexon-fda7b4c79d070f1cb4f5d7ef5b4d077d9dcf2774.tar.gz
dexon-fda7b4c79d070f1cb4f5d7ef5b4d077d9dcf2774.tar.bz2
dexon-fda7b4c79d070f1cb4f5d7ef5b4d077d9dcf2774.tar.lz
dexon-fda7b4c79d070f1cb4f5d7ef5b4d077d9dcf2774.tar.xz
dexon-fda7b4c79d070f1cb4f5d7ef5b4d077d9dcf2774.tar.zst
dexon-fda7b4c79d070f1cb4f5d7ef5b4d077d9dcf2774.zip
accounts: use pointers consistently
Account is now always a non-pointer. This will be important once the manager starts remembering accounts. AccountManager is now always a pointer because it contains locks and locks cannot be copied.
Diffstat (limited to 'accounts')
-rw-r--r--accounts/account_manager.go26
-rw-r--r--accounts/accounts_test.go3
2 files changed, 13 insertions, 16 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go
index 3b7785231..86f9c5916 100644
--- a/accounts/account_manager.go
+++ b/accounts/account_manager.go
@@ -47,7 +47,6 @@ var (
ErrNoKeys = errors.New("no keys in store")
)
-// TODO: better name for this struct?
type Account struct {
Address []byte
}
@@ -74,10 +73,10 @@ func (am *AccountManager) Coinbase() (addr []byte, err error) {
}
// MainAccount returns the primary account used for transactions.
-func (am *AccountManager) Default() (*Account, error) {
+func (am *AccountManager) Default() (Account, error) {
// TODO: persist main account address on disk
addr, err := am.firstAddr()
- return &Account{Address: addr}, err
+ return Account{Address: addr}, err
}
func (am *AccountManager) firstAddr() ([]byte, error) {
@@ -95,9 +94,9 @@ func (am *AccountManager) DeleteAccount(address []byte, auth string) error {
return am.keyStore.DeleteKey(address, auth)
}
-func (am *AccountManager) Sign(fromAccount *Account, toSign []byte) (signature []byte, err error) {
+func (am *AccountManager) Sign(a Account, toSign []byte) (signature []byte, err error) {
am.mutex.RLock()
- unlockedKey := am.unlockedKeys[string(fromAccount.Address)]
+ unlockedKey := am.unlockedKeys[string(a.Address)]
am.mutex.RUnlock()
if unlockedKey.Address == nil {
return nil, ErrLocked
@@ -106,28 +105,25 @@ func (am *AccountManager) Sign(fromAccount *Account, toSign []byte) (signature [
return signature, err
}
-func (am *AccountManager) SignLocked(fromAccount *Account, keyAuth string, toSign []byte) (signature []byte, err error) {
- key, err := am.keyStore.GetKey(fromAccount.Address, keyAuth)
+func (am *AccountManager) SignLocked(a Account, keyAuth string, toSign []byte) (signature []byte, err error) {
+ key, err := am.keyStore.GetKey(a.Address, keyAuth)
if err != nil {
return nil, err
}
am.mutex.RLock()
- am.unlockedKeys[string(fromAccount.Address)] = *key
+ am.unlockedKeys[string(a.Address)] = *key
am.mutex.RUnlock()
- go unlockLater(am, fromAccount.Address)
+ go unlockLater(am, a.Address)
signature, err = crypto.Sign(toSign, key.PrivateKey)
return signature, err
}
-func (am AccountManager) NewAccount(auth string) (*Account, error) {
+func (am *AccountManager) NewAccount(auth string) (Account, error) {
key, err := am.keyStore.GenerateNewKey(crand.Reader, auth)
if err != nil {
- return nil, err
- }
- ua := &Account{
- Address: key.Address,
+ return Account{}, err
}
- return ua, err
+ return Account{Address: key.Address}, nil
}
func (am *AccountManager) Accounts() ([]Account, error) {
diff --git a/accounts/accounts_test.go b/accounts/accounts_test.go
index 44d1d72f1..d8187220a 100644
--- a/accounts/accounts_test.go
+++ b/accounts/accounts_test.go
@@ -3,10 +3,11 @@ package accounts
import (
"testing"
+ "time"
+
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/randentropy"
"github.com/ethereum/go-ethereum/ethutil"
- "time"
)
func TestAccountManager(t *testing.T) {