docs: add note about hashing (#7073)

This commit is contained in:
Matthias Seitz
2024-03-11 14:53:30 +01:00
committed by GitHub
parent 5ce8034461
commit 63dd5d48eb

View File

@ -857,8 +857,12 @@ impl TransactionSignedNoHash {
}
/// Converts into a transaction type with its hash: [`TransactionSigned`].
///
/// Note: This will recalculate the hash of the transaction.
#[inline]
pub fn with_hash(self) -> TransactionSigned {
self.into()
let Self { signature, transaction } = self;
TransactionSigned::from_transaction_and_signature(transaction, signature)
}
/// Recovers a list of signers from a transaction list iterator
@ -941,7 +945,7 @@ impl Compact for TransactionSignedNoHash {
impl From<TransactionSignedNoHash> for TransactionSigned {
fn from(tx: TransactionSignedNoHash) -> Self {
TransactionSigned::from_transaction_and_signature(tx.transaction, tx.signature)
tx.with_hash()
}
}
@ -1155,6 +1159,7 @@ impl TransactionSigned {
}
/// Create a new signed transaction from a transaction and its signature.
///
/// This will also calculate the transaction hash using its encoding.
pub fn from_transaction_and_signature(transaction: Transaction, signature: Signature) -> Self {
let mut initial_tx = Self { transaction, hash: Default::default(), signature };