aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2019-03-05 14:09:19 +0200
committerRiccardo Spagni <ric@spagni.net>2019-03-05 14:09:19 +0200
commited6aa76cca69e4f6d0b84eb55ef7061dc4b6fc77 (patch)
treeb5cb515fa3db4dea131a3e1a3162ce3ee820b946 /src/wallet
parentMerge pull request #5231 (diff)
parentwallet_rpc_server: avoid repeated string allocations when parsing (diff)
downloadmonero-ed6aa76cca69e4f6d0b84eb55ef7061dc4b6fc77.tar.xz
Merge pull request #5100
c4851024 wallet_rpc_server: avoid repeated string allocations when parsing (moneromooo-monero) 88c85c18 cryptonote: avoid double parsing blocks when syncing (moneromooo-monero) 9feda0ee cryptonote: speed up calculating coinbase tx prunable hash (moneromooo-monero) 238401d4 core: avoid double parsing blocks after hoh (moneromooo-monero) dc5a7609 blockchain: avoid unneeded block copy (moneromooo-monero) 79b4e9f3 save some database calls when getting top block hash and height (moneromooo-monero) 98278808 blockchain: avoid pointless transaction copy and temporary (moneromooo-monero) 07d655e4 blockchain: avoid duplicate block hash computation (moneromooo-monero) f75d51ab core: avoid calculating tx prefix hash when we don't need it (moneromooo-monero) b044d03a Avoid repeated (de)serialization when syncing (moneromooo-monero) b747e836 wallet2: don't calculate prefix hash when we don't need it (moneromooo-monero) e69477bf db: speedup block addition (moneromooo-monero)
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet2.cpp12
-rw-r--r--src/wallet/wallet_rpc_server.cpp34
2 files changed, 20 insertions, 26 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index f2c0a7ba9..a476ecdc5 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -10175,11 +10175,11 @@ void wallet2::check_tx_key_helper(const crypto::hash &txid, const crypto::key_de
else
{
cryptonote::blobdata tx_data;
- crypto::hash tx_prefix_hash;
ok = string_tools::parse_hexstr_to_binbuff(res.txs_as_hex.front(), tx_data);
THROW_WALLET_EXCEPTION_IF(!ok, error::wallet_internal_error, "Failed to parse transaction from daemon");
- THROW_WALLET_EXCEPTION_IF(!cryptonote::parse_and_validate_tx_from_blob(tx_data, tx, tx_hash, tx_prefix_hash),
+ THROW_WALLET_EXCEPTION_IF(!cryptonote::parse_and_validate_tx_from_blob(tx_data, tx),
error::wallet_internal_error, "Failed to validate transaction from daemon");
+ tx_hash = cryptonote::get_transaction_hash(tx);
}
THROW_WALLET_EXCEPTION_IF(tx_hash != txid, error::wallet_internal_error,
@@ -10321,11 +10321,11 @@ std::string wallet2::get_tx_proof(const crypto::hash &txid, const cryptonote::ac
else
{
cryptonote::blobdata tx_data;
- crypto::hash tx_prefix_hash;
ok = string_tools::parse_hexstr_to_binbuff(res.txs_as_hex.front(), tx_data);
THROW_WALLET_EXCEPTION_IF(!ok, error::wallet_internal_error, "Failed to parse transaction from daemon");
- THROW_WALLET_EXCEPTION_IF(!cryptonote::parse_and_validate_tx_from_blob(tx_data, tx, tx_hash, tx_prefix_hash),
+ THROW_WALLET_EXCEPTION_IF(!cryptonote::parse_and_validate_tx_from_blob(tx_data, tx),
error::wallet_internal_error, "Failed to validate transaction from daemon");
+ tx_hash = cryptonote::get_transaction_hash(tx);
}
THROW_WALLET_EXCEPTION_IF(tx_hash != txid, error::wallet_internal_error, "Failed to get the right transaction from daemon");
@@ -10439,11 +10439,11 @@ bool wallet2::check_tx_proof(const crypto::hash &txid, const cryptonote::account
else
{
cryptonote::blobdata tx_data;
- crypto::hash tx_prefix_hash;
ok = string_tools::parse_hexstr_to_binbuff(res.txs_as_hex.front(), tx_data);
THROW_WALLET_EXCEPTION_IF(!ok, error::wallet_internal_error, "Failed to parse transaction from daemon");
- THROW_WALLET_EXCEPTION_IF(!cryptonote::parse_and_validate_tx_from_blob(tx_data, tx, tx_hash, tx_prefix_hash),
+ THROW_WALLET_EXCEPTION_IF(!cryptonote::parse_and_validate_tx_from_blob(tx_data, tx),
error::wallet_internal_error, "Failed to validate transaction from daemon");
+ tx_hash = cryptonote::get_transaction_hash(tx);
}
THROW_WALLET_EXCEPTION_IF(tx_hash != txid, error::wallet_internal_error, "Failed to get the right transaction from daemon");
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);