aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/wallet2.cpp')
-rw-r--r--src/wallet/wallet2.cpp166
1 files changed, 156 insertions, 10 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index ea3994435..2d293d45c 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -191,8 +191,7 @@ boost::optional<tools::password_container> get_password(const boost::program_opt
}
// Remove line breaks the user might have inserted
- password.erase(std::remove(password.end() - 1, password.end(), '\n'), password.end());
- password.erase(std::remove(password.end() - 1, password.end(), '\r'), password.end());
+ boost::trim_right_if(password, boost::is_any_of("\r\n"));
return {tools::password_container(std::move(password))};
}
@@ -2221,7 +2220,7 @@ bool wallet2::prepare_file_names(const std::string& file_path)
return true;
}
//----------------------------------------------------------------------------------------------------
-bool wallet2::check_connection(bool *same_version)
+bool wallet2::check_connection(uint32_t *version)
{
boost::lock_guard<boost::mutex> lock(m_daemon_rpc_mutex);
@@ -2239,7 +2238,7 @@ bool wallet2::check_connection(bool *same_version)
return false;
}
- if (same_version)
+ if (version)
{
epee::json_rpc::request<cryptonote::COMMAND_RPC_GET_VERSION::request> req_t = AUTO_VAL_INIT(req_t);
epee::json_rpc::response<cryptonote::COMMAND_RPC_GET_VERSION::response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
@@ -2248,9 +2247,9 @@ bool wallet2::check_connection(bool *same_version)
req_t.method = "get_version";
bool r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/json_rpc", req_t, resp_t, m_http_client);
if (!r || resp_t.result.status != CORE_RPC_STATUS_OK)
- *same_version = false;
+ *version = 0;
else
- *same_version = resp_t.result.version == CORE_RPC_VERSION;
+ *version = resp_t.result.version;
}
return true;
@@ -2348,11 +2347,16 @@ void wallet2::load(const std::string& wallet_, const std::string& password)
}
//----------------------------------------------------------------------------------------------------
void wallet2::check_genesis(const crypto::hash& genesis_hash) const {
- std::string what("Genesis block missmatch. You probably use wallet without testnet flag with blockchain from test network or vice versa");
+ std::string what("Genesis block mismatch. You probably use wallet without testnet flag with blockchain from test network or vice versa");
THROW_WALLET_EXCEPTION_IF(genesis_hash != m_blockchain[0], error::wallet_internal_error, what);
}
//----------------------------------------------------------------------------------------------------
+std::string wallet2::path() const
+{
+ return m_wallet_file;
+}
+//----------------------------------------------------------------------------------------------------
void wallet2::store()
{
store_to("", "");
@@ -3851,12 +3855,12 @@ static size_t estimate_rct_tx_size(int n_inputs, int mixin, int n_outputs)
return size;
}
-std::vector<size_t> wallet2::pick_prefered_rct_inputs(uint64_t needed_money) const
+std::vector<size_t> wallet2::pick_preferred_rct_inputs(uint64_t needed_money) const
{
std::vector<size_t> picks;
float current_output_relatdness = 1.0f;
- LOG_PRINT_L2("pick_prefered_rct_inputs: needed_money " << print_money(needed_money));
+ LOG_PRINT_L2("pick_preferred_rct_inputs: needed_money " << print_money(needed_money));
// try to find a rct input of enough size
for (size_t i = 0; i < m_transfers.size(); ++i)
@@ -4019,7 +4023,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
// this is used to build a tx that's 1 or 2 inputs, and 2 outputs, which
// will get us a known fee.
uint64_t estimated_fee = calculate_fee(fee_per_kb, estimate_rct_tx_size(2, fake_outs_count + 1, 2), fee_multiplier);
- prefered_inputs = pick_prefered_rct_inputs(needed_money + estimated_fee);
+ prefered_inputs = pick_preferred_rct_inputs(needed_money + estimated_fee);
if (!prefered_inputs.empty())
{
string s;
@@ -4989,6 +4993,148 @@ std::string wallet2::decrypt_with_view_secret_key(const std::string &ciphertext,
return decrypt(ciphertext, get_account().get_keys().m_view_secret_key, authenticated);
}
//----------------------------------------------------------------------------------------------------
+std::string wallet2::make_uri(const std::string &address, const std::string &payment_id, uint64_t amount, const std::string &tx_description, const std::string &recipient_name, std::string &error)
+{
+ cryptonote::account_public_address tmp_address;
+ bool has_payment_id;
+ crypto::hash8 new_payment_id;
+ if(!get_account_integrated_address_from_str(tmp_address, has_payment_id, new_payment_id, testnet(), address))
+ {
+ error = std::string("wrong address: ") + address;
+ return std::string();
+ }
+
+ // we want only one payment id
+ if (has_payment_id && !payment_id.empty())
+ {
+ error = "A single payment id is allowed";
+ return std::string();
+ }
+
+ if (!payment_id.empty())
+ {
+ crypto::hash pid32;
+ crypto::hash8 pid8;
+ if (!wallet2::parse_long_payment_id(payment_id, pid32) && !wallet2::parse_short_payment_id(payment_id, pid8))
+ {
+ error = "Invalid payment id";
+ return std::string();
+ }
+ }
+
+ std::string uri = "monero:" + address;
+ bool n_fields = 0;
+
+ if (!payment_id.empty())
+ {
+ uri += (n_fields++ ? "&" : "?") + std::string("tx_payment_id=") + payment_id;
+ }
+
+ if (amount > 0)
+ {
+ // URI encoded amount is in decimal units, not atomic units
+ uri += (n_fields++ ? "&" : "?") + std::string("tx_amount=") + cryptonote::print_money(amount);
+ }
+
+ if (!recipient_name.empty())
+ {
+ uri += (n_fields++ ? "&" : "?") + std::string("recipient_name=") + epee::net_utils::conver_to_url_format(recipient_name);
+ }
+
+ if (!tx_description.empty())
+ {
+ uri += (n_fields++ ? "&" : "?") + std::string("tx_description=") + epee::net_utils::conver_to_url_format(tx_description);
+ }
+
+ return uri;
+}
+//----------------------------------------------------------------------------------------------------
+bool wallet2::parse_uri(const std::string &uri, std::string &address, std::string &payment_id, uint64_t &amount, std::string &tx_description, std::string &recipient_name, std::vector<std::string> &unknown_parameters, std::string &error)
+{
+ if (uri.substr(0, 7) != "monero:")
+ {
+ error = std::string("URI has wrong scheme (expected \"monero:\"): ") + uri;
+ return false;
+ }
+
+ std::string remainder = uri.substr(7);
+ const char *ptr = strchr(remainder.c_str(), '?');
+ address = ptr ? remainder.substr(0, ptr-remainder.c_str()) : remainder;
+
+ cryptonote::account_public_address addr;
+ bool has_payment_id;
+ crypto::hash8 new_payment_id;
+ if(!get_account_integrated_address_from_str(addr, has_payment_id, new_payment_id, testnet(), address))
+ {
+ error = std::string("URI has wrong address: ") + address;
+ return false;
+ }
+ if (!strchr(remainder.c_str(), '?'))
+ return true;
+
+ std::vector<std::string> arguments;
+ std::string body = remainder.substr(address.size() + 1);
+ if (body.empty())
+ return true;
+ boost::split(arguments, body, boost::is_any_of("&"));
+ std::set<std::string> have_arg;
+ for (const auto &arg: arguments)
+ {
+ std::vector<std::string> kv;
+ boost::split(kv, arg, boost::is_any_of("="));
+ if (kv.size() != 2)
+ {
+ error = std::string("URI has wrong parameter: ") + arg;
+ return false;
+ }
+ if (have_arg.find(kv[0]) != have_arg.end())
+ {
+ error = std::string("URI has more than one instance of " + kv[0]);
+ return false;
+ }
+ have_arg.insert(kv[0]);
+
+ if (kv[0] == "tx_amount")
+ {
+ amount = 0;
+ if (!cryptonote::parse_amount(amount, kv[1]))
+ {
+ error = std::string("URI has invalid amount: ") + kv[1];
+ return false;
+ }
+ }
+ else if (kv[0] == "tx_payment_id")
+ {
+ if (has_payment_id)
+ {
+ error = "Separate payment id given with an integrated address";
+ return false;
+ }
+ crypto::hash hash;
+ crypto::hash8 hash8;
+ if (!wallet2::parse_long_payment_id(kv[1], hash) && !wallet2::parse_short_payment_id(kv[1], hash8))
+ {
+ error = "Invalid payment id: " + kv[1];
+ return false;
+ }
+ payment_id = kv[1];
+ }
+ else if (kv[0] == "recipient_name")
+ {
+ recipient_name = epee::net_utils::convert_from_url_format(kv[1]);
+ }
+ else if (kv[0] == "tx_description")
+ {
+ tx_description = epee::net_utils::convert_from_url_format(kv[1]);
+ }
+ else
+ {
+ unknown_parameters.push_back(arg);
+ }
+ }
+ return true;
+}
+//----------------------------------------------------------------------------------------------------
void wallet2::generate_genesis(cryptonote::block& b) {
if (m_testnet)
{