Skip to content

Commit

Permalink
Move overloads to wallet2.cpp. Introduce backwards compatibility in w…
Browse files Browse the repository at this point in the history
…allet.py for handling both new and old formats plus rewrite uri.py to handle tests properly. Rewrite was necessary to remove all broken tests written previously, restore the file and modify the way it accesses data (the structure is different).
  • Loading branch information
U65535F committed Feb 1, 2025
1 parent 546fb29 commit 993ebfc
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 199 deletions.
34 changes: 11 additions & 23 deletions src/wallet/api/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2548,35 +2548,23 @@ bool WalletImpl::checkBackgroundSync(const std::string &message) const
return false;
}

bool WalletImpl::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)
bool WalletImpl::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)
{
std::vector<tools::wallet2::uri_data> data;
if (!m_wallet->parse_uri(uri, data, payment_id, tx_description, unknown_parameters, error))
{
setStatusError(tr("Failed to parse uri"));
return false;
}
if (data.size() > 1)
{
setStatusError(tr("Multi-recipient URIs currently unsupported"));
return false;
}
address = data[0].address;
amount = data[0].amount;
recipient_name = data[0].recipient_name;
return true;
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
bool WalletImpl::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)
{
tools::wallet2::uri_data entry;
entry.address = address;
entry.amount = amount;
entry.recipient_name = recipient_name;
return m_wallet->parse_uri(uri, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error);
}

std::vector<tools::wallet2::uri_data> data;
data.push_back(entry);
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(std::vector<uri_data> data, const std::string &payment_id, const std::string &tx_description, std::string &error) const
{
return m_wallet->make_uri(data, payment_id, tx_description, error);
}

Expand Down
22 changes: 19 additions & 3 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6236,9 +6236,6 @@ std::string wallet2::make_background_keys_file_name(const std::string &wallet_fi
//----------------------------------------------------------------------------------------------------
bool wallet2::parse_long_payment_id(const std::string& payment_id_str, crypto::hash& payment_id)
{
if (payment_id_str.size() != 64)
return false;

cryptonote::blobdata payment_id_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(payment_id_str, payment_id_data))
return false;
Expand Down Expand Up @@ -15030,6 +15027,19 @@ std::string wallet2::make_uri(std::vector<uri_data> data, const std::string &pay
return uri;
}
//----------------------------------------------------------------------------------------------------
std::string wallet2::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
{
tools::wallet2::uri_data entry;
entry.address = address;
entry.amount = amount;
entry.recipient_name = recipient_name;

std::vector<tools::wallet2::uri_data> data;
data.push_back(entry);

return make_uri(data, payment_id, tx_description, 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 @@ -15117,13 +15127,19 @@ bool wallet2::parse_uri(const std::string &uri, std::vector<uri_data> &data, std
else if (kv[0] == "tx_payment_id")
{
// standalone payment ids are deprecated. use integrated address
error = "Standalone payment id deprecated, use integrated address instead";
return false;

/*
// Commenting this code to save for any unforeseen future use.
crypto::hash hash;
if (!wallet2::parse_long_payment_id(kv[1], hash))
{
error = "Invalid payment id: " + kv[1];
return false;
}
payment_id = kv[1];
*/
}
else if (kv[0] == "recipient_name")
{
Expand Down
Loading

0 comments on commit 993ebfc

Please sign in to comment.