Skip to content

Commit 31a1b48

Browse files
committed
add multi-URI support
1 parent f90a267 commit 31a1b48

File tree

12 files changed

+621
-62
lines changed

12 files changed

+621
-62
lines changed

src/simplewallet/simplewallet.cpp

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6532,25 +6532,70 @@ 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, recipient_names;
6538+
std::vector<uint64_t> amounts;
6539+
bool has_uri = m_wallet->parse_uri(local_args[i], addresses, amounts, recipient_names, payment_id_uri, tx_description, unknown_parameters, error);
65396540
if (has_uri)
65406541
{
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)
6542+
for (size_t address_index = 0; address_index < addresses.size(); address_index++)
65436543
{
6544-
if (!tools::wallet2::parse_short_payment_id(payment_id_uri, info.payment_id))
6544+
r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), addresses[address_index], oa_prompter);
6545+
if (payment_id_uri.size() == 16)
65456546
{
6546-
fail_msg_writer() << tr("failed to parse short payment ID from URI");
6547+
if (!tools::wallet2::parse_short_payment_id(payment_id_uri, info.payment_id))
6548+
{
6549+
fail_msg_writer() << tr("failed to parse short payment ID from URI");
6550+
return false;
6551+
}
6552+
info.has_payment_id = true;
6553+
}
6554+
de.amount = amounts[address_index];
6555+
de.original = addresses[address_index];
6556+
if (!r)
6557+
{
6558+
fail_msg_writer() << tr("failed to parse address");
65476559
return false;
65486560
}
6549-
info.has_payment_id = true;
6561+
de.addr = info.address;
6562+
de.is_subaddress = info.is_subaddress;
6563+
de.is_integrated = info.has_payment_id;
6564+
6565+
if (info.has_payment_id || !payment_id_uri.empty())
6566+
{
6567+
if (payment_id_seen)
6568+
{
6569+
fail_msg_writer() << tr("a single transaction cannot use more than one payment id");
6570+
return false;
6571+
}
6572+
crypto::hash payment_id;
6573+
std::string extra_nonce;
6574+
if (info.has_payment_id)
6575+
{
6576+
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
6577+
}
6578+
else if (tools::wallet2::parse_payment_id(payment_id_uri, payment_id))
6579+
{
6580+
LONG_PAYMENT_ID_SUPPORT_CHECK();
6581+
}
6582+
else
6583+
{
6584+
fail_msg_writer() << tr("failed to parse payment id, though it was detected");
6585+
return false;
6586+
}
6587+
bool r = add_extra_nonce_to_tx_extra(extra, extra_nonce);
6588+
if(!r)
6589+
{
6590+
fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
6591+
return false;
6592+
}
6593+
payment_id_seen = true;
6594+
}
6595+
dsts.push_back(de);
65506596
}
6551-
de.amount = amount;
6552-
de.original = local_args[i];
6553-
++i;
6597+
i++;
6598+
break;
65546599
}
65556600
else if (i + 1 < local_args.size())
65566601
{

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)