Skip to content

Commit

Permalink
remove v2 uri funcs as C++ differs them through function overloading …
Browse files Browse the repository at this point in the history
…anyways
  • Loading branch information
U65535F committed Feb 11, 2025
1 parent 01d3a94 commit 5b1f082
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/simplewallet/simplewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6535,7 +6535,7 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
std::string payment_id_uri, tx_description, error;
std::vector<std::string> unknown_parameters;
std::vector<tools::wallet2::uri_data> uri_data;
bool has_uri = m_wallet->parse_uri_v2(local_args[i], uri_data, payment_id_uri, tx_description, unknown_parameters, error);
bool has_uri = m_wallet->parse_uri(local_args[i], uri_data, payment_id_uri, tx_description, unknown_parameters, error);
if (has_uri)
{

Expand Down
8 changes: 4 additions & 4 deletions src/wallet/api/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2553,19 +2553,19 @@ bool WalletImpl::parse_uri(const std::string& uri, std::string& address, std::st
return m_wallet->parse_uri(uri, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error);
}

bool WalletImpl::parse_uri_v2(const std::string &uri, std::vector<tools::wallet2::uri_data> &data, std::string &payment_id, std::string &tx_description, std::vector<std::string> &unknown_parameters, std::string &error)
bool WalletImpl::parse_uri(const std::string &uri, std::vector<tools::wallet2::uri_data> &data, std::string &payment_id, std::string &tx_description, std::vector<std::string> &unknown_parameters, std::string &error)
{
return m_wallet->parse_uri_v2(uri, data, payment_id, tx_description, unknown_parameters, error);
return m_wallet->parse_uri(uri, data, payment_id, tx_description, unknown_parameters, error);
}

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
{
return m_wallet->make_uri(address, payment_id, amount, tx_description, recipient_name, error);
}

std::string WalletImpl::make_uri_v2(std::vector<tools::wallet2::uri_data> data, const std::string &payment_id, const std::string &tx_description, std::string &error) const
std::string WalletImpl::make_uri(std::vector<tools::wallet2::uri_data> data, const std::string &payment_id, const std::string &tx_description, std::string &error) const
{
return m_wallet->make_uri_v2(data, payment_id, tx_description, error);
return m_wallet->make_uri(data, payment_id, tx_description, error);
}

std::string WalletImpl::getDefaultDataDir() const
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/api/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ class WalletImpl : public Wallet
virtual void startRefresh() override;
virtual void pauseRefresh() override;
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;
virtual bool parse_uri_v2(const std::string &uri, std::vector<tools::wallet2::uri_data> &data, std::string &payment_id, std::string &tx_description, std::vector<std::string> &unknown_parameters, std::string &error);
virtual bool parse_uri(const std::string &uri, std::vector<tools::wallet2::uri_data> &data, std::string &payment_id, std::string &tx_description, std::vector<std::string> &unknown_parameters, std::string &error);
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;
virtual std::string make_uri_v2(std::vector<tools::wallet2::uri_data> data, const std::string &payment_id, const std::string &tx_description, std::string &error) const;
virtual std::string make_uri(std::vector<tools::wallet2::uri_data> data, const std::string &payment_id, const std::string &tx_description, std::string &error) const;
virtual std::string getDefaultDataDir() const override;
virtual bool blackballOutputs(const std::vector<std::string> &outputs, bool add) override;
virtual bool blackballOutput(const std::string &amount, const std::string &offset) override;
Expand Down
10 changes: 5 additions & 5 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14970,7 +14970,7 @@ std::string wallet2::custom_conver_to_url_format(const std::string &uri) const
return result;
}
//----------------------------------------------------------------------------------------------------
std::string wallet2::make_uri_v2(std::vector<uri_data> data, const std::string &payment_id, const std::string &tx_description, std::string &error) const
std::string wallet2::make_uri(std::vector<uri_data> data, const std::string &payment_id, const std::string &tx_description, std::string &error) const
{
if (data.empty())
{
Expand Down Expand Up @@ -15065,10 +15065,10 @@ std::string wallet2::make_uri(const std::string &address, const std::string &pay
std::vector<tools::wallet2::uri_data> data;
data.push_back(entry);

return make_uri_v2(data, payment_id, tx_description, error);
return make_uri(data, payment_id, tx_description, error);
}
//----------------------------------------------------------------------------------------------------
bool wallet2::parse_uri_v2(const std::string &uri, std::vector<uri_data> &data, std::string &payment_id, std::string &tx_description, std::vector<std::string> &unknown_parameters, std::string &error)
bool wallet2::parse_uri(const std::string &uri, std::vector<uri_data> &data, std::string &payment_id, std::string &tx_description, std::vector<std::string> &unknown_parameters, std::string &error)
{
if (uri.substr(0, 7) != "monero:")
{
Expand Down Expand Up @@ -15224,14 +15224,14 @@ bool wallet2::parse_uri_v2(const std::string &uri, std::vector<uri_data> &data,
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)
{
std::vector<tools::wallet2::uri_data> data;
if (!parse_uri_v2(uri, data, payment_id, tx_description, unknown_parameters, error))
if (!parse_uri(uri, data, payment_id, tx_description, unknown_parameters, error))
{
error = "Failed to parse uri";
return false;
}
if (data.size() > 1)
{
error = "Multi-recipient URIs currently unsupported; please use parse_uri_v2";
error = "Multi-recipient URIs currently unsupported in this overload";
return false;
}
address = data[0].address;
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1649,9 +1649,9 @@ namespace tools
std::string decrypt_with_view_secret_key(const std::string &ciphertext, bool authenticated = true) const;

std::string custom_conver_to_url_format(const std::string &uri) const;
std::string make_uri_v2(std::vector<uri_data> data, const std::string &payment_id, const std::string &tx_description, std::string &error) const;
std::string make_uri(std::vector<uri_data> data, const std::string &payment_id, const std::string &tx_description, std::string &error) const;
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;
bool parse_uri_v2(const std::string &uri, std::vector<uri_data> &data, std::string &payment_id, std::string &tx_description, std::vector<std::string> &unknown_parameters, std::string &error);
bool parse_uri(const std::string &uri, std::vector<uri_data> &data, std::string &payment_id, std::string &tx_description, std::vector<std::string> &unknown_parameters, std::string &error);
bool parse_uri(const std::string& uri, std::string& address, std::string& payment_id, uint64_t& amount, std::string& description, std::string& recipient_name, std::vector<std::string>& unknown_parameters, std::string& error);

uint64_t get_blockchain_height_by_date(uint16_t year, uint8_t month, uint8_t day); // 1<=month<=12, 1<=day<=31
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3134,7 +3134,7 @@ namespace tools
entry_data.recipient_name = entry.recipient_name;
data.push_back(entry_data);
}
std::string uri = m_wallet->make_uri_v2(data, req.payment_id, req.tx_description, error);
std::string uri = m_wallet->make_uri(data, req.payment_id, req.tx_description, error);

if (uri.empty())
{
Expand Down Expand Up @@ -3165,7 +3165,7 @@ namespace tools
if (!m_wallet) return not_open(er);
std::string error;
std::vector<tools::wallet2::uri_data> uri_data;
if (!m_wallet->parse_uri_v2(req.uri, uri_data, res.uri.payment_id, res.uri.tx_description, res.unknown_parameters, error))
if (!m_wallet->parse_uri(req.uri, uri_data, res.uri.payment_id, res.uri.tx_description, res.unknown_parameters, error))
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_URI;
er.message = "Error parsing URI: " + error;
Expand Down
28 changes: 14 additions & 14 deletions tests/unit_tests/uri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
bool ret = w.parse_uri(uri, address, payment_id, amount, description, recipient_name, unknown_parameters, error); \
ASSERT_EQ(ret, expected);

#define PARSE_URI_V2(uri, expected) \
#define PARSE_MULTI_URI(uri, expected) \
std::vector<tools::wallet2::uri_data> data; \
std::string payment_id, description, error; \
std::vector<std::string> unknown_parameters; \
tools::wallet2 w(cryptonote::TESTNET); \
bool ret = w.parse_uri_v2(uri, data, payment_id, description, unknown_parameters, error); \
bool ret = w.parse_uri(uri, data, payment_id, description, unknown_parameters, error); \
ASSERT_EQ(ret, expected);

TEST(uri, empty_string)
Expand Down Expand Up @@ -224,15 +224,15 @@ TEST(uri, url_encoded_once)

TEST(uri, multiple_addresses_no_params)
{
PARSE_URI_V2("monero:" TEST_ADDRESS ";" TEST_ADDRESS, true);
PARSE_MULTI_URI("monero:" TEST_ADDRESS ";" TEST_ADDRESS, true);
ASSERT_EQ(data.size(), 2);
ASSERT_EQ(data[0].address, TEST_ADDRESS);
ASSERT_EQ(data[1].address, TEST_ADDRESS);
}

TEST(uri, multiple_addresses_with_amounts)
{
PARSE_URI_V2("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_amount=0.5;0.2", true);
PARSE_MULTI_URI("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_amount=0.5;0.2", true);
ASSERT_EQ(data.size(), 2);
ASSERT_EQ(data[0].address, TEST_ADDRESS);
ASSERT_EQ(data[0].amount, 500000000000);
Expand All @@ -242,7 +242,7 @@ TEST(uri, multiple_addresses_with_amounts)

TEST(uri, multiple_addresses_with_recipient_names)
{
PARSE_URI_V2("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?recipient_name=Alice;Bob", true);
PARSE_MULTI_URI("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?recipient_name=Alice;Bob", true);
ASSERT_EQ(data.size(), 2);
ASSERT_EQ(data[0].address, TEST_ADDRESS);
ASSERT_EQ(data[0].recipient_name, "Alice");
Expand All @@ -252,17 +252,17 @@ TEST(uri, multiple_addresses_with_recipient_names)

TEST(uri, multiple_addresses_with_mismatched_amounts)
{
PARSE_URI_V2("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_amount=0.5", false);
PARSE_MULTI_URI("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_amount=0.5", false);
}

TEST(uri, multiple_addresses_with_mismatched_recipient_names)
{
PARSE_URI_V2("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?recipient_name=Alice", false);
PARSE_MULTI_URI("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?recipient_name=Alice", false);
}

TEST(uri, multiple_addresses_with_partial_params)
{
PARSE_URI_V2("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_amount=0.5;0&recipient_name=Alice;", true);
PARSE_MULTI_URI("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_amount=0.5;0&recipient_name=Alice;", true);
ASSERT_EQ(data.size(), 2);
ASSERT_EQ(data[0].address, TEST_ADDRESS);
ASSERT_EQ(data[0].amount, 500000000000);
Expand All @@ -274,36 +274,36 @@ TEST(uri, multiple_addresses_with_partial_params)

TEST(uri, multiple_addresses_with_unknown_params)
{
PARSE_URI_V2("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?unknown_param=123;456", true);
PARSE_MULTI_URI("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?unknown_param=123;456", true);
ASSERT_EQ(unknown_parameters.size(), 1);
ASSERT_EQ(unknown_parameters[0], "unknown_param=123;456");
}

TEST(uri, multiple_addresses_with_payment_id)
{
PARSE_URI_V2("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_payment_id=1234567890123456789012345678901234567890123456789012345678901234", true);
PARSE_MULTI_URI("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_payment_id=1234567890123456789012345678901234567890123456789012345678901234", true);
ASSERT_EQ(payment_id, "1234567890123456789012345678901234567890123456789012345678901234");
}

TEST(uri, multiple_addresses_with_invalid_payment_id)
{
PARSE_URI_V2("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_payment_id=123456", false);
PARSE_MULTI_URI("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_payment_id=123456", false);
}

TEST(uri, multiple_addresses_with_description)
{
PARSE_URI_V2("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_description=Payment%20for%20services", true);
PARSE_MULTI_URI("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_description=Payment%20for%20services", true);
ASSERT_EQ(description, "Payment for services");
}

TEST(uri, multiple_addresses_mismatched_params)
{
PARSE_URI_V2("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_amount=0.5&recipient_name=Alice", false);
PARSE_MULTI_URI("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_amount=0.5&recipient_name=Alice", false);
}

TEST(uri, multiple_addresses_all_params_correct)
{
PARSE_URI_V2("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_amount=0.5;0.2&recipient_name=Alice;Bob&tx_description=Payment%20for%20services", true);
PARSE_MULTI_URI("monero:" TEST_ADDRESS ";" TEST_ADDRESS "?tx_amount=0.5;0.2&recipient_name=Alice;Bob&tx_description=Payment%20for%20services", true);
ASSERT_EQ(data.size(), 2);
ASSERT_EQ(data[0].address, TEST_ADDRESS);
ASSERT_EQ(data[0].amount, 500000000000);
Expand Down

0 comments on commit 5b1f082

Please sign in to comment.