Skip to content

Commit a64336b

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

File tree

9 files changed

+697
-43
lines changed

9 files changed

+697
-43
lines changed

src/simplewallet/simplewallet.cpp

Lines changed: 90 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6479,15 +6479,18 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
64796479
{
64806480
std::string payment_id_str = local_args.back();
64816481
crypto::hash payment_id;
6482-
bool r = true;
64836482
if (tools::wallet2::parse_long_payment_id(payment_id_str, payment_id))
64846483
{
64856484
LONG_PAYMENT_ID_SUPPORT_CHECK();
6486-
}
6487-
if(!r)
6488-
{
6489-
fail_msg_writer() << tr("payment id failed to encode");
6490-
return false;
6485+
std::string extra_nonce;
6486+
set_payment_id_to_tx_extra_nonce(extra_nonce, payment_id);
6487+
if (!add_extra_nonce_to_tx_extra(extra, extra_nonce))
6488+
{
6489+
fail_msg_writer() << tr("failed to set up payment id");
6490+
return false;
6491+
}
6492+
payment_id_seen = true;
6493+
local_args.pop_back();
64916494
}
64926495
}
64936496

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

65156518
vector<cryptonote::address_parse_info> dsts_info;
65166519
vector<cryptonote::tx_destination_entry> dsts;
6520+
std::string tx_description;
65176521
for (size_t i = 0; i < local_args.size(); )
65186522
{
65196523
dsts_info.emplace_back();
@@ -6522,25 +6526,66 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
65226526
bool r = true;
65236527

65246528
// 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);
6529+
std::string error;
6530+
std::vector<std::string> unknown_parameters, addresses, recipient_names;
6531+
std::vector<uint64_t> amounts;
6532+
bool has_uri = parse_uri(local_args[i], addresses, amounts, recipient_names, tx_description, unknown_parameters, error);
65296533
if (has_uri)
65306534
{
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)
6535+
std::string payment_id_uri;
6536+
for (auto &unknown_parameter : unknown_parameters)
65336537
{
6534-
if (!tools::wallet2::parse_short_payment_id(payment_id_uri, info.payment_id))
6538+
if (boost::starts_with(unknown_parameter, "tx_payment_id="))
65356539
{
6536-
fail_msg_writer() << tr("failed to parse short payment ID from URI");
6540+
payment_id_uri = unknown_parameter.substr(sizeof("tx_payment_id=")-1);
6541+
}
6542+
}
6543+
bool payment_id_used = false;
6544+
for (size_t j = 0; j < addresses.size(); ++j)
6545+
{
6546+
r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), addresses[j], oa_prompter);
6547+
if (!r)
6548+
{
6549+
fail_msg_writer() << tr("failed to parse address");
65376550
return false;
65386551
}
6539-
info.has_payment_id = true;
6552+
6553+
if (!payment_id_uri.empty() && !payment_id_used)
6554+
{
6555+
if (payment_id_seen)
6556+
{
6557+
fail_msg_writer() << tr("a single transaction cannot use more than one payment id");
6558+
return false;
6559+
}
6560+
if (payment_id_uri.size() == 16)
6561+
{
6562+
if (!tools::wallet2::parse_short_payment_id(payment_id_uri, info.payment_id))
6563+
{
6564+
fail_msg_writer() << tr("failed to parse short payment ID from URI");
6565+
return false;
6566+
}
6567+
info.has_payment_id = true;
6568+
std::string extra_nonce;
6569+
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
6570+
if (!add_extra_nonce_to_tx_extra(extra, extra_nonce))
6571+
{
6572+
fail_msg_writer() << tr("failed to set up payment id");
6573+
return false;
6574+
}
6575+
}
6576+
payment_id_seen = true;
6577+
}
6578+
payment_id_used = true;
6579+
6580+
de.amount = amounts[j];
6581+
de.original = addresses[j];
6582+
de.addr = info.address;
6583+
de.is_subaddress = info.is_subaddress;
6584+
de.is_integrated = info.has_payment_id;
6585+
dsts.push_back(de);
65406586
}
6541-
de.amount = amount;
6542-
de.original = local_args[i];
65436587
++i;
6588+
continue;
65446589
}
65456590
else if (i + 1 < local_args.size())
65466591
{
@@ -6573,33 +6618,18 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
65736618
de.is_subaddress = info.is_subaddress;
65746619
de.is_integrated = info.has_payment_id;
65756620

6576-
if (info.has_payment_id || !payment_id_uri.empty())
6621+
if (info.has_payment_id)
65776622
{
65786623
if (payment_id_seen)
65796624
{
65806625
fail_msg_writer() << tr("a single transaction cannot use more than one payment id");
65816626
return false;
65826627
}
6583-
6584-
crypto::hash payment_id;
65856628
std::string extra_nonce;
6586-
if (info.has_payment_id)
6629+
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
6630+
if (!add_extra_nonce_to_tx_extra(extra, extra_nonce))
65876631
{
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");
6632+
fail_msg_writer() << tr("failed to set up payment id");
66036633
return false;
66046634
}
66056635
payment_id_seen = true;
@@ -6747,6 +6777,7 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
67476777
}
67486778
}
67496779

6780+
auto backup_ptx_vector = ptx_vector;
67506781
// actually commit the transactions
67516782
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
67526783
if (ms_status.multisig_is_active && called_by_mms)
@@ -6812,6 +6843,15 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
68126843
{
68136844
commit_or_save(ptx_vector, m_do_not_relay);
68146845
}
6846+
6847+
if (!tx_description.empty())
6848+
{
6849+
for (const auto &ptx : backup_ptx_vector)
6850+
{
6851+
crypto::hash txid = get_transaction_hash(ptx.tx);
6852+
m_wallet->set_tx_note(txid, tx_description);
6853+
}
6854+
}
68156855
}
68166856
catch (const std::exception &e)
68176857
{
@@ -8699,12 +8739,21 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
86998739
std::string destinations = "-";
87008740
if (!transfer.outputs.empty())
87018741
{
8702-
destinations = "";
8703-
for (const auto& output : transfer.outputs)
8742+
if (transfer.outputs.size() == 1)
87048743
{
8705-
if (!destinations.empty())
8706-
destinations += ", ";
8707-
destinations += (transfer.direction == "in" ? output.first.substr(0, 6) : output.first) + ":" + print_money(output.second);
8744+
destinations = (transfer.direction == "in" ? transfer.outputs[0].first.substr(0, 6) : transfer.outputs[0].first);
8745+
}
8746+
else
8747+
{
8748+
destinations.clear();
8749+
for (const auto& output : transfer.outputs)
8750+
{
8751+
if (!destinations.empty())
8752+
{
8753+
destinations += ", ";
8754+
}
8755+
destinations += (transfer.direction == "in" ? output.first.substr(0, 6) : output.first) + ":" + print_money(output.second);
8756+
}
87088757
}
87098758
}
87108759

0 commit comments

Comments
 (0)