From 6034eaffc8b55ec5e07834e8656b230b5fccb661 Mon Sep 17 00:00:00 2001 From: MoroccanMalinois Date: Wed, 11 Jan 2017 03:16:21 +0000 Subject: [PATCH] Add parse_uri to libwalletqt --- src/libwalletqt/Wallet.cpp | 17 +++++++++++++++++ src/libwalletqt/Wallet.h | 2 ++ src/libwalletqt/WalletManager.cpp | 6 ++++++ src/libwalletqt/WalletManager.h | 1 + 4 files changed, 26 insertions(+) diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 5bf75788..bca9d072 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -450,6 +450,23 @@ bool Wallet::verifySignedMessage(const QString &message, const QString &address, return m_walletImpl->verifySignedMessage(message.toStdString(), address.toStdString(), signature.toStdString()); } } +bool Wallet::parse_uri(const QString &uri, QString &address, QString &payment_id, uint64_t &amount, QString &tx_description, QString &recipient_name, QVector &unknown_parameters, QString &error) +{ + std::string s_address, s_payment_id, s_tx_description, s_recipient_name, s_error; + std::vector s_unknown_parameters; + bool res= m_walletImpl->parse_uri(uri.toStdString(), s_address, s_payment_id, amount, s_tx_description, s_recipient_name, s_unknown_parameters, s_error); + if(res) + { + address = QString::fromStdString(s_address); + payment_id = QString::fromStdString(s_payment_id); + tx_description = QString::fromStdString(s_tx_description); + recipient_name = QString::fromStdString(s_recipient_name); + for( const auto &p : s_unknown_parameters ) + unknown_parameters.append(QString::fromStdString(p)); + } + error = QString::fromStdString(s_error); + return res; +} Wallet::Wallet(Monero::Wallet *w, QObject *parent) : QObject(parent) diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 24bdc15b..8217b8ba 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -183,6 +183,8 @@ public: //! verify a signed message Q_INVOKABLE bool verifySignedMessage(const QString &message, const QString &address, const QString &signature, bool filename = false) const; + //! Parse URI + Q_INVOKABLE bool parse_uri(const QString &uri, QString &address, QString &payment_id, uint64_t &amount, QString &tx_description, QString &recipient_name, QVector &unknown_parameters, QString &error); //! saved payment id QString paymentId() const; diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 5a090ec3..e08c71d4 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -234,6 +234,12 @@ QString WalletManager::resolveOpenAlias(const QString &address) const res = std::string(dnssec_valid ? "true" : "false") + "|" + res; return QString::fromStdString(res); } +bool WalletManager::parse_uri(const QString &uri, QString &address, QString &payment_id, uint64_t &amount, QString &tx_description, QString &recipient_name, QVector &unknown_parameters, QString &error) +{ + if (m_currentWallet) + return m_currentWallet->parse_uri(uri, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error); + return false; +} void WalletManager::setLogLevel(int logLevel) { diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 6673061a..87e2277a 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -117,6 +117,7 @@ public: Q_INVOKABLE double getPasswordStrength(const QString &password) const; Q_INVOKABLE QString resolveOpenAlias(const QString &address) const; + Q_INVOKABLE bool parse_uri(const QString &uri, QString &address, QString &payment_id, uint64_t &amount, QString &tx_description, QString &recipient_name, QVector &unknown_parameters, QString &error); signals: