chore: accept AsRef in calculate_transaction_root (#2188)

This commit is contained in:
Matthias Seitz
2023-04-11 19:41:57 +02:00
committed by GitHub
parent 840a0c7860
commit f919eeebfc
2 changed files with 12 additions and 4 deletions

View File

@ -36,12 +36,14 @@ impl Hasher for KeccakHasher {
/// Calculate a transaction root. /// Calculate a transaction root.
/// ///
/// `(rlp(index), encoded(tx))` pairs. /// `(rlp(index), encoded(tx))` pairs.
pub fn calculate_transaction_root<'a>( pub fn calculate_transaction_root<I, T>(transactions: I) -> H256
transactions: impl IntoIterator<Item = &'a TransactionSigned>, where
) -> H256 { I: IntoIterator<Item = T>,
T: AsRef<TransactionSigned>,
{
ordered_trie_root::<KeccakHasher, _>(transactions.into_iter().map(|tx| { ordered_trie_root::<KeccakHasher, _>(transactions.into_iter().map(|tx| {
let mut tx_rlp = Vec::new(); let mut tx_rlp = Vec::new();
tx.encode_inner(&mut tx_rlp, false); tx.as_ref().encode_inner(&mut tx_rlp, false);
tx_rlp tx_rlp
})) }))
} }

View File

@ -540,6 +540,12 @@ pub struct TransactionSigned {
pub transaction: Transaction, pub transaction: Transaction,
} }
impl AsRef<Self> for TransactionSigned {
fn as_ref(&self) -> &Self {
self
}
}
// === impl TransactionSigned === // === impl TransactionSigned ===
impl TransactionSigned { impl TransactionSigned {