aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_basic
diff options
context:
space:
mode:
authorAlexander Blair <snipa@jagtech.io>2020-08-27 02:52:48 -0700
committerAlexander Blair <snipa@jagtech.io>2020-08-27 02:52:59 -0700
commit38914fe6fadaaf8585c1961d4bdf954ccc844bde (patch)
tree6a2ab535da02a6ea53cc15ae37228d90e91fd2e9 /src/cryptonote_basic
parentMerge pull request #6610 (diff)
parentAvoid some temporary strings when reading off the database (diff)
downloadmonero-38914fe6fadaaf8585c1961d4bdf954ccc844bde.tar.xz
Merge pull request #6613
55363c594 Avoid some temporary strings when reading off the database (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_basic')
-rw-r--r--src/cryptonote_basic/blobdatatype.h3
-rw-r--r--src/cryptonote_basic/cryptonote_format_utils.cpp37
-rw-r--r--src/cryptonote_basic/cryptonote_format_utils.h26
3 files changed, 35 insertions, 31 deletions
diff --git a/src/cryptonote_basic/blobdatatype.h b/src/cryptonote_basic/blobdatatype.h
index 6906e0c9d..7f899993b 100644
--- a/src/cryptonote_basic/blobdatatype.h
+++ b/src/cryptonote_basic/blobdatatype.h
@@ -31,10 +31,11 @@
#pragma once
#include <string>
+#include <boost/utility/string_ref_fwd.hpp>
#include "span.h"
namespace cryptonote
{
typedef std::string blobdata;
- typedef epee::span<const char> blobdata_ref;
+ typedef boost::string_ref blobdata_ref;
}
diff --git a/src/cryptonote_basic/cryptonote_format_utils.cpp b/src/cryptonote_basic/cryptonote_format_utils.cpp
index 3fd059ac1..d808a9c1d 100644
--- a/src/cryptonote_basic/cryptonote_format_utils.cpp
+++ b/src/cryptonote_basic/cryptonote_format_utils.cpp
@@ -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);
}
diff --git a/src/cryptonote_basic/cryptonote_format_utils.h b/src/cryptonote_basic/cryptonote_format_utils.h
index 5639e38d0..636a88b9a 100644
--- a/src/cryptonote_basic/cryptonote_format_utils.h
+++ b/src/cryptonote_basic/cryptonote_format_utils.h
@@ -52,11 +52,11 @@ namespace cryptonote
crypto::hash get_transaction_prefix_hash(const transaction_prefix& tx, hw::device &hwdev);
void get_transaction_prefix_hash(const transaction_prefix& tx, crypto::hash& h);
crypto::hash get_transaction_prefix_hash(const transaction_prefix& tx);
- bool parse_and_validate_tx_prefix_from_blob(const blobdata& tx_blob, transaction_prefix& tx);
- 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& tx_blob, transaction& tx, crypto::hash& tx_hash);
- bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, transaction& tx);
- bool parse_and_validate_tx_base_from_blob(const blobdata& tx_blob, transaction& tx);
+ bool parse_and_validate_tx_prefix_from_blob(const blobdata_ref& tx_blob, transaction_prefix& tx);
+ bool parse_and_validate_tx_from_blob(const blobdata_ref& 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);
+ bool parse_and_validate_tx_from_blob(const blobdata_ref& tx_blob, transaction& tx);
+ bool parse_and_validate_tx_base_from_blob(const blobdata_ref& tx_blob, transaction& tx);
bool is_v1_tx(const blobdata_ref& tx_blob);
bool is_v1_tx(const blobdata& tx_blob);
@@ -102,27 +102,27 @@ namespace cryptonote
bool generate_key_image_helper(const account_keys& ack, const std::unordered_map<crypto::public_key, subaddress_index>& subaddresses, const crypto::public_key& out_key, const crypto::public_key& tx_public_key, const std::vector<crypto::public_key>& additional_tx_public_keys, size_t real_output_index, keypair& in_ephemeral, crypto::key_image& ki, hw::device &hwdev);
bool generate_key_image_helper_precomp(const account_keys& ack, const crypto::public_key& out_key, const crypto::key_derivation& recv_derivation, size_t real_output_index, const subaddress_index& received_index, keypair& in_ephemeral, crypto::key_image& ki, hw::device &hwdev);
void get_blob_hash(const blobdata& blob, crypto::hash& res);
- void get_blob_hash(const epee::span<const char>& blob, crypto::hash& res);
+ void get_blob_hash(const blobdata_ref& blob, crypto::hash& res);
crypto::hash get_blob_hash(const blobdata& blob);
- crypto::hash get_blob_hash(const epee::span<const char>& blob);
+ crypto::hash get_blob_hash(const blobdata_ref& blob);
std::string short_hash_str(const crypto::hash& h);
crypto::hash get_transaction_hash(const transaction& t);
bool get_transaction_hash(const transaction& t, crypto::hash& res);
bool get_transaction_hash(const transaction& t, crypto::hash& res, size_t& blob_size);
bool get_transaction_hash(const transaction& t, crypto::hash& res, size_t* blob_size);
- bool calculate_transaction_prunable_hash(const transaction& t, const cryptonote::blobdata *blob, crypto::hash& res);
- crypto::hash get_transaction_prunable_hash(const transaction& t, const cryptonote::blobdata *blob = NULL);
+ bool calculate_transaction_prunable_hash(const transaction& t, const cryptonote::blobdata_ref *blob, crypto::hash& res);
+ crypto::hash get_transaction_prunable_hash(const transaction& t, const cryptonote::blobdata_ref *blob = NULL);
bool calculate_transaction_hash(const transaction& t, crypto::hash& res, size_t* blob_size);
crypto::hash get_pruned_transaction_hash(const transaction& t, const crypto::hash &pruned_data_hash);
blobdata get_block_hashing_blob(const block& b);
- bool calculate_block_hash(const block& b, crypto::hash& res, const blobdata *blob = NULL);
+ bool calculate_block_hash(const block& b, crypto::hash& res, const blobdata_ref *blob = NULL);
bool get_block_hash(const block& b, crypto::hash& res);
crypto::hash get_block_hash(const block& b);
- 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& b_blob, block& b);
- 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);
+ bool parse_and_validate_block_from_blob(const blobdata_ref& b_blob, block& b);
+ bool parse_and_validate_block_from_blob(const blobdata_ref& b_blob, block& b, crypto::hash &block_hash);
bool get_inputs_money_amount(const transaction& tx, uint64_t& money);
uint64_t get_outs_money_amount(const transaction& tx);
bool check_inputs_types_supported(const transaction& tx);