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.
This commit is contained in:
Thomas Winget 2014-09-17 17:38:15 -04:00 committed by Riccardo Spagni
parent a5757a628f
commit f437cb58bf
1 changed files with 53 additions and 2 deletions

View File

@ -30,6 +30,7 @@
#include <thread> #include <thread>
#include <iostream> #include <iostream>
#include <sstream>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
@ -909,10 +910,60 @@ bool simple_wallet::transfer(const std::vector<std::string> &args_)
{ {
cryptonote::tx_destination_entry de; cryptonote::tx_destination_entry de;
if(!get_account_address_from_str(de.addr, m_wallet->testnet(), local_args[i])) if(!get_account_address_from_str(de.addr, m_wallet->testnet(), local_args[i]))
{
// 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]; fail_msg_writer() << "wrong address: " << local_args[i];
return true; return true;
} }
}
bool ok = cryptonote::parse_amount(de.amount, local_args[i + 1]); bool ok = cryptonote::parse_amount(de.amount, local_args[i + 1]);
if(!ok || 0 == de.amount) if(!ok || 0 == de.amount)