aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Winget <tewinget@gmail.com>2014-09-17 17:38:15 -0400
committerRiccardo Spagni <ric@spagni.net>2014-09-23 22:58:25 +0200
commitf437cb58bf4556ecd18e570a89036c590ff2c997 (patch)
tree7480ff3ead4fad34ad98676fbf9fee34ad05dce7
parentMonero addres from DNS TXT record implemented, tests pass (diff)
downloadmonero-f437cb58bf4556ecd18e570a89036c590ff2c997.tar.xz
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.
-rw-r--r--src/simplewallet/simplewallet.cpp55
1 files changed, 53 insertions, 2 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index fbe7c4730..07b2f7935 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -30,6 +30,7 @@
#include <thread>
#include <iostream>
+#include <sstream>
#include <boost/lexical_cast.hpp>
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
@@ -910,8 +911,58 @@ bool simple_wallet::transfer(const std::vector<std::string> &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]);