aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-11-26 00:19:50 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-03-05 11:58:22 +0000
commitc4851024ced48988c9a61db2a89b0cfd0c56915a (patch)
treee3ecefce3b7508387c143880aeb372daab0572f8
parentcryptonote: avoid double parsing blocks when syncing (diff)
downloadmonero-c4851024ced48988c9a61db2a89b0cfd0c56915a.tar.xz
wallet_rpc_server: avoid repeated string allocations when parsing
Diffstat (limited to '')
-rw-r--r--src/wallet/wallet_rpc_server.cpp34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 9adfb06c8..110777c4f 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -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))
- {
- er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
- er.message = "Payment ID has invalid format: " + payment_id_str;
- return false;
- }
-
- if(sizeof(payment_id) == payment_id_blob.size())
+ bool r;
+ if (payment_id_str.size() == 2 * sizeof(payment_id))
{
- payment_id = *reinterpret_cast<const crypto::hash*>(payment_id_blob.data());
+ r = epee::string_tools::hex_to_pod(payment_id_str, payment_id);
}
- else if(sizeof(payment_id8) == payment_id_blob.size())
+ else if (payment_id_str.size() == 2 * sizeof(payment_id8))
{
- 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);