accounts: AccountManager -> Manager
This commit is contained in:
parent
3750ec7b7d
commit
fb53a9362e
@ -52,7 +52,7 @@ type Account struct {
|
||||
Address []byte
|
||||
}
|
||||
|
||||
type AccountManager struct {
|
||||
type Manager struct {
|
||||
keyStore crypto.KeyStore2
|
||||
unlocked map[string]*unlocked
|
||||
unlockTime time.Duration
|
||||
@ -66,8 +66,8 @@ type unlocked struct {
|
||||
*crypto.Key
|
||||
}
|
||||
|
||||
func NewAccountManager(keyStore crypto.KeyStore2, unlockTime time.Duration) *AccountManager {
|
||||
return &AccountManager{
|
||||
func NewManager(keyStore crypto.KeyStore2, unlockTime time.Duration) *Manager {
|
||||
return &Manager{
|
||||
keyStore: keyStore,
|
||||
unlocked: make(map[string]*unlocked),
|
||||
unlockTime: unlockTime,
|
||||
@ -75,19 +75,19 @@ func NewAccountManager(keyStore crypto.KeyStore2, unlockTime time.Duration) *Acc
|
||||
}
|
||||
|
||||
// Coinbase returns the account address that mining rewards are sent to.
|
||||
func (am *AccountManager) Coinbase() (addr []byte, err error) {
|
||||
func (am *Manager) 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) {
|
||||
func (am *Manager) 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) {
|
||||
func (am *Manager) firstAddr() ([]byte, error) {
|
||||
addrs, err := am.keyStore.GetKeyAddresses()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -98,11 +98,11 @@ func (am *AccountManager) firstAddr() ([]byte, error) {
|
||||
return addrs[0], nil
|
||||
}
|
||||
|
||||
func (am *AccountManager) DeleteAccount(address []byte, auth string) error {
|
||||
func (am *Manager) DeleteAccount(address []byte, auth string) error {
|
||||
return am.keyStore.DeleteKey(address, auth)
|
||||
}
|
||||
|
||||
func (am *AccountManager) Sign(a Account, toSign []byte) (signature []byte, err error) {
|
||||
func (am *Manager) Sign(a Account, toSign []byte) (signature []byte, err error) {
|
||||
am.mutex.RLock()
|
||||
unlockedKey, found := am.unlocked[string(a.Address)]
|
||||
am.mutex.RUnlock()
|
||||
@ -113,7 +113,7 @@ func (am *AccountManager) Sign(a Account, toSign []byte) (signature []byte, err
|
||||
return signature, err
|
||||
}
|
||||
|
||||
func (am *AccountManager) SignLocked(a Account, keyAuth string, toSign []byte) (signature []byte, err error) {
|
||||
func (am *Manager) 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
|
||||
@ -124,7 +124,7 @@ func (am *AccountManager) SignLocked(a Account, keyAuth string, toSign []byte) (
|
||||
return signature, err
|
||||
}
|
||||
|
||||
func (am *AccountManager) NewAccount(auth string) (Account, error) {
|
||||
func (am *Manager) NewAccount(auth string) (Account, error) {
|
||||
key, err := am.keyStore.GenerateNewKey(crand.Reader, auth)
|
||||
if err != nil {
|
||||
return Account{}, err
|
||||
@ -132,7 +132,7 @@ func (am *AccountManager) NewAccount(auth string) (Account, error) {
|
||||
return Account{Address: key.Address}, nil
|
||||
}
|
||||
|
||||
func (am *AccountManager) Accounts() ([]Account, error) {
|
||||
func (am *Manager) Accounts() ([]Account, error) {
|
||||
addresses, err := am.keyStore.GetKeyAddresses()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -148,7 +148,7 @@ func (am *AccountManager) Accounts() ([]Account, error) {
|
||||
return accounts, err
|
||||
}
|
||||
|
||||
func (am *AccountManager) addUnlocked(addr []byte, key *crypto.Key) *unlocked {
|
||||
func (am *Manager) addUnlocked(addr []byte, key *crypto.Key) *unlocked {
|
||||
u := &unlocked{addr: addr, abort: make(chan struct{}), Key: key}
|
||||
am.mutex.Lock()
|
||||
prev, found := am.unlocked[string(addr)]
|
||||
@ -162,7 +162,7 @@ func (am *AccountManager) addUnlocked(addr []byte, key *crypto.Key) *unlocked {
|
||||
return u
|
||||
}
|
||||
|
||||
func (am *AccountManager) dropLater(u *unlocked) {
|
||||
func (am *Manager) dropLater(u *unlocked) {
|
||||
t := time.NewTimer(am.unlockTime)
|
||||
defer t.Stop()
|
||||
select {
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
func TestAccountManager(t *testing.T) {
|
||||
ks := crypto.NewKeyStorePlain(ethutil.DefaultDataDir() + "/testaccounts")
|
||||
am := NewAccountManager(ks, 100*time.Millisecond)
|
||||
am := NewManager(ks, 100*time.Millisecond)
|
||||
pass := "" // not used but required by API
|
||||
a1, err := am.NewAccount(pass)
|
||||
toSign := randentropy.GetEntropyCSPRNG(32)
|
||||
@ -38,7 +38,7 @@ func TestAccountManager(t *testing.T) {
|
||||
|
||||
func TestAccountManagerLocking(t *testing.T) {
|
||||
ks := crypto.NewKeyStorePassphrase(ethutil.DefaultDataDir() + "/testaccounts")
|
||||
am := NewAccountManager(ks, 200*time.Millisecond)
|
||||
am := NewManager(ks, 200*time.Millisecond)
|
||||
pass := "foo"
|
||||
a1, err := am.NewAccount(pass)
|
||||
toSign := randentropy.GetEntropyCSPRNG(32)
|
||||
|
@ -167,8 +167,8 @@ func GetChain(ctx *cli.Context) (*core.ChainManager, ethutil.Database) {
|
||||
return core.NewChainManager(db, new(event.TypeMux)), db
|
||||
}
|
||||
|
||||
func GetAccountManager(ctx *cli.Context) *accounts.AccountManager {
|
||||
func GetAccountManager(ctx *cli.Context) *accounts.Manager {
|
||||
dataDir := ctx.GlobalString(DataDirFlag.Name)
|
||||
ks := crypto.NewKeyStorePassphrase(path.Join(dataDir, "keys"))
|
||||
return accounts.NewAccountManager(ks, 300*time.Second)
|
||||
return accounts.NewManager(ks, 300*time.Second)
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ type Config struct {
|
||||
Dial bool
|
||||
|
||||
MinerThreads int
|
||||
AccountManager *accounts.AccountManager
|
||||
AccountManager *accounts.Manager
|
||||
}
|
||||
|
||||
func (cfg *Config) parseBootNodes() []*discover.Node {
|
||||
@ -115,7 +115,7 @@ type Ethereum struct {
|
||||
txPool *core.TxPool
|
||||
chainManager *core.ChainManager
|
||||
blockPool *blockpool.BlockPool
|
||||
accountManager *accounts.AccountManager
|
||||
accountManager *accounts.Manager
|
||||
whisper *whisper.Whisper
|
||||
|
||||
net *p2p.Server
|
||||
@ -204,21 +204,21 @@ func New(config *Config) (*Ethereum, error) {
|
||||
return eth, nil
|
||||
}
|
||||
|
||||
func (s *Ethereum) Logger() logger.LogSystem { return s.logger }
|
||||
func (s *Ethereum) Name() string { return s.net.Name }
|
||||
func (s *Ethereum) AccountManager() *accounts.AccountManager { return s.accountManager }
|
||||
func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager }
|
||||
func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor }
|
||||
func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
|
||||
func (s *Ethereum) BlockPool() *blockpool.BlockPool { return s.blockPool }
|
||||
func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper }
|
||||
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux }
|
||||
func (s *Ethereum) Db() ethutil.Database { return s.db }
|
||||
func (s *Ethereum) Miner() *miner.Miner { return s.miner }
|
||||
func (s *Ethereum) IsListening() bool { return true } // Always listening
|
||||
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
|
||||
func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() }
|
||||
func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers }
|
||||
func (s *Ethereum) Logger() logger.LogSystem { return s.logger }
|
||||
func (s *Ethereum) Name() string { return s.net.Name }
|
||||
func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager }
|
||||
func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager }
|
||||
func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor }
|
||||
func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
|
||||
func (s *Ethereum) BlockPool() *blockpool.BlockPool { return s.blockPool }
|
||||
func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper }
|
||||
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux }
|
||||
func (s *Ethereum) Db() ethutil.Database { return s.db }
|
||||
func (s *Ethereum) Miner() *miner.Miner { return s.miner }
|
||||
func (s *Ethereum) IsListening() bool { return true } // Always listening
|
||||
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
|
||||
func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() }
|
||||
func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers }
|
||||
|
||||
// Start the ethereum
|
||||
func (s *Ethereum) Start() error {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"github.com/obscuren/otto"
|
||||
|
@ -27,7 +27,7 @@ var pipelogger = logger.NewLogger("XETH")
|
||||
type Backend interface {
|
||||
BlockProcessor() *core.BlockProcessor
|
||||
ChainManager() *core.ChainManager
|
||||
AccountManager() *accounts.AccountManager
|
||||
AccountManager() *accounts.Manager
|
||||
TxPool() *core.TxPool
|
||||
PeerCount() int
|
||||
IsListening() bool
|
||||
@ -42,7 +42,7 @@ type XEth struct {
|
||||
eth Backend
|
||||
blockProcessor *core.BlockProcessor
|
||||
chainManager *core.ChainManager
|
||||
accountManager *accounts.AccountManager
|
||||
accountManager *accounts.Manager
|
||||
state *State
|
||||
whisper *Whisper
|
||||
miner *miner.Miner
|
||||
|
Loading…
Reference in New Issue
Block a user