Skip to content

Commit 2265a26

Browse files
authored
chore(primitives): remove redundant intermediary type (#350)
1 parent 3b06d22 commit 2265a26

File tree

5 files changed

+20
-43
lines changed

5 files changed

+20
-43
lines changed

crates/executor/src/implementation/blockifier/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl<'a> BlockExecutor<'a> for StarknetVMProcessor<'a> {
228228
None
229229
};
230230

231-
let tx = TxWithHash::from(&exec_tx);
231+
let tx = TxWithHash::from(exec_tx.clone());
232232
let hash = tx.hash;
233233
let result = utils::transact(
234234
&mut state.cached_state,

crates/executor/src/implementation/blockifier/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub fn transact<S: StateReader>(
143143

144144
tx_state.commit();
145145

146-
let receipt = build_receipt(tx.tx_ref(), fee, &info);
146+
let receipt = build_receipt(&tx.transaction, fee, &info);
147147
Ok(ExecutionResult::new_success(receipt, info))
148148
}
149149

crates/executor/src/utils.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use katana_primitives::receipt::{
55
self, DataAvailabilityResources, DeclareTxReceipt, DeployAccountTxReceipt, Event, GasUsed,
66
InvokeTxReceipt, L1HandlerTxReceipt, MessageToL1, Receipt,
77
};
8-
use katana_primitives::transaction::TxRef;
8+
use katana_primitives::transaction::ExecutableTx;
99
use tracing::trace;
1010

1111
pub(crate) const LOG_TARGET: &str = "executor";
@@ -27,7 +27,7 @@ pub fn log_resources(resources: &TransactionResources) {
2727
}
2828

2929
pub(crate) fn build_receipt(
30-
tx: TxRef<'_>,
30+
tx: &ExecutableTx,
3131
fee: FeeInfo,
3232
info: &TransactionExecutionInfo,
3333
) -> Receipt {
@@ -37,23 +37,23 @@ pub(crate) fn build_receipt(
3737
let revert_error = info.revert_error.as_ref().map(|e| e.to_string());
3838

3939
match tx {
40-
TxRef::Invoke(_) => Receipt::Invoke(InvokeTxReceipt {
40+
ExecutableTx::Invoke(_) => Receipt::Invoke(InvokeTxReceipt {
4141
events,
4242
fee,
4343
revert_error,
4444
messages_sent,
4545
execution_resources,
4646
}),
4747

48-
TxRef::Declare(_) => Receipt::Declare(DeclareTxReceipt {
48+
ExecutableTx::Declare(_) => Receipt::Declare(DeclareTxReceipt {
4949
events,
5050
fee,
5151
revert_error,
5252
messages_sent,
5353
execution_resources,
5454
}),
5555

56-
TxRef::L1Handler(tx) => Receipt::L1Handler(L1HandlerTxReceipt {
56+
ExecutableTx::L1Handler(tx) => Receipt::L1Handler(L1HandlerTxReceipt {
5757
events,
5858
fee,
5959
revert_error,
@@ -62,7 +62,7 @@ pub(crate) fn build_receipt(
6262
execution_resources,
6363
}),
6464

65-
TxRef::DeployAccount(tx) => Receipt::DeployAccount(DeployAccountTxReceipt {
65+
ExecutableTx::DeployAccount(tx) => Receipt::DeployAccount(DeployAccountTxReceipt {
6666
events,
6767
fee,
6868
revert_error,

crates/executor/tests/executor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn test_executor_with_valid_blocks_impl<EF: ExecutorFactory>(
4141
//
4242

4343
let block = &blocks[0];
44-
expected_txs.extend(block.body.iter().map(|t| t.into()));
44+
expected_txs.extend(block.body.iter().map(|t| t.clone().into()));
4545

4646
executor.execute_block(block.clone()).unwrap();
4747

@@ -124,7 +124,7 @@ fn test_executor_with_valid_blocks_impl<EF: ExecutorFactory>(
124124
//
125125

126126
let block = &blocks[1];
127-
expected_txs.extend(block.body.iter().map(|t| t.into()));
127+
expected_txs.extend(block.body.iter().map(|t| t.clone().into()));
128128

129129
executor.execute_block(block.clone()).unwrap();
130130

@@ -171,7 +171,7 @@ fn test_executor_with_valid_blocks_impl<EF: ExecutorFactory>(
171171
//
172172

173173
let block = &blocks[2];
174-
expected_txs.extend(block.body.iter().map(|t| t.into()));
174+
expected_txs.extend(block.body.iter().map(|t| t.clone().into()));
175175

176176
executor.execute_block(block.clone()).unwrap();
177177

crates/primitives/src/transaction.rs

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,6 @@ impl Tx {
108108
}
109109
}
110110

111-
#[derive(Debug)]
112-
pub enum TxRef<'a> {
113-
Invoke(&'a InvokeTx),
114-
Declare(&'a DeclareTx),
115-
L1Handler(&'a L1HandlerTx),
116-
DeployAccount(&'a DeployAccountTx),
117-
}
118-
119-
impl<'a> From<TxRef<'a>> for Tx {
120-
fn from(value: TxRef<'a>) -> Self {
121-
match value {
122-
TxRef::Invoke(tx) => Tx::Invoke(tx.clone()),
123-
TxRef::Declare(tx) => Tx::Declare(tx.clone()),
124-
TxRef::L1Handler(tx) => Tx::L1Handler(tx.clone()),
125-
TxRef::DeployAccount(tx) => Tx::DeployAccount(tx.clone()),
126-
}
127-
}
128-
}
129-
130111
/// Represents a transaction that has all the necessary data to be executed.
131112
#[derive(Debug, Clone, From, PartialEq, Eq)]
132113
pub enum ExecutableTx {
@@ -146,15 +127,6 @@ impl ExecutableTx {
146127
}
147128
}
148129

149-
pub fn tx_ref(&self) -> TxRef<'_> {
150-
match self {
151-
ExecutableTx::Invoke(tx) => TxRef::Invoke(tx),
152-
ExecutableTx::L1Handler(tx) => TxRef::L1Handler(tx),
153-
ExecutableTx::Declare(tx) => TxRef::Declare(tx),
154-
ExecutableTx::DeployAccount(tx) => TxRef::DeployAccount(tx),
155-
}
156-
}
157-
158130
pub fn r#type(&self) -> TxType {
159131
match self {
160132
ExecutableTx::Invoke(_) => TxType::Invoke,
@@ -748,12 +720,17 @@ pub struct TxWithHash {
748720

749721
impl From<ExecutableTxWithHash> for TxWithHash {
750722
fn from(tx: ExecutableTxWithHash) -> Self {
751-
Self { hash: tx.hash, transaction: tx.tx_ref().into() }
723+
Self { hash: tx.hash, transaction: tx.transaction.into() }
752724
}
753725
}
754726

755-
impl From<&ExecutableTxWithHash> for TxWithHash {
756-
fn from(tx: &ExecutableTxWithHash) -> Self {
757-
Self { hash: tx.hash, transaction: tx.tx_ref().into() }
727+
impl From<ExecutableTx> for Tx {
728+
fn from(tx: ExecutableTx) -> Self {
729+
match tx {
730+
ExecutableTx::Invoke(tx) => Tx::Invoke(tx),
731+
ExecutableTx::L1Handler(tx) => Tx::L1Handler(tx),
732+
ExecutableTx::Declare(tx) => Tx::Declare(tx.transaction),
733+
ExecutableTx::DeployAccount(tx) => Tx::DeployAccount(tx),
734+
}
758735
}
759736
}

0 commit comments

Comments
 (0)