mirror of
https://github.com/monero-project/monero.git
synced 2025-08-17 12:40:20 -04:00
Avoid some temporary strings when reading off the database
This commit is contained in:
parent
43a4fd9e16
commit
55363c5941
11 changed files with 92 additions and 92 deletions
|
@ -209,7 +209,7 @@ namespace cryptonote
|
|||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, transaction& tx)
|
||||
bool parse_and_validate_tx_from_blob(const blobdata_ref& tx_blob, transaction& tx)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << tx_blob;
|
||||
|
@ -222,7 +222,7 @@ namespace cryptonote
|
|||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_tx_base_from_blob(const blobdata& tx_blob, transaction& tx)
|
||||
bool parse_and_validate_tx_base_from_blob(const blobdata_ref& tx_blob, transaction& tx)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << tx_blob;
|
||||
|
@ -234,7 +234,7 @@ namespace cryptonote
|
|||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_tx_prefix_from_blob(const blobdata& tx_blob, transaction_prefix& tx)
|
||||
bool parse_and_validate_tx_prefix_from_blob(const blobdata_ref& tx_blob, transaction_prefix& tx)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << tx_blob;
|
||||
|
@ -244,7 +244,7 @@ namespace cryptonote
|
|||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, transaction& tx, crypto::hash& tx_hash)
|
||||
bool parse_and_validate_tx_from_blob(const blobdata_ref& tx_blob, transaction& tx, crypto::hash& tx_hash)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << tx_blob;
|
||||
|
@ -258,7 +258,7 @@ namespace cryptonote
|
|||
return get_transaction_hash(tx, tx_hash);
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, transaction& tx, crypto::hash& tx_hash, crypto::hash& tx_prefix_hash)
|
||||
bool parse_and_validate_tx_from_blob(const blobdata_ref& tx_blob, transaction& tx, crypto::hash& tx_hash, crypto::hash& tx_prefix_hash)
|
||||
{
|
||||
if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash))
|
||||
return false;
|
||||
|
@ -958,7 +958,7 @@ namespace cryptonote
|
|||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
void get_blob_hash(const epee::span<const char>& blob, crypto::hash& res)
|
||||
void get_blob_hash(const blobdata_ref& blob, crypto::hash& res)
|
||||
{
|
||||
cn_fast_hash(blob.data(), blob.size(), res);
|
||||
}
|
||||
|
@ -1045,7 +1045,7 @@ namespace cryptonote
|
|||
return h;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
crypto::hash get_blob_hash(const epee::span<const char>& blob)
|
||||
crypto::hash get_blob_hash(const blobdata_ref& blob)
|
||||
{
|
||||
crypto::hash h = null_hash;
|
||||
get_blob_hash(blob, h);
|
||||
|
@ -1065,7 +1065,7 @@ namespace cryptonote
|
|||
return get_transaction_hash(t, res, NULL);
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool calculate_transaction_prunable_hash(const transaction& t, const cryptonote::blobdata *blob, crypto::hash& res)
|
||||
bool calculate_transaction_prunable_hash(const transaction& t, const cryptonote::blobdata_ref *blob, crypto::hash& res)
|
||||
{
|
||||
if (t.version == 1)
|
||||
return false;
|
||||
|
@ -1073,7 +1073,7 @@ namespace cryptonote
|
|||
if (blob && unprunable_size)
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(unprunable_size <= blob->size(), false, "Inconsistent transaction unprunable and blob sizes");
|
||||
cryptonote::get_blob_hash(epee::span<const char>(blob->data() + unprunable_size, blob->size() - unprunable_size), res);
|
||||
cryptonote::get_blob_hash(blobdata_ref(blob->data() + unprunable_size, blob->size() - unprunable_size), res);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1090,7 +1090,7 @@ namespace cryptonote
|
|||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
crypto::hash get_transaction_prunable_hash(const transaction& t, const cryptonote::blobdata *blobdata)
|
||||
crypto::hash get_transaction_prunable_hash(const transaction& t, const cryptonote::blobdata_ref *blobdata)
|
||||
{
|
||||
crypto::hash res;
|
||||
if (t.is_prunable_hash_valid())
|
||||
|
@ -1168,7 +1168,7 @@ namespace cryptonote
|
|||
|
||||
// base rct
|
||||
CHECK_AND_ASSERT_MES(prefix_size <= unprunable_size && unprunable_size <= blob.size(), false, "Inconsistent transaction prefix, unprunable and blob sizes");
|
||||
cryptonote::get_blob_hash(epee::span<const char>(blob.data() + prefix_size, unprunable_size - prefix_size), hashes[1]);
|
||||
cryptonote::get_blob_hash(blobdata_ref(blob.data() + prefix_size, unprunable_size - prefix_size), hashes[1]);
|
||||
|
||||
// prunable rct
|
||||
if (t.rct_signatures.type == rct::RCTTypeNull)
|
||||
|
@ -1177,7 +1177,8 @@ namespace cryptonote
|
|||
}
|
||||
else
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(calculate_transaction_prunable_hash(t, &blob, hashes[2]), false, "Failed to get tx prunable hash");
|
||||
cryptonote::blobdata_ref blobref(blob);
|
||||
CHECK_AND_ASSERT_MES(calculate_transaction_prunable_hash(t, &blobref, hashes[2]), false, "Failed to get tx prunable hash");
|
||||
}
|
||||
|
||||
// the tx hash is the hash of the 3 hashes
|
||||
|
@ -1241,13 +1242,15 @@ namespace cryptonote
|
|||
return blob;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool calculate_block_hash(const block& b, crypto::hash& res, const blobdata *blob)
|
||||
bool calculate_block_hash(const block& b, crypto::hash& res, const blobdata_ref *blob)
|
||||
{
|
||||
blobdata bd;
|
||||
blobdata_ref bdref;
|
||||
if (!blob)
|
||||
{
|
||||
bd = block_to_blob(b);
|
||||
blob = &bd;
|
||||
bdref = bd;
|
||||
blob = &bdref;
|
||||
}
|
||||
|
||||
bool hash_result = get_object_hash(get_block_hashing_blob(b), res);
|
||||
|
@ -1330,7 +1333,7 @@ namespace cryptonote
|
|||
return res;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b, crypto::hash *block_hash)
|
||||
bool parse_and_validate_block_from_blob(const blobdata_ref& b_blob, block& b, crypto::hash *block_hash)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << b_blob;
|
||||
|
@ -1348,12 +1351,12 @@ namespace cryptonote
|
|||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b)
|
||||
bool parse_and_validate_block_from_blob(const blobdata_ref& b_blob, block& b)
|
||||
{
|
||||
return parse_and_validate_block_from_blob(b_blob, b, NULL);
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b, crypto::hash &block_hash)
|
||||
bool parse_and_validate_block_from_blob(const blobdata_ref& b_blob, block& b, crypto::hash &block_hash)
|
||||
{
|
||||
return parse_and_validate_block_from_blob(b_blob, b, &block_hash);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue