Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple-URI support in parse_uri and make_uri #9756

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
7469d69
Multiple url functionality.
U65535F Jan 28, 2025
d1f69b9
Remove commented line.
U65535F Jan 28, 2025
1b1e930
Fix error by removing repeated code block.
U65535F Jan 28, 2025
168668a
fix no member named errors
U65535F Jan 28, 2025
ab0c39e
Add function overloads for make_uri to make it compatible with older …
U65535F Jan 28, 2025
25b3ef2
Fix tests
U65535F Jan 29, 2025
a55f1f1
Fix function overloads
U65535F Jan 29, 2025
246926a
Fix errors of parse_uri saying that m_wallet was not found.
U65535F Jan 29, 2025
bfa2c35
Add semi-colon
U65535F Jan 29, 2025
cd922c6
Update parse_uri to support single tx
U65535F Jan 29, 2025
0fe95f9
fix parse_uri
U65535F Jan 29, 2025
a5750c5
fix errors
U65535F Jan 29, 2025
4a83b22
fix make_uri
U65535F Jan 30, 2025
6ca8ace
Slight imporvements and fix always failing test code.
U65535F Jan 30, 2025
dab6fe2
Fix tests that were using atomic units in URL. Add parameter consiste…
U65535F Jan 30, 2025
20e6095
Fix failing python functional tests
U65535F Jan 31, 2025
546fb29
fix improper size calc
U65535F Jan 31, 2025
993ebfc
Move overloads to wallet2.cpp. Introduce backwards compatibility in w…
U65535F Feb 1, 2025
577b7ee
Fix function declarations
U65535F Feb 1, 2025
faf7306
fix uri_data not found by replacing it with tools::wallet2::uri_data …
U65535F Feb 1, 2025
48fe7eb
remove override keyword from wallet.h: make_uri and parse_uri
U65535F Feb 1, 2025
9383f36
fix override issue
U65535F Feb 1, 2025
ca7b72e
add semi-colon.
U65535F Feb 2, 2025
a7fbf60
warning fix: loop variable 'entry' creates a copy.
U65535F Feb 2, 2025
df0021e
Merge branch 'master' of https://github.com/U65535F/monero
U65535F Feb 2, 2025
400d812
add const keyword
U65535F Feb 2, 2025
d678eee
allow standalone payment ids (yet not recommended; fallback)
U65535F Feb 2, 2025
bd357c5
Exclude core_tests
U65535F Feb 2, 2025
f0de5c8
fix failing uri.py by properly calling make_uri and parse_uri. restor…
U65535F Feb 2, 2025
c489d7d
introduce a custom convert to url func instead of modifying existing …
U65535F Feb 2, 2025
5911114
fix conver_to_url_format not declared by changing call to epee::net_u…
U65535F Feb 2, 2025
d9a56b8
Remove out of scope payment id check
U65535F Feb 10, 2025
cd59dfa
Introduce v2 versions of make_uri and parse_uri to ensure proper back…
U65535F Feb 11, 2025
6f27307
add new-lines
U65535F Feb 11, 2025
01d3a94
fix occurrences of uri funcs
U65535F Feb 11, 2025
5b1f082
remove v2 uri funcs as C++ differs them through function overloading …
U65535F Feb 11, 2025
0d7cb1a
fix make_uri_v2 and parse_uri_v2 calling make_uri and parse_uri in py…
U65535F Feb 11, 2025
3562a50
fix uri.py not providing payment_id to one of the tests
U65535F Feb 11, 2025
33ad3f0
remove extra new lines in wallet2_api.h
U65535F Feb 11, 2025
1ebba43
Merge branch 'monero-project:master' into master
U65535F Feb 12, 2025
71aa95e
only accept standard types as parameters
U65535F Feb 12, 2025
de28957
Merge branch 'master' of https://github.com/U65535F/monero
U65535F Feb 12, 2025
44b70c1
update wallet2
U65535F Feb 12, 2025
eeb3051
fix typos and overlooked references to old variables
U65535F Feb 12, 2025
bbcc043
fix typos
U65535F Feb 12, 2025
a647610
add const keyword
U65535F Feb 12, 2025
c1964b1
fix const keyword dropping error
U65535F Feb 12, 2025
707700d
remove override keyword
U65535F Feb 12, 2025
952486e
add const keyword to wallet2 interface
U65535F Feb 12, 2025
cc6deca
add const keyword
U65535F Feb 12, 2025
0d8698f
restore unnecessary edits and address sneedlewoods' comments
U65535F Feb 12, 2025
c6f16a6
remove some unnecessary edits and old references to removed variables…
U65535F Feb 12, 2025
1f14a22
fix silly typos
U65535F Feb 12, 2025
9158feb
Merge branch 'monero-project:master' into master
U65535F Feb 14, 2025
e4c0e63
Merge branch 'monero-project:master' into master
U65535F Feb 16, 2025
dedfcec
Merge branch 'monero-project:master' into master
U65535F Feb 17, 2025
b59fc59
Merge branch 'monero-project:master' into master
U65535F Feb 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 58 additions & 11 deletions src/simplewallet/simplewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6532,25 +6532,72 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
bool r = true;

// check for a URI
std::string address_uri, payment_id_uri, tx_description, recipient_name, error;
std::string payment_id_uri, tx_description, error;
std::vector<std::string> unknown_parameters;
uint64_t amount = 0;
bool has_uri = m_wallet->parse_uri(local_args[i], address_uri, payment_id_uri, amount, tx_description, recipient_name, unknown_parameters, error);
std::vector<std::string> addresses;
std::vector<uint64_t> amounts;
std::vector<std::string> recipient_names;
bool has_uri = m_wallet->parse_uri(local_args[i], addresses, amounts, recipient_names, payment_id_uri, tx_description, unknown_parameters, error);
if (has_uri)
{
r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), address_uri, oa_prompter);
if (payment_id_uri.size() == 16)

for (size_t j = 0; j < addresses.size(); j++)
{
if (!tools::wallet2::parse_short_payment_id(payment_id_uri, info.payment_id))
r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), addresses[j], oa_prompter);
if (payment_id_uri.size() == 16)
{
fail_msg_writer() << tr("failed to parse short payment ID from URI");
if (!tools::wallet2::parse_short_payment_id(payment_id_uri, info.payment_id))
{
fail_msg_writer() << tr("failed to parse short payment ID from URI");
return false;
}
info.has_payment_id = true;
}
de.amount = amounts[j];
de.original = addresses[j];
if (!r)
{
fail_msg_writer() << tr("failed to parse address");
return false;
}
info.has_payment_id = true;
de.addr = info.address;
de.is_subaddress = info.is_subaddress;
de.is_integrated = info.has_payment_id;

if (info.has_payment_id || !payment_id_uri.empty())
{
if (payment_id_seen)
{
fail_msg_writer() << tr("a single transaction cannot use more than one payment id");
return false;
}
crypto::hash payment_id;
std::string extra_nonce;
if (info.has_payment_id)
{
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
}
else if (tools::wallet2::parse_payment_id(payment_id_uri, payment_id))
{
LONG_PAYMENT_ID_SUPPORT_CHECK();
}
else
{
fail_msg_writer() << tr("failed to parse payment id, though it was detected");
return false;
}
bool r = add_extra_nonce_to_tx_extra(extra, extra_nonce);
if(!r)
{
fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
return false;
}
payment_id_seen = true;
}
dsts.push_back(de);
}
de.amount = amount;
de.original = local_args[i];
++i;
i++;
break;
}
else if (i + 1 < local_args.size())
{
Expand Down
12 changes: 11 additions & 1 deletion src/wallet/api/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2548,16 +2548,26 @@ 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::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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say this is also unnecessary

{
return m_wallet->parse_uri(uri, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error);
}

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)
{
return m_wallet->parse_uri(uri, addresses, amounts, recipient_names, 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(std::vector<std::string> &addresses, std::vector<std::uint64_t> &amounts, std::vector<std::string> &recipient_names, const std::string &payment_id, const std::string &tx_description, std::string &error) const
{
return m_wallet->make_uri(addresses, amounts, recipient_names, payment_id, tx_description, error);
}

std::string WalletImpl::getDefaultDataDir() const
{
return tools::get_default_data_dir();
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/api/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +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(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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no virtual keyword in the front here (it should only be used in the interface class src/wallet/api/wallet2_api.h (here you can find some general information about "pure virtual function" and "interface class")), IMO it's unfortunate that many methods in src/wallet/api/wallet.h already have this wrong, but for example these methods are considered to do it the "right way":

Device getDeviceType() const override;
bool close(bool store = true);
std::string seed(const std::string& seed_offset = "") const override;
std::string getSeedLanguage() const override;
void setSeedLanguage(const std::string &arg) override;
// void setListener(Listener *) {}
int status() const override;
std::string errorString() const override;
void statusWithErrorString(int& status, std::string& errorString) const override;
bool setPassword(const std::string &password) override;
const std::string& getPassword() const override;
bool setDevicePin(const std::string &password) override;
bool setDevicePassphrase(const std::string &password) override;
std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0) const override;
std::string integratedAddress(const std::string &payment_id) const override;
std::string secretViewKey() const override;
std::string publicViewKey() const override;
std::string secretSpendKey() const override;
std::string publicSpendKey() const override;
std::string publicMultisigSignerKey() const override;
std::string path() const override;
void stop() override;
bool store(const std::string &path) override;
std::string filename() const override;
std::string keysFilename() const override;
bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = "", bool use_ssl = false, bool lightWallet = false, const std::string &proxy_address = "") override;
bool connectToDaemon() override;
ConnectionStatus connected() const override;
void setTrustedDaemon(bool arg) override;
bool trustedDaemon() const override;
bool setProxy(const std::string &address) override;
uint64_t balance(uint32_t accountIndex = 0) const override;
uint64_t unlockedBalance(uint32_t accountIndex = 0) const override;
uint64_t blockChainHeight() const override;
uint64_t approximateBlockChainHeight() const override;
uint64_t estimateBlockChainHeight() const override;
uint64_t daemonBlockChainHeight() const override;
uint64_t daemonBlockChainTargetHeight() const override;
bool synchronized() const override;
bool refresh() override;
void refreshAsync() override;
bool rescanBlockchain() override;
void rescanBlockchainAsync() override;
void setAutoRefreshInterval(int millis) override;
int autoRefreshInterval() const override;
void setRefreshFromBlockHeight(uint64_t refresh_from_block_height) override;
uint64_t getRefreshFromBlockHeight() const override { return m_wallet->get_refresh_from_block_height(); };
void setRecoveringFromSeed(bool recoveringFromSeed) override;
void setRecoveringFromDevice(bool recoveringFromDevice) override;
void setSubaddressLookahead(uint32_t major, uint32_t minor) override;
bool watchOnly() const override;
bool isDeterministic() const override;
bool rescanSpent() override;
NetworkType nettype() const override {return static_cast<NetworkType>(m_wallet->nettype());}
void hardForkInfo(uint8_t &version, uint64_t &earliest_height) const override;
bool useForkRules(uint8_t version, int64_t early_blocks) const override;

Again same for make_uri() below.

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(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;
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
4 changes: 3 additions & 1 deletion src/wallet/api/wallet2_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1066,8 +1066,10 @@ struct Wallet
virtual bool verifyMessageWithPublicKey(const std::string &message, const std::string &publicKey, const std::string &signature) const = 0;

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;
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
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;

= 0 at the end for "pure virtual" functions


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;

virtual std::string make_uri(std::vector<std::string> &addresses, std::vector<std::uint64_t> &amounts, std::vector<std::string> &recipient_names, const std::string &payment_id, const std::string &tx_description, std::string &error) const;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
virtual std::string make_uri(std::vector<std::string> &addresses, std::vector<std::uint64_t> &amounts, std::vector<std::string> &recipient_names, const std::string &payment_id, const std::string &tx_description, std::string &error) const;
virtual std::string make_uri(std::vector<std::string> &addresses, std::vector<std::uint64_t> &amounts, std::vector<std::string> &recipient_names, const std::string &payment_id, const std::string &tx_description, std::string &error) const = 0;

virtual std::string getDefaultDataDir() const = 0;

/*
Expand Down
Loading
Loading