Skip to content

Commit

Permalink
tx hash from tx prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptozoidberg committed May 11, 2014
1 parent 0a2f3b1 commit 714b066
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/currency_core/currency_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ namespace currency
VARINT_FIELD(amount)
FIELD(target)
END_SERIALIZE()


};

class transaction_prefix
Expand Down Expand Up @@ -202,8 +200,9 @@ namespace currency
ar.end_array();
END_SERIALIZE()

private:

static size_t get_signature_size(const txin_v& tx_in);

};


Expand Down
21 changes: 15 additions & 6 deletions src/currency_core/currency_format_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,20 +749,22 @@ namespace currency
{
crypto::hash h = null_hash;
size_t blob_size = 0;
get_object_hash(t, h, blob_size);
get_object_hash(static_cast<const transaction_prefix&>(t), h, blob_size);
return h;
}
//---------------------------------------------------------------
bool get_transaction_hash(const transaction& t, crypto::hash& res)
{
size_t blob_size = 0;
return get_object_hash(t, res, blob_size);
return get_object_hash(static_cast<const transaction_prefix&>(t), res, blob_size);
}
//---------------------------------------------------------------
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)
{
return get_object_hash(t, res, blob_size);
}
}*/
//------------------------------------------------------------------
template<typename pod_operand_a, typename pod_operand_b>
crypto::hash hash_together(const pod_operand_a& a, const pod_operand_b& b)
Expand Down Expand Up @@ -971,6 +973,14 @@ namespace currency
return true;
}
//---------------------------------------------------------------
size_t get_object_blobsize(const transaction& t)
{
size_t prefix_blob = get_object_blobsize(static_cast<const transaction_prefix&>(t));
for(const auto& in: t.vin)
prefix_blob += transaction::get_signature_size(in);
return prefix_blob;
}
//---------------------------------------------------------------
blobdata block_to_blob(const block& b)
{
return t_serializable_object_to_blob(b);
Expand Down Expand Up @@ -1007,8 +1017,7 @@ namespace currency
{
std::vector<crypto::hash> txs_ids;
crypto::hash h = null_hash;
size_t bl_sz = 0;
get_transaction_hash(b.miner_tx, h, bl_sz);
get_transaction_hash(b.miner_tx, h);
txs_ids.push_back(h);
BOOST_FOREACH(auto& th, b.tx_hashes)
txs_ids.push_back(th);
Expand Down
4 changes: 3 additions & 1 deletion src/currency_core/currency_format_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace currency

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);
blobdata get_block_hashing_blob(const block& b);
bool get_block_hash(const block& b, crypto::hash& res);
crypto::hash get_block_hash(const block& b);
Expand Down Expand Up @@ -235,6 +235,8 @@ namespace currency
return b.size();
}
//---------------------------------------------------------------
size_t get_object_blobsize(const transaction& t);
//---------------------------------------------------------------
template<class t_object>
bool get_object_hash(const t_object& o, crypto::hash& res, size_t& blob_size)
{
Expand Down
4 changes: 2 additions & 2 deletions src/currency_core/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ namespace currency
bool tx_memory_pool::add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block)
{
crypto::hash h = null_hash;
size_t blob_size = 0;
get_transaction_hash(tx, h, blob_size);
size_t blob_size = get_object_blobsize(tx);
get_transaction_hash(tx, h);
return add_tx(tx, h, blob_size, tvc, keeped_by_block);
}
//---------------------------------------------------------------------------------
Expand Down

0 comments on commit 714b066

Please sign in to comment.