This commit is contained in:
Gustav Simonsson 2015-02-23 22:10:31 +00:00
commit f78f982dd3
4 changed files with 47 additions and 17 deletions

View file

@ -93,3 +93,7 @@ func (am *AccountManager) Accounts() ([]Account, error) {
} }
return accounts, err return accounts, err
} }
func (am *AccountManager) KeyStore() crypto.KeyStore2 {
return am.keyStore
}

View file

@ -37,6 +37,7 @@ import (
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
@ -175,7 +176,19 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
return gui.win, nil return gui.win, nil
} }
func (gui *Gui) ImportKey(filePath string) { func (gui *Gui) ImportKey(fileURL string) {
filePath := fileURL[6:] // path after "file://"
pass := "bar" // TODO: get from UI
fileContent, err := ioutil.ReadFile(filePath)
if err != nil {
guilogger.Errorln("unable to import key: ", err)
// TODO: UI feedback
}
_, err = crypto.ImportPreSaleKey(gui.eth.AccountManager().KeyStore(), fileContent, pass)
if err != nil {
guilogger.Errorln("unable to import key: ", err)
// TODO: UI feedback
}
} }
func (gui *Gui) showKeyImport(context *qml.Context) (*qml.Window, error) { func (gui *Gui) showKeyImport(context *qml.Context) (*qml.Window, error) {

View file

@ -7,6 +7,7 @@ import (
"path" "path"
"strings" "strings"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
@ -117,6 +118,7 @@ type Ethereum struct {
blockProcessor *core.BlockProcessor blockProcessor *core.BlockProcessor
txPool *core.TxPool txPool *core.TxPool
chainManager *core.ChainManager chainManager *core.ChainManager
accountManager *accounts.AccountManager
blockPool *BlockPool blockPool *BlockPool
whisper *whisper.Whisper whisper *whisper.Whisper
@ -177,6 +179,12 @@ func New(config *Config) (*Ethereum, error) {
} }
eth.chainManager = core.NewChainManager(db, eth.EventMux()) eth.chainManager = core.NewChainManager(db, eth.EventMux())
// TODO: add config flag and case on plain/protected key store
ks := crypto.NewKeyStorePlain(crypto.DefaultDataDir())
am := accounts.NewAccountManager(ks)
eth.accountManager = &am
eth.txPool = core.NewTxPool(eth.EventMux()) eth.txPool = core.NewTxPool(eth.EventMux())
eth.blockProcessor = core.NewBlockProcessor(db, eth.txPool, eth.chainManager, eth.EventMux()) eth.blockProcessor = core.NewBlockProcessor(db, eth.txPool, eth.chainManager, eth.EventMux())
eth.chainManager.SetProcessor(eth.blockProcessor) eth.chainManager.SetProcessor(eth.blockProcessor)
@ -214,22 +222,23 @@ func New(config *Config) (*Ethereum, error) {
return eth, nil return eth, nil
} }
func (s *Ethereum) KeyManager() *crypto.KeyManager { return s.keyManager } func (s *Ethereum) KeyManager() *crypto.KeyManager { return s.keyManager }
func (s *Ethereum) Logger() ethlogger.LogSystem { return s.logger } func (s *Ethereum) Logger() ethlogger.LogSystem { return s.logger }
func (s *Ethereum) Name() string { return s.net.Name } func (s *Ethereum) Name() string { return s.net.Name }
func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager } func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager }
func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor } func (s *Ethereum) AccountManager() *accounts.AccountManager { return s.accountManager }
func (s *Ethereum) TxPool() *core.TxPool { return s.txPool } func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor }
func (s *Ethereum) BlockPool() *BlockPool { return s.blockPool } func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper } func (s *Ethereum) BlockPool() *BlockPool { return s.blockPool }
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux } func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper }
func (s *Ethereum) Db() ethutil.Database { return s.db } func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux }
func (s *Ethereum) Miner() *miner.Miner { return s.miner } func (s *Ethereum) Db() ethutil.Database { return s.db }
func (s *Ethereum) IsListening() bool { return true } // Always listening func (s *Ethereum) Miner() *miner.Miner { return s.miner }
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() } func (s *Ethereum) IsListening() bool { return true } // Always listening
func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() } func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers } func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() }
func (s *Ethereum) Coinbase() []byte { return nil } // TODO func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers }
func (s *Ethereum) Coinbase() []byte { return nil } // TODO
// Start the ethereum // Start the ethereum
func (s *Ethereum) Start() error { func (s *Ethereum) Start() error {

View file

@ -9,6 +9,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
@ -26,6 +27,7 @@ var pipelogger = logger.NewLogger("XETH")
type Backend interface { type Backend interface {
BlockProcessor() *core.BlockProcessor BlockProcessor() *core.BlockProcessor
ChainManager() *core.ChainManager ChainManager() *core.ChainManager
AccountManager() *accounts.AccountManager
TxPool() *core.TxPool TxPool() *core.TxPool
PeerCount() int PeerCount() int
IsListening() bool IsListening() bool
@ -41,6 +43,7 @@ type XEth struct {
eth Backend eth Backend
blockProcessor *core.BlockProcessor blockProcessor *core.BlockProcessor
chainManager *core.ChainManager chainManager *core.ChainManager
accountManager *accounts.AccountManager
state *State state *State
whisper *Whisper whisper *Whisper
miner *miner.Miner miner *miner.Miner
@ -51,6 +54,7 @@ func New(eth Backend) *XEth {
eth: eth, eth: eth,
blockProcessor: eth.BlockProcessor(), blockProcessor: eth.BlockProcessor(),
chainManager: eth.ChainManager(), chainManager: eth.ChainManager(),
accountManager: eth.AccountManager(),
whisper: NewWhisper(eth.Whisper()), whisper: NewWhisper(eth.Whisper()),
miner: eth.Miner(), miner: eth.Miner(),
} }