Merge pull request #304

7cca8b8 Transfer: support OpenAlias addresses (moneromooo.monero)
This commit is contained in:
Riccardo Spagni 2016-12-20 23:13:59 +02:00
commit ff274721f6
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
3 changed files with 100 additions and 8 deletions

View file

@ -27,6 +27,8 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.2
import moneroComponents.PendingTransaction 1.0 import moneroComponents.PendingTransaction 1.0
import "../components" import "../components"
import moneroComponents.Wallet 1.0 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 { Item {
id: pageRoot id: pageRoot
@ -204,23 +235,74 @@ Rectangle {
onLinkActivated: appWindow.showPageRequest("AddressBook") onLinkActivated: appWindow.showPageRequest("AddressBook")
} }
// recipient address input // recipient address input
LineEdit { RowLayout {
id: addressLine id: addressLineRow
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: addressLabel.bottom anchors.top: addressLabel.bottom
LineEdit {
id: addressLine
anchors.left: parent.left
anchors.right: resolveButton.left
anchors.leftMargin: 17 anchors.leftMargin: 17
anchors.rightMargin: 17
anchors.topMargin: 5 anchors.topMargin: 5
placeholderText: "4..." placeholderText: "4..."
// validator: RegExpValidator { regExp: /[0-9A-Fa-f]{95}/g } // 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 { Label {
id: paymentIdLabel id: paymentIdLabel
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: addressLine.bottom anchors.top: addressLineRow.bottom
anchors.leftMargin: 17 anchors.leftMargin: 17
anchors.rightMargin: 17 anchors.rightMargin: 17
anchors.topMargin: 17 anchors.topMargin: 17

View file

@ -227,6 +227,14 @@ double WalletManager::miningHashRate() const
return m_pimpl->miningHashRate(); 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) void WalletManager::setLogLevel(int logLevel)
{ {
Monero::WalletManagerFactory::setLogLevel(logLevel); Monero::WalletManagerFactory::setLogLevel(logLevel);

View file

@ -116,6 +116,8 @@ public:
Q_INVOKABLE double getPasswordStrength(const QString &password) const; Q_INVOKABLE double getPasswordStrength(const QString &password) const;
Q_INVOKABLE QString resolveOpenAlias(const QString &address) const;
signals: signals:
void walletOpened(Wallet * wallet); void walletOpened(Wallet * wallet);