mirror of
https://github.com/feather-wallet/feather.git
synced 2025-01-08 11:59:29 +00:00
libwalletqt: cleanup WalletManager
This commit is contained in:
parent
46ae248259
commit
6903609e8b
2 changed files with 25 additions and 130 deletions
|
@ -193,21 +193,11 @@ QStringList WalletManager::findWallets(const QString &path)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WalletManager::errorString() const
|
|
||||||
{
|
|
||||||
return tr("Unknown error");
|
|
||||||
}
|
|
||||||
|
|
||||||
quint64 WalletManager::maximumAllowedAmount() const
|
quint64 WalletManager::maximumAllowedAmount() const
|
||||||
{
|
{
|
||||||
return Monero::Wallet::maximumAllowedAmount();
|
return Monero::Wallet::maximumAllowedAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WalletManager::maximumAllowedAmountAsString() const
|
|
||||||
{
|
|
||||||
return WalletManager::displayAmount(WalletManager::maximumAllowedAmount());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString WalletManager::displayAmount(quint64 amount, bool trailing_zeroes, int decimals)
|
QString WalletManager::displayAmount(quint64 amount, bool trailing_zeroes, int decimals)
|
||||||
{
|
{
|
||||||
auto amountStr = QString::fromStdString(Monero::Wallet::displayAmount(amount));
|
auto amountStr = QString::fromStdString(Monero::Wallet::displayAmount(amount));
|
||||||
|
@ -260,38 +250,6 @@ QString WalletManager::paymentIdFromAddress(const QString &address, NetworkType:
|
||||||
return QString::fromStdString(Monero::Wallet::paymentIdFromAddress(address.toStdString(), static_cast<Monero::NetworkType>(nettype)));
|
return QString::fromStdString(Monero::Wallet::paymentIdFromAddress(address.toStdString(), static_cast<Monero::NetworkType>(nettype)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WalletManager::setDaemonAddressAsync(const QString &address)
|
|
||||||
{
|
|
||||||
m_scheduler.run([this, address] {
|
|
||||||
m_pimpl->setDaemonAddress(address.toStdString());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WalletManager::connected() const
|
|
||||||
{
|
|
||||||
return m_pimpl->connected();
|
|
||||||
}
|
|
||||||
|
|
||||||
quint64 WalletManager::networkDifficulty() const
|
|
||||||
{
|
|
||||||
return m_pimpl->networkDifficulty();
|
|
||||||
}
|
|
||||||
|
|
||||||
quint64 WalletManager::blockchainHeight() const
|
|
||||||
{
|
|
||||||
return m_pimpl->blockchainHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
quint64 WalletManager::blockchainTargetHeight() const
|
|
||||||
{
|
|
||||||
return m_pimpl->blockchainTargetHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WalletManager::localDaemonSynced() const
|
|
||||||
{
|
|
||||||
return blockchainHeight() > 1 && blockchainHeight() >= blockchainTargetHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WalletManager::isDaemonLocal(const QString &daemon_address) const
|
bool WalletManager::isDaemonLocal(const QString &daemon_address) const
|
||||||
{
|
{
|
||||||
return daemon_address.isEmpty() ? false : Monero::Utils::isAddressLocal(daemon_address.toStdString());
|
return daemon_address.isEmpty() ? false : Monero::Utils::isAddressLocal(daemon_address.toStdString());
|
||||||
|
@ -321,16 +279,6 @@ void WalletManager::setLogCategories(const QString &categories)
|
||||||
Monero::WalletManagerFactory::setLogCategories(categories.toStdString());
|
Monero::WalletManagerFactory::setLogCategories(categories.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WalletManager::urlToLocalPath(const QUrl &url) const
|
|
||||||
{
|
|
||||||
return QDir::toNativeSeparators(url.toLocalFile());
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl WalletManager::localPathToUrl(const QString &path) const
|
|
||||||
{
|
|
||||||
return QUrl::fromLocalFile(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WalletManager::clearWalletCache(const QString &wallet_path)
|
bool WalletManager::clearWalletCache(const QString &wallet_path)
|
||||||
{
|
{
|
||||||
QString fileName = wallet_path;
|
QString fileName = wallet_path;
|
||||||
|
@ -374,26 +322,3 @@ void WalletManager::onPassphraseEntered(const QString &passphrase, bool enter_on
|
||||||
m_passphraseReceiver->onPassphraseEntered(passphrase, enter_on_device, entry_abort);
|
m_passphraseReceiver->onPassphraseEntered(passphrase, enter_on_device, entry_abort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WalletManager::proxyAddress() const
|
|
||||||
{
|
|
||||||
QMutexLocker locker(&m_proxyMutex);
|
|
||||||
return m_proxyAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WalletManager::setProxyAddress(QString address)
|
|
||||||
{
|
|
||||||
m_scheduler.run([this, address] {
|
|
||||||
{
|
|
||||||
QMutexLocker locker(&m_proxyMutex);
|
|
||||||
|
|
||||||
if (!m_pimpl->setProxy(address.toStdString()))
|
|
||||||
{
|
|
||||||
qCritical() << "Failed to set proxy address" << address;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_proxyAddress = std::move(address);
|
|
||||||
}
|
|
||||||
emit proxyAddressChanged();
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -23,7 +23,6 @@ struct WalletManager;
|
||||||
class WalletManager : public QObject, public PassprasePrompter
|
class WalletManager : public QObject, public PassprasePrompter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool connected READ connected)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum LogLevel {
|
enum LogLevel {
|
||||||
|
@ -39,7 +38,7 @@ public:
|
||||||
|
|
||||||
static WalletManager * instance();
|
static WalletManager * instance();
|
||||||
// wizard: createWallet path;
|
// wizard: createWallet path;
|
||||||
Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password,
|
Wallet * createWallet(const QString &path, const QString &password,
|
||||||
const QString &language, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1);
|
const QString &language, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -49,19 +48,19 @@ public:
|
||||||
* \param nettype - type of network the wallet is running on
|
* \param nettype - type of network the wallet is running on
|
||||||
* \return wallet object pointer
|
* \return wallet object pointer
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1);
|
Wallet * openWallet(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief openWalletAsync - asynchronous version of "openWallet". Returns immediately. "walletOpened" signal
|
* \brief openWalletAsync - asynchronous version of "openWallet". Returns immediately. "walletOpened" signal
|
||||||
* emitted when wallet opened;
|
* emitted when wallet opened;
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void openWalletAsync(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1);
|
void openWalletAsync(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1);
|
||||||
|
|
||||||
// wizard: recoveryWallet path; hint: internally it recorvers wallet and set password = ""
|
// wizard: recoveryWallet path; hint: internally it recorvers wallet and set password = ""
|
||||||
Q_INVOKABLE Wallet * recoveryWallet(const QString &path, const QString &password, const QString &seed, const QString &seed_offset,
|
Wallet * recoveryWallet(const QString &path, const QString &password, const QString &seed, const QString &seed_offset,
|
||||||
NetworkType::Type nettype = NetworkType::MAINNET, quint64 restoreHeight = 0, quint64 kdfRounds = 1);
|
NetworkType::Type nettype = NetworkType::MAINNET, quint64 restoreHeight = 0, quint64 kdfRounds = 1);
|
||||||
|
|
||||||
Q_INVOKABLE Wallet * createWalletFromKeys(const QString &path,
|
Wallet * createWalletFromKeys(const QString &path,
|
||||||
const QString &password,
|
const QString &password,
|
||||||
const QString &language,
|
const QString &language,
|
||||||
NetworkType::Type nettype,
|
NetworkType::Type nettype,
|
||||||
|
@ -71,7 +70,7 @@ public:
|
||||||
quint64 restoreHeight = 0,
|
quint64 restoreHeight = 0,
|
||||||
quint64 kdfRounds = 1);
|
quint64 kdfRounds = 1);
|
||||||
|
|
||||||
Q_INVOKABLE Wallet * createDeterministicWalletFromSpendKey(const QString &path,
|
Wallet * createDeterministicWalletFromSpendKey(const QString &path,
|
||||||
const QString &password,
|
const QString &password,
|
||||||
const QString &language,
|
const QString &language,
|
||||||
NetworkType::Type nettype,
|
NetworkType::Type nettype,
|
||||||
|
@ -80,14 +79,14 @@ public:
|
||||||
quint64 kdfRounds,
|
quint64 kdfRounds,
|
||||||
const QString &offset_passphrase = "");
|
const QString &offset_passphrase = "");
|
||||||
|
|
||||||
Q_INVOKABLE Wallet * createWalletFromDevice(const QString &path,
|
Wallet * createWalletFromDevice(const QString &path,
|
||||||
const QString &password,
|
const QString &password,
|
||||||
NetworkType::Type nettype,
|
NetworkType::Type nettype,
|
||||||
const QString &deviceName,
|
const QString &deviceName,
|
||||||
quint64 restoreHeight = 0,
|
quint64 restoreHeight = 0,
|
||||||
const QString &subaddressLookahead = "");
|
const QString &subaddressLookahead = "");
|
||||||
|
|
||||||
Q_INVOKABLE void createWalletFromDeviceAsync(const QString &path,
|
void createWalletFromDeviceAsync(const QString &path,
|
||||||
const QString &password,
|
const QString &password,
|
||||||
NetworkType::Type nettype,
|
NetworkType::Type nettype,
|
||||||
const QString &deviceName,
|
const QString &deviceName,
|
||||||
|
@ -96,64 +95,40 @@ public:
|
||||||
|
|
||||||
|
|
||||||
//! checks is given filename is a wallet;
|
//! checks is given filename is a wallet;
|
||||||
Q_INVOKABLE bool walletExists(const QString &path) const;
|
bool walletExists(const QString &path) const;
|
||||||
|
|
||||||
//! verify wallet password
|
//! verify wallet password
|
||||||
Q_INVOKABLE bool verifyWalletPassword(const QString &keys_file_name, const QString &password, bool no_spend_key, uint64_t kdf_rounds = 1) const;
|
bool verifyWalletPassword(const QString &keys_file_name, const QString &password, bool no_spend_key, uint64_t kdf_rounds = 1) const;
|
||||||
|
|
||||||
//! returns list with wallet's filenames, if found by given path
|
//! returns list with wallet's filenames, if found by given path
|
||||||
Q_INVOKABLE QStringList findWallets(const QString &path);
|
QStringList findWallets(const QString &path);
|
||||||
|
|
||||||
//! returns error description in human language
|
|
||||||
Q_INVOKABLE QString errorString() const;
|
|
||||||
|
|
||||||
//! since we can't call static method from QML, move it to this class
|
//! since we can't call static method from QML, move it to this class
|
||||||
Q_INVOKABLE static QString displayAmount(quint64 amount, bool trailing_zeroes = true, int decimals = 12);
|
static QString displayAmount(quint64 amount, bool trailing_zeroes = true, int decimals = 12);
|
||||||
Q_INVOKABLE static quint64 amountFromString(const QString &amount);
|
static quint64 amountFromString(const QString &amount);
|
||||||
Q_INVOKABLE static quint64 amountFromDouble(double amount);
|
static quint64 amountFromDouble(double amount);
|
||||||
Q_INVOKABLE quint64 maximumAllowedAmount() const;
|
quint64 maximumAllowedAmount() const;
|
||||||
|
|
||||||
// QML JS engine doesn't support unsigned integers
|
bool paymentIdValid(const QString &payment_id) const;
|
||||||
Q_INVOKABLE QString maximumAllowedAmountAsString() const;
|
static bool addressValid(const QString &address, NetworkType::Type nettype);
|
||||||
|
static bool keyValid(const QString &key, const QString &address, bool isViewKey, NetworkType::Type nettype);
|
||||||
|
|
||||||
Q_INVOKABLE bool paymentIdValid(const QString &payment_id) const;
|
QString paymentIdFromAddress(const QString &address, NetworkType::Type nettype) const;
|
||||||
Q_INVOKABLE static bool addressValid(const QString &address, NetworkType::Type nettype);
|
|
||||||
Q_INVOKABLE static bool keyValid(const QString &key, const QString &address, bool isViewKey, NetworkType::Type nettype);
|
|
||||||
|
|
||||||
Q_INVOKABLE QString paymentIdFromAddress(const QString &address, NetworkType::Type nettype) const;
|
bool isDaemonLocal(const QString &daemon_address) const;
|
||||||
|
|
||||||
Q_INVOKABLE void setDaemonAddressAsync(const QString &address);
|
void setLogLevel(int logLevel);
|
||||||
Q_INVOKABLE bool connected() const;
|
void setLogCategories(const QString &categories);
|
||||||
Q_INVOKABLE quint64 networkDifficulty() const;
|
|
||||||
Q_INVOKABLE quint64 blockchainHeight() const;
|
|
||||||
Q_INVOKABLE quint64 blockchainTargetHeight() const;
|
|
||||||
Q_INVOKABLE bool localDaemonSynced() const;
|
|
||||||
Q_INVOKABLE bool isDaemonLocal(const QString &daemon_address) const;
|
|
||||||
|
|
||||||
// QML missing such functionality, implementing these helpers here
|
|
||||||
Q_INVOKABLE QString urlToLocalPath(const QUrl &url) const;
|
|
||||||
Q_INVOKABLE QUrl localPathToUrl(const QString &path) const;
|
|
||||||
|
|
||||||
Q_INVOKABLE void setLogLevel(int logLevel);
|
|
||||||
Q_INVOKABLE void setLogCategories(const QString &categories);
|
|
||||||
|
|
||||||
Q_INVOKABLE quint64 add(quint64 x, quint64 y) const { return x + y; }
|
|
||||||
Q_INVOKABLE quint64 sub(quint64 x, quint64 y) const { return x - y; }
|
|
||||||
Q_INVOKABLE qint64 addi(qint64 x, qint64 y) const { return x + y; }
|
|
||||||
Q_INVOKABLE qint64 subi(qint64 x, qint64 y) const { return x - y; }
|
|
||||||
|
|
||||||
QString resolveOpenAlias(const QString &address, bool &dnssecValid) const;
|
QString resolveOpenAlias(const QString &address, bool &dnssecValid) const;
|
||||||
void resolveOpenAliasAsync(const QString &address);
|
void resolveOpenAliasAsync(const QString &address);
|
||||||
|
|
||||||
// clear/rename wallet cache
|
// clear/rename wallet cache
|
||||||
Q_INVOKABLE static bool clearWalletCache(const QString &fileName);
|
static bool clearWalletCache(const QString &fileName);
|
||||||
|
|
||||||
Q_INVOKABLE void onPassphraseEntered(const QString &passphrase, bool enter_on_device, bool entry_abort=false);
|
void onPassphraseEntered(const QString &passphrase, bool enter_on_device, bool entry_abort=false);
|
||||||
virtual void onWalletPassphraseNeeded(bool on_device) override;
|
virtual void onWalletPassphraseNeeded(bool on_device) override;
|
||||||
|
|
||||||
QString proxyAddress() const;
|
|
||||||
void setProxyAddress(QString address);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void walletOpened(Wallet * wallet);
|
void walletOpened(Wallet * wallet);
|
||||||
void walletCreated(Wallet * wallet);
|
void walletCreated(Wallet * wallet);
|
||||||
|
@ -161,11 +136,8 @@ signals:
|
||||||
void deviceButtonRequest(quint64 buttonCode);
|
void deviceButtonRequest(quint64 buttonCode);
|
||||||
void deviceButtonPressed();
|
void deviceButtonPressed();
|
||||||
void deviceError(const QString &message);
|
void deviceError(const QString &message);
|
||||||
void miningStatus(bool isMining) const;
|
|
||||||
void proxyAddressChanged() const;
|
|
||||||
void openAliasResolved(const QString &alias, const QString &address, bool dnssecValid);
|
void openAliasResolved(const QString &alias, const QString &address, bool dnssecValid);
|
||||||
|
|
||||||
public slots:
|
|
||||||
private:
|
private:
|
||||||
friend class WalletPassphraseListenerImpl;
|
friend class WalletPassphraseListenerImpl;
|
||||||
|
|
||||||
|
@ -177,8 +149,6 @@ private:
|
||||||
mutable QMutex m_mutex;
|
mutable QMutex m_mutex;
|
||||||
PassphraseReceiver *m_passphraseReceiver;
|
PassphraseReceiver *m_passphraseReceiver;
|
||||||
QMutex m_mutex_passphraseReceiver;
|
QMutex m_mutex_passphraseReceiver;
|
||||||
QString m_proxyAddress;
|
|
||||||
mutable QMutex m_proxyMutex;
|
|
||||||
FutureScheduler m_scheduler;
|
FutureScheduler m_scheduler;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue