Skip to content

Commit 857b2fe

Browse files
committed
add multi-URI support
1 parent f90a267 commit 857b2fe

File tree

12 files changed

+614
-63
lines changed

12 files changed

+614
-63
lines changed

src/simplewallet/simplewallet.cpp

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6532,25 +6532,71 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
65326532
bool r = true;
65336533

65346534
// check for a URI
6535-
std::string address_uri, payment_id_uri, tx_description, recipient_name, error;
6535+
std::string payment_id_uri, tx_description, error;
65366536
std::vector<std::string> unknown_parameters;
6537-
uint64_t amount = 0;
6538-
bool has_uri = m_wallet->parse_uri(local_args[i], address_uri, payment_id_uri, amount, tx_description, recipient_name, unknown_parameters, error);
6537+
std::vector<std::string> addresses;
6538+
std::vector<uint64_t> amounts;
6539+
std::vector<std::string> recipient_names;
6540+
bool has_uri = m_wallet->parse_uri(local_args[i], addresses, amounts, recipient_names, payment_id_uri, tx_description, unknown_parameters, error);
65396541
if (has_uri)
65406542
{
6541-
r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), address_uri, oa_prompter);
6542-
if (payment_id_uri.size() == 16)
6543+
for (size_t j = 0; j < addresses.size(); j++)
65436544
{
6544-
if (!tools::wallet2::parse_short_payment_id(payment_id_uri, info.payment_id))
6545+
r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), addresses[j], oa_prompter);
6546+
if (payment_id_uri.size() == 16)
65456547
{
6546-
fail_msg_writer() << tr("failed to parse short payment ID from URI");
6548+
if (!tools::wallet2::parse_short_payment_id(payment_id_uri, info.payment_id))
6549+
{
6550+
fail_msg_writer() << tr("failed to parse short payment ID from URI");
6551+
return false;
6552+
}
6553+
info.has_payment_id = true;
6554+
}
6555+
de.amount = amounts[j];
6556+
de.original = addresses[j];
6557+
if (!r)
6558+
{
6559+
fail_msg_writer() << tr("failed to parse address");
65476560
return false;
65486561
}
6549-
info.has_payment_id = true;
6562+
de.addr = info.address;
6563+
de.is_subaddress = info.is_subaddress;
6564+
de.is_integrated = info.has_payment_id;
6565+
6566+
if (info.has_payment_id || !payment_id_uri.empty())
6567+
{
6568+
if (payment_id_seen)
6569+
{
6570+
fail_msg_writer() << tr("a single transaction cannot use more than one payment id");
6571+
return false;
6572+
}
6573+
crypto::hash payment_id;
6574+
std::string extra_nonce;
6575+
if (info.has_payment_id)
6576+
{
6577+
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
6578+
}
6579+
else if (tools::wallet2::parse_payment_id(payment_id_uri, payment_id))
6580+
{
6581+
LONG_PAYMENT_ID_SUPPORT_CHECK();
6582+
}
6583+
else
6584+
{
6585+
fail_msg_writer() << tr("failed to parse payment id, though it was detected");
6586+
return false;
6587+
}
6588+
bool r = add_extra_nonce_to_tx_extra(extra, extra_nonce);
6589+
if(!r)
6590+
{
6591+
fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
6592+
return false;
6593+
}
6594+
payment_id_seen = true;
6595+
}
6596+
dsts.push_back(de);
65506597
}
6551-
de.amount = amount;
6552-
de.original = local_args[i];
6553-
++i;
6598+
i++;
6599+
break;
65546600
}
65556601
else if (i + 1 < local_args.size())
65566602
{

src/wallet/api/wallet.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,11 +2553,21 @@ bool WalletImpl::parse_uri(const std::string &uri, std::string &address, std::st
25532553
return m_wallet->parse_uri(uri, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error);
25542554
}
25552555

2556+
bool WalletImpl::parse_uri(const std::string &uri, std::vector<std::string> &addresses, std::vector<std::uint64_t> &amounts, std::vector<std::string> &recipient_names, std::string &payment_id, std::string &tx_description, std::vector<std::string> &unknown_parameters, std::string &error)
2557+
{
2558+
return m_wallet->parse_uri(uri, addresses, amounts, recipient_names, payment_id, tx_description, unknown_parameters, error);
2559+
}
2560+
25562561
std::string WalletImpl::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) const
25572562
{
25582563
return m_wallet->make_uri(address, payment_id, amount, tx_description, recipient_name, error);
25592564
}
25602565

2566+
std::string WalletImpl::make_uri(const std::vector<std::string> &addresses, const std::vector<std::uint64_t> &amounts, const std::vector<std::string> &recipient_names, const std::string &payment_id, const std::string &tx_description, std::string &error) const
2567+
{
2568+
return m_wallet->make_uri(addresses, amounts, recipient_names, payment_id, tx_description, error);
2569+
}
2570+
25612571
std::string WalletImpl::getDefaultDataDir() const
25622572
{
25632573
return tools::get_default_data_dir();

src/wallet/api/wallet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ class WalletImpl : public Wallet
214214
virtual void startRefresh() override;
215215
virtual void pauseRefresh() override;
216216
virtual bool 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) override;
217+
bool parse_uri(const std::string &uri, std::vector<std::string> &addresses, std::vector<std::uint64_t> &amounts, std::vector<std::string> &recipient_names, std::string &payment_id, std::string &tx_description, std::vector<std::string> &unknown_parameters, std::string &error) override;
217218
virtual std::string 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) const override;
219+
std::string make_uri(const std::vector<std::string> &addresses, const std::vector<std::uint64_t> &amounts, const std::vector<std::string> &recipient_names, const std::string &payment_id, const std::string &tx_description, std::string &error) const override;
218220
virtual std::string getDefaultDataDir() const override;
219221
virtual bool blackballOutputs(const std::vector<std::string> &outputs, bool add) override;
220222
virtual bool blackballOutput(const std::string &amount, const std::string &offset) override;

src/wallet/api/wallet2_api.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,8 +1066,11 @@ struct Wallet
10661066
virtual bool verifyMessageWithPublicKey(const std::string &message, const std::string &publicKey, const std::string &signature) const = 0;
10671067

10681068
virtual bool 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) = 0;
1069-
virtual std::string 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) const = 0;
1069+
virtual bool parse_uri(const std::string &uri, std::vector<std::string> &addresses, std::vector<std::uint64_t> &amounts, std::vector<std::string> &recipient_names, std::string &payment_id, std::string &tx_description, std::vector<std::string> &unknown_parameters, std::string &error) = 0;
10701070

1071+
virtual std::string 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) const = 0;
1072+
virtual std::string make_uri(const std::vector<std::string> &addresses, const std::vector<std::uint64_t> &amounts, const std::vector<std::string> &recipient_names, const std::string &payment_id, const std::string &tx_description, std::string &error) const = 0;
1073+
10711074
virtual std::string getDefaultDataDir() const = 0;
10721075

10731076
/*

0 commit comments

Comments
 (0)