aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorOran Juice <oranjuices@hotmail.com>2014-09-28 15:52:05 +0530
committerOran Juice <oranjuices@hotmail.com>2014-09-28 15:52:05 +0530
commit4f693d715c036346b642298cc94bd4d87c5f35e2 (patch)
treec7f764d9f9d90de3947eff7910901ee3a56212b1 /src/wallet
parentMinor comment changes and code clean-up (diff)
parentRevert "low risk, potentially varint overflow bug patched thanks to BBR" (diff)
downloadmonero-4f693d715c036346b642298cc94bd4d87c5f35e2.tar.xz
Merge with origin/master
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet2.cpp63
-rw-r--r--src/wallet/wallet2.h3
-rw-r--r--src/wallet/wallet_errors.h18
3 files changed, 75 insertions, 9 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 6222b0c03..b8f793d7c 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -47,6 +47,7 @@ using namespace epee;
#include "serialization/binary_utils.h"
#include "cryptonote_protocol/blobdatatype.h"
#include "mnemonics/electrum-words.h"
+#include "common/dns_utils.h"
extern "C"
{
@@ -751,6 +752,7 @@ void wallet2::add_unconfirmed_tx(const cryptonote::transaction& tx, uint64_t cha
utd.m_sent_time = time(NULL);
utd.m_tx = tx;
}
+
//----------------------------------------------------------------------------------------------------
void wallet2::transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, size_t fake_outputs_count,
uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx& ptx)
@@ -815,6 +817,67 @@ std::vector<std::vector<cryptonote::tx_destination_entry>> split_amounts(
}
} // anonymous namespace
+/**
+ * @brief gets a monero address from the TXT record of a DNS entry
+ *
+ * gets the monero address from the TXT record of the DNS entry associated
+ * with <url>. If this lookup fails, or the TXT record does not contain an
+ * XMR address in the correct format, returns an empty string. <dnssec_valid>
+ * will be set true or false according to whether or not the DNS query passes
+ * DNSSEC validation.
+ *
+ * @param url the url to look up
+ * @param dnssec_valid return-by-reference for DNSSEC status of query
+ *
+ * @return a monero address (as a string) or an empty string
+ */
+std::vector<std::string> wallet2::addresses_from_url(const std::string& url, bool& dnssec_valid)
+{
+ // TODO: update this correctly once DNSResolver::get_txt_record() supports it.
+ dnssec_valid = false;
+
+ std::vector<std::string> addresses;
+ // get txt records
+ auto records = tools::DNSResolver::instance().get_txt_record(url);
+
+ // for each txt record, try to find a monero address in it.
+ for (auto& rec : records)
+ {
+ std::string addr = address_from_txt_record(rec);
+ if (addr.size())
+ {
+ addresses.push_back(addr);
+ }
+ }
+
+ return addresses;
+}
+
+//----------------------------------------------------------------------------------------------------
+// TODO: parse the string in a less stupid way, probably with regex
+std::string wallet2::address_from_txt_record(const std::string& s)
+{
+ // make sure the txt record has "oa1:xmr" and find it
+ auto pos = s.find("oa1:xmr");
+
+ // search from there to find "recipient_address="
+ pos = s.find("recipient_address=", pos);
+
+ pos += 18; // move past "recipient_address="
+
+ // find the next semicolon
+ auto pos2 = s.find(";", pos);
+ if (pos2 != std::string::npos)
+ {
+ // length of address == 95, we can at least validate that much here
+ if (pos2 - pos == 95)
+ {
+ return s.substr(pos, 95);
+ }
+ }
+ return std::string();
+}
+
//----------------------------------------------------------------------------------------------------
// take a pending tx and actually send it to the daemon
void wallet2::commit_tx(pending_tx& ptx)
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 3311e3438..90918677e 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -196,6 +196,9 @@ namespace tools
static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);
+ static std::vector<std::string> addresses_from_url(const std::string& url, bool& dnssec_valid);
+
+ static std::string address_from_txt_record(const std::string& s);
private:
bool store_keys(const std::string& keys_file_name, const std::string& password);
void load_keys(const std::string& keys_file_name, const std::string& password);
diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h
index 7914ff8e1..ebec931e4 100644
--- a/src/wallet/wallet_errors.h
+++ b/src/wallet/wallet_errors.h
@@ -383,11 +383,11 @@ namespace tools
, uint64_t unlock_time
, bool testnet
)
- : transfer_error {std::move(loc), "transaction was not constructed"}
- , m_sources {sources}
- , m_destinations {destinations}
- , m_unlock_time {unlock_time}
- , m_testnet {testnet}
+ : transfer_error(std::move(loc), "transaction was not constructed")
+ , m_sources(sources)
+ , m_destinations(destinations)
+ , m_unlock_time(unlock_time)
+ , m_testnet(testnet)
{
}
@@ -471,10 +471,10 @@ namespace tools
, uint64_t fee
, bool testnet
)
- : transfer_error {std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits<uint64_t>::max())}
- , m_destinations {destinations}
- , m_fee {fee}
- , m_testnet {testnet}
+ : transfer_error(std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits<uint64_t>::max()))
+ , m_destinations(destinations)
+ , m_fee(fee)
+ , m_testnet(testnet)
{
}