Skip to content
Snippets Groups Projects
Commit 64d22fe9 authored by Éloïs's avatar Éloïs
Browse files

[opti] Reduce blocks without cloning transactions

parent 76c92f0b
No related branches found
No related tags found
No related merge requests found
...@@ -170,8 +170,12 @@ impl TxDocOrTxHash { ...@@ -170,8 +170,12 @@ impl TxDocOrTxHash {
/// lightening consists in transforming the document by its hash. /// lightening consists in transforming the document by its hash.
pub fn reduce(&self) -> TxDocOrTxHash { pub fn reduce(&self) -> TxDocOrTxHash {
if let TxDocOrTxHash::TxDoc(ref tx_doc) = self { if let TxDocOrTxHash::TxDoc(ref tx_doc) = self {
let mut tx_doc = tx_doc.deref().clone(); let tx_doc = tx_doc.deref();
TxDocOrTxHash::TxHash(tx_doc.get_hash()) if let Some(ref hash) = tx_doc.get_hash_opt() {
TxDocOrTxHash::TxHash(*hash)
} else {
TxDocOrTxHash::TxHash(tx_doc.clone().compute_hash())
}
} else { } else {
self.clone() self.clone()
} }
......
...@@ -508,6 +508,10 @@ impl TransactionDocument { ...@@ -508,6 +508,10 @@ impl TransactionDocument {
self.hash = Some(Hash::from_hex(&sha256.result_str()).unwrap()); self.hash = Some(Hash::from_hex(&sha256.result_str()).unwrap());
self.hash.expect("Try to get hash of a reduce tx !") self.hash.expect("Try to get hash of a reduce tx !")
} }
/// get transaction hash option
pub fn get_hash_opt(&self) -> Option<Hash> {
self.hash
}
/// Get transaction hash /// Get transaction hash
pub fn get_hash(&mut self) -> Hash { pub fn get_hash(&mut self) -> Hash {
if let Some(hash) = self.hash { if let Some(hash) = self.hash {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment