Integrate pre-sale key import function

* TODO: get password from UI
* TODO: UI feedback on successful and failed import
This commit is contained in:
Gustav Simonsson 2015-02-23 21:48:22 +01:00
parent dd086791ac
commit 193e20c8fe
4 changed files with 47 additions and 17 deletions

View file

@ -93,3 +93,7 @@ func (am *AccountManager) Accounts() ([]Account, error) {
}
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/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil"
@ -175,7 +176,19 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
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) {

View file

@ -7,6 +7,7 @@ import (
"path"
"strings"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
@ -117,6 +118,7 @@ type Ethereum struct {
blockProcessor *core.BlockProcessor
txPool *core.TxPool
chainManager *core.ChainManager
accountManager *accounts.AccountManager
blockPool *BlockPool
whisper *whisper.Whisper
@ -177,6 +179,12 @@ func New(config *Config) (*Ethereum, error) {
}
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.blockProcessor = core.NewBlockProcessor(db, eth.txPool, eth.chainManager, eth.EventMux())
eth.chainManager.SetProcessor(eth.blockProcessor)
@ -214,22 +222,23 @@ func New(config *Config) (*Ethereum, error) {
return eth, nil
}
func (s *Ethereum) KeyManager() *crypto.KeyManager { return s.keyManager }
func (s *Ethereum) Logger() ethlogger.LogSystem { return s.logger }
func (s *Ethereum) Name() string { return s.net.Name }
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 { 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) Coinbase() []byte { return nil } // TODO
func (s *Ethereum) KeyManager() *crypto.KeyManager { return s.keyManager }
func (s *Ethereum) Logger() ethlogger.LogSystem { return s.logger }
func (s *Ethereum) Name() string { return s.net.Name }
func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager }
func (s *Ethereum) AccountManager() *accounts.AccountManager { return s.accountManager }
func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor }
func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
func (s *Ethereum) 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) Coinbase() []byte { return nil } // TODO
// Start the ethereum
func (s *Ethereum) Start() error {

View file

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