Skip to content

Commit 2b2ffe7

Browse files
committed
add multi-URI support
1 parent 7fe199f commit 2b2ffe7

File tree

9 files changed

+701
-43
lines changed

9 files changed

+701
-43
lines changed

src/simplewallet/simplewallet.cpp

Lines changed: 91 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include "multisig/multisig.h"
7474
#include "wallet/wallet_args.h"
7575
#include "wallet/fee_priority.h"
76+
#include "wallet/uri.hpp"
7677
#include "version.h"
7778
#include <stdexcept>
7879
#include "wallet/message_store.h"
@@ -6479,15 +6480,18 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
64796480
{
64806481
std::string payment_id_str = local_args.back();
64816482
crypto::hash payment_id;
6482-
bool r = true;
64836483
if (tools::wallet2::parse_long_payment_id(payment_id_str, payment_id))
64846484
{
64856485
LONG_PAYMENT_ID_SUPPORT_CHECK();
6486-
}
6487-
if(!r)
6488-
{
6489-
fail_msg_writer() << tr("payment id failed to encode");
6490-
return false;
6486+
std::string extra_nonce;
6487+
set_payment_id_to_tx_extra_nonce(extra_nonce, payment_id);
6488+
if (!add_extra_nonce_to_tx_extra(extra, extra_nonce))
6489+
{
6490+
fail_msg_writer() << tr("failed to set up payment id");
6491+
return false;
6492+
}
6493+
payment_id_seen = true;
6494+
local_args.pop_back();
64916495
}
64926496
}
64936497

@@ -6514,6 +6518,7 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
65146518

65156519
vector<cryptonote::address_parse_info> dsts_info;
65166520
vector<cryptonote::tx_destination_entry> dsts;
6521+
std::string tx_description;
65176522
for (size_t i = 0; i < local_args.size(); )
65186523
{
65196524
dsts_info.emplace_back();
@@ -6522,25 +6527,66 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
65226527
bool r = true;
65236528

65246529
// check for a URI
6525-
std::string address_uri, payment_id_uri, tx_description, recipient_name, error;
6526-
std::vector<std::string> unknown_parameters;
6527-
uint64_t amount = 0;
6528-
bool has_uri = m_wallet->parse_uri(local_args[i], address_uri, payment_id_uri, amount, tx_description, recipient_name, unknown_parameters, error);
6530+
std::string error;
6531+
std::vector<std::string> unknown_parameters, addresses, recipient_names;
6532+
std::vector<uint64_t> amounts;
6533+
bool has_uri = parse_uri(local_args[i], addresses, amounts, recipient_names, tx_description, unknown_parameters, error);
65296534
if (has_uri)
65306535
{
6531-
r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), address_uri, oa_prompter);
6532-
if (payment_id_uri.size() == 16)
6536+
std::string payment_id_uri;
6537+
for (auto &unknown_parameter : unknown_parameters)
65336538
{
6534-
if (!tools::wallet2::parse_short_payment_id(payment_id_uri, info.payment_id))
6539+
if (boost::starts_with(unknown_parameter, "tx_payment_id="))
65356540
{
6536-
fail_msg_writer() << tr("failed to parse short payment ID from URI");
6541+
payment_id_uri = unknown_parameter.substr(sizeof("tx_payment_id=")-1);
6542+
}
6543+
}
6544+
bool payment_id_used = false;
6545+
for (size_t j = 0; j < addresses.size(); ++j)
6546+
{
6547+
r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), addresses[j], oa_prompter);
6548+
if (!r)
6549+
{
6550+
fail_msg_writer() << tr("failed to parse address");
65376551
return false;
65386552
}
6539-
info.has_payment_id = true;
6553+
6554+
if (!payment_id_uri.empty() && !payment_id_used)
6555+
{
6556+
if (payment_id_seen)
6557+
{
6558+
fail_msg_writer() << tr("a single transaction cannot use more than one payment id");
6559+
return false;
6560+
}
6561+
if (payment_id_uri.size() == 16)
6562+
{
6563+
if (!tools::wallet2::parse_short_payment_id(payment_id_uri, info.payment_id))
6564+
{
6565+
fail_msg_writer() << tr("failed to parse short payment ID from URI");
6566+
return false;
6567+
}
6568+
info.has_payment_id = true;
6569+
std::string extra_nonce;
6570+
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
6571+
if (!add_extra_nonce_to_tx_extra(extra, extra_nonce))
6572+
{
6573+
fail_msg_writer() << tr("failed to set up payment id");
6574+
return false;
6575+
}
6576+
}
6577+
payment_id_seen = true;
6578+
}
6579+
payment_id_used = true;
6580+
6581+
de.amount = amounts[j];
6582+
de.original = addresses[j];
6583+
de.addr = info.address;
6584+
de.is_subaddress = info.is_subaddress;
6585+
de.is_integrated = info.has_payment_id;
6586+
dsts.push_back(de);
65406587
}
6541-
de.amount = amount;
6542-
de.original = local_args[i];
65436588
++i;
6589+
continue;
65446590
}
65456591
else if (i + 1 < local_args.size())
65466592
{
@@ -6573,33 +6619,18 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
65736619
de.is_subaddress = info.is_subaddress;
65746620
de.is_integrated = info.has_payment_id;
65756621

6576-
if (info.has_payment_id || !payment_id_uri.empty())
6622+
if (info.has_payment_id)
65776623
{
65786624
if (payment_id_seen)
65796625
{
65806626
fail_msg_writer() << tr("a single transaction cannot use more than one payment id");
65816627
return false;
65826628
}
6583-
6584-
crypto::hash payment_id;
65856629
std::string extra_nonce;
6586-
if (info.has_payment_id)
6630+
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
6631+
if (!add_extra_nonce_to_tx_extra(extra, extra_nonce))
65876632
{
6588-
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
6589-
}
6590-
else if (tools::wallet2::parse_payment_id(payment_id_uri, payment_id))
6591-
{
6592-
LONG_PAYMENT_ID_SUPPORT_CHECK();
6593-
}
6594-
else
6595-
{
6596-
fail_msg_writer() << tr("failed to parse payment id, though it was detected");
6597-
return false;
6598-
}
6599-
bool r = add_extra_nonce_to_tx_extra(extra, extra_nonce);
6600-
if(!r)
6601-
{
6602-
fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
6633+
fail_msg_writer() << tr("failed to set up payment id");
66036634
return false;
66046635
}
66056636
payment_id_seen = true;
@@ -6747,6 +6778,7 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
67476778
}
67486779
}
67496780

6781+
auto backup_ptx_vector = ptx_vector;
67506782
// actually commit the transactions
67516783
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
67526784
if (ms_status.multisig_is_active && called_by_mms)
@@ -6812,6 +6844,15 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
68126844
{
68136845
commit_or_save(ptx_vector, m_do_not_relay);
68146846
}
6847+
6848+
if (!tx_description.empty())
6849+
{
6850+
for (const auto &ptx : backup_ptx_vector)
6851+
{
6852+
crypto::hash txid = get_transaction_hash(ptx.tx);
6853+
m_wallet->set_tx_note(txid, tx_description);
6854+
}
6855+
}
68156856
}
68166857
catch (const std::exception &e)
68176858
{
@@ -8699,12 +8740,21 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
86998740
std::string destinations = "-";
87008741
if (!transfer.outputs.empty())
87018742
{
8702-
destinations = "";
8703-
for (const auto& output : transfer.outputs)
8743+
if (transfer.outputs.size() == 1)
87048744
{
8705-
if (!destinations.empty())
8706-
destinations += ", ";
8707-
destinations += (transfer.direction == "in" ? output.first.substr(0, 6) : output.first) + ":" + print_money(output.second);
8745+
destinations = (transfer.direction == "in" ? transfer.outputs[0].first.substr(0, 6) : transfer.outputs[0].first);
8746+
}
8747+
else
8748+
{
8749+
destinations.clear();
8750+
for (const auto& output : transfer.outputs)
8751+
{
8752+
if (!destinations.empty())
8753+
{
8754+
destinations += ", ";
8755+
}
8756+
destinations += (transfer.direction == "in" ? output.first.substr(0, 6) : output.first) + ":" + print_money(output.second);
8757+
}
87088758
}
87098759
}
87108760

0 commit comments

Comments
 (0)