From f437cb58bf4556ecd18e570a89036c590ff2c997 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 17:38:15 -0400 Subject: [PATCH] Simplewallet should now resolve urls to addresses Simplewallet should now do a DNS query on an address if it fails to convert the given string to a binary representation of an address (base58->binary). It will prompt the user, telling of what the "url" passed was, what monero address it translated to, and whether or not DNSSEC validation was a success, and ask for a confirmation that these are all acceptable. --- src/simplewallet/simplewallet.cpp | 55 +++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index fbe7c473..07b2f793 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -910,8 +911,58 @@ bool simple_wallet::transfer(const std::vector &args_) cryptonote::tx_destination_entry de; if(!get_account_address_from_str(de.addr, m_wallet->testnet(), local_args[i])) { - fail_msg_writer() << "wrong address: " << local_args[i]; - return true; + // if treating as an address fails, try as url + bool dnssec_ok = false; + std::string addr_from_dns; + std::string url = local_args[i]; + + // attempt to get address from dns query + addr_from_dns = tools::wallet2::address_from_url(url, dnssec_ok); + + // if string not empty, see if it's an address + if (addr_from_dns.size()) + { + if (get_account_address_from_str(de.addr, addr_from_dns)) + { + // if it was an address, prompt user for confirmation. + // inform user of DNSSEC validation status as well. + + std::string dnssec_str; + if (dnssec_ok) + { + dnssec_str = "DNSSEC validation PASSED!"; + } + else + { + dnssec_str = "DNSSEC validation FAILED!"; + } + std::stringstream prompt; + prompt << "For URL: " << url + << "," << dnssec_str + << " Monero Address = " << addr_from_dns + << std::endl + << "Is this OK? (Y/n) " + ; + + // prompt the user for confirmation given the dns query and dnssec status + std::string confirm_dns_ok = command_line::input_line(prompt.str()); + if (confirm_dns_ok != "Y" && confirm_dns_ok != "y" && confirm_dns_ok != "Yes" && confirm_dns_ok != "yes") + { + fail_msg_writer() << "User terminated transfer request, disagreed with dns result from url: " << url; + return true; + } + } + else + { + fail_msg_writer() << "Failed to get a monero address from: " << local_args[i]; + return true; + } + } + else + { + fail_msg_writer() << "wrong address: " << local_args[i]; + return true; + } } bool ok = cryptonote::parse_amount(de.amount, local_args[i + 1]);