mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-27 05:13:25 +01:00
wallet_rpc_server: avoid repeated string allocations when parsing
This commit is contained in:
parent
88c85c18e0
commit
c4851024ce
@ -1684,23 +1684,14 @@ namespace tools
|
||||
cryptonote::blobdata payment_id_blob;
|
||||
|
||||
// TODO - should the whole thing fail because of one bad id?
|
||||
|
||||
if(!epee::string_tools::parse_hexstr_to_binbuff(payment_id_str, payment_id_blob))
|
||||
bool r;
|
||||
if (payment_id_str.size() == 2 * sizeof(payment_id))
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
|
||||
er.message = "Payment ID has invalid format: " + payment_id_str;
|
||||
return false;
|
||||
r = epee::string_tools::hex_to_pod(payment_id_str, payment_id);
|
||||
}
|
||||
|
||||
if(sizeof(payment_id) == payment_id_blob.size())
|
||||
else if (payment_id_str.size() == 2 * sizeof(payment_id8))
|
||||
{
|
||||
payment_id = *reinterpret_cast<const crypto::hash*>(payment_id_blob.data());
|
||||
}
|
||||
else if(sizeof(payment_id8) == payment_id_blob.size())
|
||||
{
|
||||
payment_id8 = *reinterpret_cast<const crypto::hash8*>(payment_id_blob.data());
|
||||
memcpy(payment_id.data, payment_id8.data, 8);
|
||||
memset(payment_id.data + 8, 0, 24);
|
||||
r = epee::string_tools::hex_to_pod(payment_id_str, payment_id8);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1709,6 +1700,13 @@ namespace tools
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!r)
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
|
||||
er.message = "Payment ID has invalid format: " + payment_id_str;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<wallet2::payment_details> payment_list;
|
||||
m_wallet->get_payments(payment_id, payment_list, req.min_block_height);
|
||||
|
||||
@ -2588,23 +2586,19 @@ namespace tools
|
||||
ski.resize(req.signed_key_images.size());
|
||||
for (size_t n = 0; n < ski.size(); ++n)
|
||||
{
|
||||
cryptonote::blobdata bd;
|
||||
|
||||
if(!epee::string_tools::parse_hexstr_to_binbuff(req.signed_key_images[n].key_image, bd) || bd.size() != sizeof(crypto::key_image))
|
||||
if (!epee::string_tools::hex_to_pod(req.signed_key_images[n].key_image, ski[n].first))
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_WRONG_KEY_IMAGE;
|
||||
er.message = "failed to parse key image";
|
||||
return false;
|
||||
}
|
||||
ski[n].first = *reinterpret_cast<const crypto::key_image*>(bd.data());
|
||||
|
||||
if(!epee::string_tools::parse_hexstr_to_binbuff(req.signed_key_images[n].signature, bd) || bd.size() != sizeof(crypto::signature))
|
||||
if (!epee::string_tools::hex_to_pod(req.signed_key_images[n].signature, ski[n].second))
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_WRONG_SIGNATURE;
|
||||
er.message = "failed to parse signature";
|
||||
return false;
|
||||
}
|
||||
ski[n].second = *reinterpret_cast<const crypto::signature*>(bd.data());
|
||||
}
|
||||
uint64_t spent = 0, unspent = 0;
|
||||
uint64_t height = m_wallet->import_key_images(ski, req.offset, spent, unspent);
|
||||
|
Loading…
Reference in New Issue
Block a user