mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 10:37:37 -07:00
wallet_rpc_server: support regex for get_accounts tag
This commit adds a 'regexp' boolean field to the get_accounts request. The flag is set to false by default and maintains backwards compatibility. When set to true the user can search tags by regular expression filters. An additional error message was added for failed regular expression searches. Bump minor version to 25.
This commit is contained in:
parent
d562deaaa9
commit
d1f1947995
@ -622,7 +622,7 @@ namespace tools
|
|||||||
res.total_unlocked_balance = 0;
|
res.total_unlocked_balance = 0;
|
||||||
cryptonote::subaddress_index subaddr_index = {0,0};
|
cryptonote::subaddress_index subaddr_index = {0,0};
|
||||||
const std::pair<std::map<std::string, std::string>, std::vector<std::string>> account_tags = m_wallet->get_account_tags();
|
const std::pair<std::map<std::string, std::string>, std::vector<std::string>> account_tags = m_wallet->get_account_tags();
|
||||||
if (!req.tag.empty() && account_tags.first.count(req.tag) == 0)
|
if (!req.tag.empty() && account_tags.first.count(req.tag) == 0 && !req.regexp)
|
||||||
{
|
{
|
||||||
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
|
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
|
||||||
er.message = (boost::format(tr("Tag %s is unregistered.")) % req.tag).str();
|
er.message = (boost::format(tr("Tag %s is unregistered.")) % req.tag).str();
|
||||||
@ -630,7 +630,9 @@ namespace tools
|
|||||||
}
|
}
|
||||||
for (; subaddr_index.major < m_wallet->get_num_subaddress_accounts(); ++subaddr_index.major)
|
for (; subaddr_index.major < m_wallet->get_num_subaddress_accounts(); ++subaddr_index.major)
|
||||||
{
|
{
|
||||||
if (!req.tag.empty() && req.tag != account_tags.second[subaddr_index.major])
|
bool no_match = !req.regexp ? (!req.tag.empty() && req.tag != account_tags.second[subaddr_index.major])
|
||||||
|
: (!req.tag.empty() && !boost::regex_match(account_tags.second[subaddr_index.major], boost::regex(req.tag)));
|
||||||
|
if (no_match)
|
||||||
continue;
|
continue;
|
||||||
wallet_rpc::COMMAND_RPC_GET_ACCOUNTS::subaddress_account_info info;
|
wallet_rpc::COMMAND_RPC_GET_ACCOUNTS::subaddress_account_info info;
|
||||||
info.account_index = subaddr_index.major;
|
info.account_index = subaddr_index.major;
|
||||||
@ -643,6 +645,12 @@ namespace tools
|
|||||||
res.total_balance += info.balance;
|
res.total_balance += info.balance;
|
||||||
res.total_unlocked_balance += info.unlocked_balance;
|
res.total_unlocked_balance += info.unlocked_balance;
|
||||||
}
|
}
|
||||||
|
if (res.subaddress_accounts.size() == 0 && req.regexp)
|
||||||
|
{
|
||||||
|
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
|
||||||
|
er.message = (boost::format(tr("No matches for regex filter %s .")) % req.tag).str();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
// advance which version they will stop working with
|
// advance which version they will stop working with
|
||||||
// Don't go over 32767 for any of these
|
// Don't go over 32767 for any of these
|
||||||
#define WALLET_RPC_VERSION_MAJOR 1
|
#define WALLET_RPC_VERSION_MAJOR 1
|
||||||
#define WALLET_RPC_VERSION_MINOR 24
|
#define WALLET_RPC_VERSION_MINOR 25
|
||||||
#define MAKE_WALLET_RPC_VERSION(major,minor) (((major)<<16)|(minor))
|
#define MAKE_WALLET_RPC_VERSION(major,minor) (((major)<<16)|(minor))
|
||||||
#define WALLET_RPC_VERSION MAKE_WALLET_RPC_VERSION(WALLET_RPC_VERSION_MAJOR, WALLET_RPC_VERSION_MINOR)
|
#define WALLET_RPC_VERSION MAKE_WALLET_RPC_VERSION(WALLET_RPC_VERSION_MAJOR, WALLET_RPC_VERSION_MINOR)
|
||||||
namespace tools
|
namespace tools
|
||||||
@ -243,10 +243,12 @@ namespace wallet_rpc
|
|||||||
{
|
{
|
||||||
std::string tag; // all accounts if empty, otherwise those accounts with this tag
|
std::string tag; // all accounts if empty, otherwise those accounts with this tag
|
||||||
bool strict_balances;
|
bool strict_balances;
|
||||||
|
bool regexp; // allow regular expression filters if set to true
|
||||||
|
|
||||||
BEGIN_KV_SERIALIZE_MAP()
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
KV_SERIALIZE(tag)
|
KV_SERIALIZE(tag)
|
||||||
KV_SERIALIZE_OPT(strict_balances, false)
|
KV_SERIALIZE_OPT(strict_balances, false)
|
||||||
|
KV_SERIALIZE_OPT(regexp, false)
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
typedef epee::misc_utils::struct_init<request_t> request;
|
typedef epee::misc_utils::struct_init<request_t> request;
|
||||||
|
Loading…
Reference in New Issue
Block a user