From 7cca8b8aa77e1684e29c3260728bf5b797c1c04a Mon Sep 17 00:00:00 2001 From: "moneromooo.monero" Date: Sat, 17 Dec 2016 15:57:42 +0000 Subject: [PATCH] Transfer: support OpenAlias addresses --- pages/Transfer.qml | 98 ++++++++++++++++++++++++++++--- src/libwalletqt/WalletManager.cpp | 8 +++ src/libwalletqt/WalletManager.h | 2 + 3 files changed, 100 insertions(+), 8 deletions(-) diff --git a/pages/Transfer.qml b/pages/Transfer.qml index 649750bb..4068b378 100644 --- a/pages/Transfer.qml +++ b/pages/Transfer.qml @@ -27,6 +27,8 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import QtQuick 2.0 +import QtQuick.Layouts 1.1 +import QtQuick.Dialogs 1.2 import moneroComponents.PendingTransaction 1.0 import "../components" import moneroComponents.Wallet 1.0 @@ -50,6 +52,35 @@ Rectangle { } } + function isValidOpenAliasAddress(address) { + address = address.trim() + var dot = address.indexOf('.') + if (dot < 0) + return false + // we can get an awful lot of valid domains, including non ASCII chars... accept anything + return true + } + + function oa_message(text) { + oaPopup.title = qsTr("OpenAlias error") + translationManager.emptyString + oaPopup.text = text + oaPopup.icon = StandardIcon.Information + oaPopup.onCloseCallback = null + oaPopup.open() + } + + // Information dialog + StandardDialog { + // dynamically change onclose handler + property var onCloseCallback + id: oaPopup + cancelVisible: false + onAccepted: { + if (onCloseCallback) { + onCloseCallback() + } + } + } Item { id: pageRoot @@ -204,23 +235,74 @@ Rectangle { onLinkActivated: appWindow.showPageRequest("AddressBook") } // recipient address input - LineEdit { - id: addressLine + RowLayout { + id: addressLineRow anchors.left: parent.left anchors.right: parent.right anchors.top: addressLabel.bottom - anchors.leftMargin: 17 - anchors.rightMargin: 17 - anchors.topMargin: 5 - placeholderText: "4..." - // validator: RegExpValidator { regExp: /[0-9A-Fa-f]{95}/g } + + LineEdit { + id: addressLine + anchors.left: parent.left + anchors.right: resolveButton.left + anchors.leftMargin: 17 + anchors.topMargin: 5 + placeholderText: "4..." + // validator: RegExpValidator { regExp: /[0-9A-Fa-f]{95}/g } + } + + StandardButton { + id: resolveButton + anchors.right: parent.right + anchors.leftMargin: 17 + anchors.topMargin: 17 + anchors.rightMargin: 17 + width: 60 + text: qsTr("RESOLVE") + translationManager.emptyString + shadowReleasedColor: "#FF4304" + shadowPressedColor: "#B32D00" + releasedColor: "#FF6C3C" + pressedColor: "#FF4304" + enabled : isValidOpenAliasAddress(addressLine.text) + onClicked: { + var result = walletManager.resolveOpenAlias(addressLine.text) + if (result) { + var parts = result.split("|") + if (parts.length == 2) { + var address_ok = walletManager.addressValid(parts[1], appWindow.persistentSettings.testnet) + if (parts[0] === "true") { + if (address_ok) { + addressLine.text = parts[1] + addressLine.cursorPosition = 0 + } + else + oa_message(qsTr("No valid address found at this OpenAlias address")) + } else if (parts[0] === "false") { + if (address_ok) { + addressLine.text = parts[1] + addressLine.cursorPosition = 0 + oa_message(qsTr("Address found, but the DNSSEC signatures could not be verified, so this address may be spoofed")) + } else { + oa_message(qsTr("No valid address found at this OpenAlias address, but the DNSSEC signatures could not be verified, so this may be spoofed")) + } + } else { + oa_message(qsTr("Internal error")) + } + } else { + oa_message(qsTr("Internal error")) + } + } else { + oa_message(qsTr("No address found")) + } + } + } } Label { id: paymentIdLabel anchors.left: parent.left anchors.right: parent.right - anchors.top: addressLine.bottom + anchors.top: addressLineRow.bottom anchors.leftMargin: 17 anchors.rightMargin: 17 anchors.topMargin: 17 diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 64e9a1db..5a090ec3 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -227,6 +227,14 @@ double WalletManager::miningHashRate() const return m_pimpl->miningHashRate(); } +QString WalletManager::resolveOpenAlias(const QString &address) const +{ + bool dnssec_valid = false; + std::string res = m_pimpl->resolveOpenAlias(address.toStdString(), dnssec_valid); + res = std::string(dnssec_valid ? "true" : "false") + "|" + res; + return QString::fromStdString(res); +} + void WalletManager::setLogLevel(int logLevel) { Monero::WalletManagerFactory::setLogLevel(logLevel); diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index fb3dd142..d06b4f6c 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -116,6 +116,8 @@ public: Q_INVOKABLE double getPasswordStrength(const QString &password) const; + Q_INVOKABLE QString resolveOpenAlias(const QString &address) const; + signals: void walletOpened(Wallet * wallet);