Merge pull request #43

a7e4e34 make sure wallet is closed on app close (Jacob Brydolf)
a88c031 continue recovering from seed on open if not finished (Jacob Brydolf)
625ae77 wizard: save recovering state (Jacob Brydolf)
06d628b libwalletqt: added isRecovering state (Jacob Brydolf)
1ca4fd2 one more variable fix (Jacob Brydolf)
This commit is contained in:
Riccardo Spagni
2016-10-10 22:19:35 +02:00
5 changed files with 27 additions and 11 deletions

View File

@@ -158,7 +158,6 @@ ApplicationWindow {
} }
console.log("using wizard wallet") console.log("using wizard wallet")
connectWallet(wizard.settings['wallet']) connectWallet(wizard.settings['wallet'])
isNewWallet = true isNewWallet = true
@@ -183,7 +182,9 @@ ApplicationWindow {
currentWallet.moneySpent.connect(onWalletMoneySent) currentWallet.moneySpent.connect(onWalletMoneySent)
currentWallet.moneyReceived.connect(onWalletMoneyReceived) currentWallet.moneyReceived.connect(onWalletMoneyReceived)
console.log("initializing with daemon address: ", persistentSettings.daemon_address) console.log("initializing with daemon address: ", persistentSettings.daemon_address)
currentWallet.initAsync(persistentSettings.daemon_address, 0); console.log("Recovering from seed: ", persistentSettings.is_recovering)
console.log("restore Height", persistentSettings.restore_height)
currentWallet.initAsync(persistentSettings.daemon_address, 0, persistentSettings.is_recovering, persistentSettings.restore_height);
} }
function walletPath() { function walletPath() {
@@ -244,7 +245,6 @@ ApplicationWindow {
leftPanel.daemonProgress.updateProgress(dCurrentBlock,dTargetBlock); leftPanel.daemonProgress.updateProgress(dCurrentBlock,dTargetBlock);
// Store wallet after first refresh. To prevent broken wallet after a crash // Store wallet after first refresh. To prevent broken wallet after a crash
// TODO: Move this to libwallet?
if(isNewWallet && currentWallet.blockChainHeight() > 0){ if(isNewWallet && currentWallet.blockChainHeight() > 0){
currentWallet.store(persistentSettings.wallet_path) currentWallet.store(persistentSettings.wallet_path)
isNewWallet = false isNewWallet = false
@@ -257,6 +257,11 @@ ApplicationWindow {
walletInitialized = true walletInitialized = true
} }
// recovering from seed is finished after first refresh
if(persistentSettings.is_recovering) {
persistentSettings.is_recovering = false
}
leftPanel.networkStatus.connected = currentWallet.connected leftPanel.networkStatus.connected = currentWallet.connected
onWalletUpdate(); onWalletUpdate();
@@ -445,7 +450,8 @@ ApplicationWindow {
property bool testnet: true property bool testnet: true
property string daemon_address: "localhost:38081" property string daemon_address: "localhost:38081"
property string payment_id property string payment_id
property int restore_height:0 property int restore_height : 0
property bool is_recovering : false
} }
// TODO: replace with customized popups // TODO: replace with customized popups
@@ -788,4 +794,8 @@ ApplicationWindow {
} }
} }
} }
onClosing: {
walletManager.closeWallet(currentWallet);
console.log("onClosing called");
}
} }

View File

@@ -115,13 +115,18 @@ bool Wallet::store(const QString &path)
return m_walletImpl->store(path.toStdString()); return m_walletImpl->store(path.toStdString());
} }
bool Wallet::init(const QString &daemonAddress, quint64 upperTransactionLimit) bool Wallet::init(const QString &daemonAddress, quint64 upperTransactionLimit, bool isRecovering, quint64 restoreHeight)
{ {
return m_walletImpl->init(daemonAddress.toStdString(), upperTransactionLimit); return m_walletImpl->init(daemonAddress.toStdString(), upperTransactionLimit);
} }
void Wallet::initAsync(const QString &daemonAddress, quint64 upperTransactionLimit) void Wallet::initAsync(const QString &daemonAddress, quint64 upperTransactionLimit, bool isRecovering, quint64 restoreHeight)
{ {
if (isRecovering){
qDebug() << "RESTORING";
m_walletImpl->setRecoveringFromSeed(true);
m_walletImpl->setRefreshFromBlockHeight(restoreHeight);
}
m_walletImpl->initAsync(daemonAddress.toStdString(), upperTransactionLimit); m_walletImpl->initAsync(daemonAddress.toStdString(), upperTransactionLimit);
} }
@@ -263,6 +268,5 @@ Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent)
Wallet::~Wallet() Wallet::~Wallet()
{ {
Bitmonero::WalletManagerFactory::getWalletManager()->closeWallet(m_walletImpl); Bitmonero::WalletManagerFactory::getWalletManager()->closeWallet(m_walletImpl);
} }

View File

@@ -74,10 +74,10 @@ public:
Q_INVOKABLE bool store(const QString &path); Q_INVOKABLE bool store(const QString &path);
//! initializes wallet //! initializes wallet
Q_INVOKABLE bool init(const QString &daemonAddress, quint64 upperTransactionLimit); Q_INVOKABLE bool init(const QString &daemonAddress, quint64 upperTransactionLimit, bool isRecovering = false, quint64 restoreHeight = 0);
//! initializes wallet asynchronously //! initializes wallet asynchronously
Q_INVOKABLE void initAsync(const QString &daemonAddress, quint64 upperTransactionLimit); Q_INVOKABLE void initAsync(const QString &daemonAddress, quint64 upperTransactionLimit, bool isRecovering = false, quint64 restoreHeight = 0);
//! connects to daemon //! connects to daemon
Q_INVOKABLE bool connectToDaemon(); Q_INVOKABLE bool connectToDaemon();

View File

@@ -138,6 +138,7 @@ Rectangle {
appWindow.persistentSettings.daemon_address = settings.daemon_address appWindow.persistentSettings.daemon_address = settings.daemon_address
appWindow.persistentSettings.testnet = settings.testnet appWindow.persistentSettings.testnet = settings.testnet
appWindow.persistentSettings.restore_height = parseInt(settings.restore_height) appWindow.persistentSettings.restore_height = parseInt(settings.restore_height)
appWindow.persistentSettings.is_recovering = (settings.is_recovering === undefined)? false : settings.is_recovering
} }

View File

@@ -54,17 +54,18 @@ Item {
settingsObject['account_name'] = uiItem.accountNameText settingsObject['account_name'] = uiItem.accountNameText
settingsObject['words'] = Utils.lineBreaksToSpaces(uiItem.wordsTextItem.memoText) settingsObject['words'] = Utils.lineBreaksToSpaces(uiItem.wordsTextItem.memoText)
settingsObject['wallet_path'] = uiItem.walletPath settingsObject['wallet_path'] = uiItem.walletPath
settingsObject['restoreHeight'] = parseInt(uiItem.restoreHeight) settingsObject['restore_height'] = parseInt(uiItem.restoreHeight)
return recoveryWallet(settingsObject) return recoveryWallet(settingsObject)
} }
function recoveryWallet(settingsObject) { function recoveryWallet(settingsObject) {
var testnet = appWindow.persistentSettings.testnet; var testnet = appWindow.persistentSettings.testnet;
var restoreHeight = settingsObject.restoreHeight; var restoreHeight = settingsObject.restore_height;
var wallet = walletManager.recoveryWallet(oshelper.temporaryFilename(), settingsObject.words, testnet, restoreHeight); var wallet = walletManager.recoveryWallet(oshelper.temporaryFilename(), settingsObject.words, testnet, restoreHeight);
var success = wallet.status === Wallet.Status_Ok; var success = wallet.status === Wallet.Status_Ok;
if (success) { if (success) {
settingsObject['wallet'] = wallet; settingsObject['wallet'] = wallet;
settingsObject['is_recovering'] = true;
} else { } else {
walletManager.closeWallet(wallet); walletManager.closeWallet(wallet);
} }