chore: replace TransactionSigned struct inits with new functions (#12779)

This commit is contained in:
Tien Nguyen
2024-11-22 21:28:59 +07:00
committed by GitHub
parent 64728e0856
commit f2860006f7
8 changed files with 63 additions and 81 deletions

View File

@ -549,12 +549,9 @@ impl<TX: DbTx + 'static, N: NodeTypes> DatabaseProvider<TX, N> {
let body = transactions
.into_iter()
.map(|tx| match transaction_kind {
TransactionVariant::NoHash => TransactionSigned {
// Caller explicitly asked for no hash, so we don't calculate it
hash: Default::default(),
signature: tx.signature,
transaction: tx.transaction,
},
TransactionVariant::NoHash => {
TransactionSigned::new_unhashed(tx.transaction, tx.signature)
}
TransactionVariant::WithHash => tx.with_hash(),
})
.collect();
@ -1499,11 +1496,9 @@ impl<TX: DbTx + 'static, N: NodeTypes<ChainSpec: EthereumHardforks>> Transaction
fn transaction_by_hash(&self, hash: TxHash) -> ProviderResult<Option<TransactionSigned>> {
if let Some(id) = self.transaction_id(hash)? {
Ok(self.transaction_by_id_no_hash(id)?.map(|tx| TransactionSigned {
hash: hash.into(),
signature: tx.signature,
transaction: tx.transaction,
}))
Ok(self
.transaction_by_id_no_hash(id)?
.map(|tx| TransactionSigned::new(tx.transaction, tx.signature, hash)))
} else {
Ok(None)
}
@ -1517,11 +1512,7 @@ impl<TX: DbTx + 'static, N: NodeTypes<ChainSpec: EthereumHardforks>> Transaction
let mut transaction_cursor = self.tx.cursor_read::<tables::TransactionBlocks>()?;
if let Some(transaction_id) = self.transaction_id(tx_hash)? {
if let Some(tx) = self.transaction_by_id_no_hash(transaction_id)? {
let transaction = TransactionSigned {
hash: tx_hash.into(),
signature: tx.signature,
transaction: tx.transaction,
};
let transaction = TransactionSigned::new(tx.transaction, tx.signature, tx_hash);
if let Some(block_number) =
transaction_cursor.seek(transaction_id).map(|b| b.map(|(_, bn)| bn))?
{

View File

@ -88,9 +88,14 @@ pub(crate) static TEST_BLOCK: LazyLock<SealedBlock> = LazyLock::new(|| SealedBlo
hex!("cf7b274520720b50e6a4c3e5c4d553101f44945396827705518ce17cb7219a42").into(),
),
body: BlockBody {
transactions: vec![TransactionSigned {
hash: b256!("3541dd1d17e76adeb25dcf2b0a9b60a1669219502e58dcf26a2beafbfb550397").into(),
signature: Signature::new(
transactions: vec![TransactionSigned::new(
Transaction::Legacy(TxLegacy {
gas_price: 10,
gas_limit: 400_000,
to: TxKind::Call(hex!("095e7baea6a6c7c4c2dfeb977efac326af552d87").into()),
..Default::default()
}),
Signature::new(
U256::from_str(
"51983300959770368863831494747186777928121405155922056726144551509338672451120",
)
@ -101,13 +106,8 @@ pub(crate) static TEST_BLOCK: LazyLock<SealedBlock> = LazyLock::new(|| SealedBlo
.unwrap(),
false,
),
transaction: Transaction::Legacy(TxLegacy {
gas_price: 10,
gas_limit: 400_000,
to: TxKind::Call(hex!("095e7baea6a6c7c4c2dfeb977efac326af552d87").into()),
..Default::default()
}),
}],
b256!("3541dd1d17e76adeb25dcf2b0a9b60a1669219502e58dcf26a2beafbfb550397"),
)],
..Default::default()
},
});