Merge pull request #11073

5cc215d wallet: respect --no-dns for OpenAlias (Samy)

ACKs: jpk68, SNeedlewoods, selsta
This commit is contained in:
tobtoht
2026-08-16 15:20:41 +00:00
6 changed files with 55 additions and 17 deletions
@@ -236,9 +236,22 @@ namespace cryptonote {
, const std::string& str_or_url
, std::function<std::string(const std::string&, const std::vector<std::string>&, bool)> dns_confirm
)
{
return get_account_address_from_str_or_url(info, nettype, str_or_url, true, dns_confirm);
}
//--------------------------------------------------------------------------------
bool get_account_address_from_str_or_url(
address_parse_info& info
, network_type nettype
, const std::string& str_or_url
, bool allow_dns
, std::function<std::string(const std::string&, const std::vector<std::string>&, bool)> dns_confirm
)
{
if (get_account_address_from_str(info, nettype, str_or_url))
return true;
if (!allow_dns)
return false;
bool dnssec_valid;
std::string address_str = tools::dns_utils::get_account_address_as_str_from_url(str_or_url, dnssec_valid, dns_confirm);
return !address_str.empty() &&
@@ -90,6 +90,14 @@ namespace cryptonote {
, std::function<std::string(const std::string&, const std::vector<std::string>&, bool)> dns_confirm = return_first_address
);
bool get_account_address_from_str_or_url(
address_parse_info& info
, network_type nettype
, const std::string& str_or_url
, bool allow_dns
, std::function<std::string(const std::string&, const std::vector<std::string>&, bool)> dns_confirm = return_first_address
);
bool is_coinbase(const transaction_prefix& tx);
bool operator ==(const cryptonote::transaction& a, const cryptonote::transaction& b);
+12 -12
View File
@@ -6433,7 +6433,7 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
bool has_uri = m_wallet->parse_uri(local_args[i], address_uri, payment_id_uri, amount, tx_description, recipient_name, unknown_parameters, error);
if (has_uri)
{
r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), address_uri, oa_prompter);
r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), address_uri, m_wallet->is_dns_enabled(), oa_prompter);
if (payment_id_uri.size() == 16)
{
if (!tools::wallet2::parse_short_payment_id(payment_id_uri, info.payment_id))
@@ -6449,7 +6449,7 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
}
else if (i + 1 < local_args.size())
{
r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args[i], oa_prompter);
r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args[i], m_wallet->is_dns_enabled(), oa_prompter);
bool ok = cryptonote::parse_amount(de.amount, local_args[i + 1]);
if(!ok || 0 == de.amount)
{
@@ -6976,7 +6976,7 @@ bool simple_wallet::sweep_main(uint32_t account, uint64_t below, const std::vect
}
cryptonote::address_parse_info info;
if (!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args[0], oa_prompter))
if (!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args[0], m_wallet->is_dns_enabled(), oa_prompter))
{
fail_msg_writer() << tr("failed to parse address");
print_usage();
@@ -7236,7 +7236,7 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
}
cryptonote::address_parse_info info;
if (!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args[1], oa_prompter))
if (!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args[1], m_wallet->is_dns_enabled(), oa_prompter))
{
fail_msg_writer() << tr("failed to parse address");
return true;
@@ -7817,7 +7817,7 @@ bool simple_wallet::set_tx_key(const std::vector<std::string> &args_)
if (local_args.size() > 1)
{
cryptonote::address_parse_info info;
if (cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args.back(), oa_prompter))
if (cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args.back(), m_wallet->is_dns_enabled(), oa_prompter))
{
if (!info.is_subaddress)
{
@@ -7898,7 +7898,7 @@ bool simple_wallet::get_tx_proof(const std::vector<std::string> &args)
}
cryptonote::address_parse_info info;
if(!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), args[1], oa_prompter))
if(!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), args[1], m_wallet->is_dns_enabled(), oa_prompter))
{
fail_msg_writer() << tr("failed to parse address");
return true;
@@ -7966,7 +7966,7 @@ bool simple_wallet::check_tx_key(const std::vector<std::string> &args_)
}
cryptonote::address_parse_info info;
if(!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args[2], oa_prompter))
if(!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args[2], m_wallet->is_dns_enabled(), oa_prompter))
{
fail_msg_writer() << tr("failed to parse address");
return true;
@@ -8030,7 +8030,7 @@ bool simple_wallet::check_tx_proof(const std::vector<std::string> &args)
// parse address
cryptonote::address_parse_info info;
if(!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), args[1], oa_prompter))
if(!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), args[1], m_wallet->is_dns_enabled(), oa_prompter))
{
fail_msg_writer() << tr("failed to parse address");
return true;
@@ -8236,7 +8236,7 @@ bool simple_wallet::check_reserve_proof(const std::vector<std::string> &args)
return true;
cryptonote::address_parse_info info;
if(!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), args[0], oa_prompter))
if(!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), args[0], m_wallet->is_dns_enabled(), oa_prompter))
{
fail_msg_writer() << tr("failed to parse address");
return true;
@@ -9530,7 +9530,7 @@ bool simple_wallet::address_book(const std::vector<std::string> &args/* = std::v
else if (args[0] == "add")
{
cryptonote::address_parse_info info;
if(!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), args[1], oa_prompter))
if(!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), args[1], m_wallet->is_dns_enabled(), oa_prompter))
{
fail_msg_writer() << tr("failed to parse address");
return true;
@@ -9810,7 +9810,7 @@ bool simple_wallet::verify(const std::vector<std::string> &args)
}
cryptonote::address_parse_info info;
if(!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), address_string, oa_prompter))
if(!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), address_string, m_wallet->is_dns_enabled(), oa_prompter))
{
fail_msg_writer() << tr("failed to parse address");
return true;
@@ -10736,7 +10736,7 @@ void simple_wallet::mms_signer(const std::vector<std::string> &args)
if (args.size() == 4)
{
cryptonote::address_parse_info info;
bool ok = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), args[3], oa_prompter);
bool ok = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), args[3], m_wallet->is_dns_enabled(), oa_prompter);
if (!ok)
{
fail_msg_writer() << tr("Invalid Monero address");
+1
View File
@@ -1481,6 +1481,7 @@ private:
uint64_t hash_m_transfers(boost::optional<uint64_t> transfer_height, crypto::hash &hash) const;
void finish_rescan_bc_keep_key_images(uint64_t transfer_height, const crypto::hash &hash);
void enable_dns(bool enable) { m_use_dns = enable; }
bool is_dns_enabled() const { return m_use_dns && !m_offline; }
void set_offline(bool offline = true);
bool is_offline() const { return m_offline; }
+5 -5
View File
@@ -1047,7 +1047,7 @@ namespace tools
cryptonote::address_parse_info info;
cryptonote::tx_destination_entry de;
er.message = "";
if(!get_account_address_from_str_or_url(info, m_wallet->nettype(), it->address,
if(!get_account_address_from_str_or_url(info, m_wallet->nettype(), it->address, m_wallet->is_dns_enabled(),
[&er](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid)->std::string {
if (!dnssec_valid)
{
@@ -2482,7 +2482,7 @@ namespace tools
cryptonote::address_parse_info info;
er.message = "";
if(!get_account_address_from_str_or_url(info, m_wallet->nettype(), req.address,
if(!get_account_address_from_str_or_url(info, m_wallet->nettype(), req.address, m_wallet->is_dns_enabled(),
[&er](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid)->std::string {
if (!dnssec_valid)
{
@@ -3286,7 +3286,7 @@ namespace tools
cryptonote::address_parse_info info;
er.message = "";
if(!get_account_address_from_str_or_url(info, m_wallet->nettype(), req.address,
if(!get_account_address_from_str_or_url(info, m_wallet->nettype(), req.address, m_wallet->is_dns_enabled(),
[&er](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid)->std::string {
if (!dnssec_valid)
{
@@ -3334,7 +3334,7 @@ namespace tools
if (req.set_address)
{
er.message = "";
if(!get_account_address_from_str_or_url(info, m_wallet->nettype(), req.address,
if(!get_account_address_from_str_or_url(info, m_wallet->nettype(), req.address, m_wallet->is_dns_enabled(),
[&er](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid)->std::string {
if (!dnssec_valid)
{
@@ -4734,7 +4734,7 @@ namespace tools
if (req.allow_openalias)
{
std::string address;
res.valid = get_account_address_from_str_or_url(info, net_type.type, req.address,
res.valid = get_account_address_from_str_or_url(info, net_type.type, req.address, !m_wallet || m_wallet->is_dns_enabled(),
[&er, &address](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid)->std::string {
if (!dnssec_valid)
{
+16
View File
@@ -116,3 +116,19 @@ TEST(AddressFromURL, Failure)
ASSERT_EQ(0, addresses.size());
}
TEST(AddressFromURL, Disabled)
{
cryptonote::address_parse_info info;
tools::wallet2 wallet;
wallet.enable_dns(false);
EXPECT_TRUE(cryptonote::get_account_address_from_str_or_url(
info, cryptonote::MAINNET, MONERO_DONATION_ADDR, wallet.is_dns_enabled()));
EXPECT_FALSE(cryptonote::get_account_address_from_str_or_url(
info, cryptonote::MAINNET, "donate.getmonero.org", wallet.is_dns_enabled()));
wallet.enable_dns(true);
wallet.set_offline();
EXPECT_FALSE(wallet.is_dns_enabled());
}