Skip to content

Commit 7b19872

Browse files
authored
feat(starknet_class_manager_types): implement consensus tx to and from internal consensus tx (#3579)
1 parent 4881d96 commit 7b19872

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

crates/starknet_class_manager_types/src/transaction_converter.rs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use starknet_api::rpc_transaction::{
1414
RpcDeployAccountTransaction,
1515
RpcTransaction,
1616
};
17-
use starknet_api::transaction::CalculateContractAddress;
17+
use starknet_api::transaction::fields::Fee;
18+
use starknet_api::transaction::{CalculateContractAddress, TransactionHasher, TransactionVersion};
1819
use starknet_api::{executable_transaction, transaction, StarknetApiError};
1920
use thiserror::Error;
2021

@@ -73,16 +74,32 @@ impl TransactionConverter {
7374
impl TransactionConverterTrait for TransactionConverter {
7475
async fn convert_internal_consensus_tx_to_consensus_tx(
7576
&self,
76-
_tx: InternalConsensusTransaction,
77+
tx: InternalConsensusTransaction,
7778
) -> TransactionConverterResult<ConsensusTransaction> {
78-
todo!()
79+
match tx {
80+
InternalConsensusTransaction::RpcTransaction(tx) => self
81+
.convert_internal_rpc_tx_to_rpc_tx(tx)
82+
.await
83+
.map(ConsensusTransaction::RpcTransaction),
84+
InternalConsensusTransaction::L1Handler(tx) => {
85+
Ok(ConsensusTransaction::L1Handler(tx.tx))
86+
}
87+
}
7988
}
8089

8190
async fn convert_consensus_tx_to_internal_consensus_tx(
8291
&self,
83-
_tx: ConsensusTransaction,
92+
tx: ConsensusTransaction,
8493
) -> TransactionConverterResult<InternalConsensusTransaction> {
85-
todo!()
94+
match tx {
95+
ConsensusTransaction::RpcTransaction(tx) => self
96+
.convert_rpc_tx_to_internal_rpc_tx(tx)
97+
.await
98+
.map(InternalConsensusTransaction::RpcTransaction),
99+
ConsensusTransaction::L1Handler(tx) => self
100+
.convert_consensus_l1_handler_to_internal_l1_handler(tx)
101+
.map(InternalConsensusTransaction::L1Handler),
102+
}
86103
}
87104

88105
async fn convert_internal_rpc_tx_to_rpc_tx(
@@ -182,17 +199,17 @@ impl TransactionConverterTrait for TransactionConverter {
182199
}
183200
}
184201

185-
// TODO(alonl): remove this once the conversion functions are implemented.
186-
#[allow(dead_code)]
187-
fn convert_consensus_l1_handler_to_internal_l1_handler(
188-
_tx: transaction::L1HandlerTransaction,
189-
) -> executable_transaction::L1HandlerTransaction {
190-
todo!()
191-
}
192-
193-
#[allow(dead_code)]
194-
fn convert_internal_l1_handler_to_consensus_l1_handler(
195-
_tx: executable_transaction::L1HandlerTransaction,
196-
) -> transaction::L1HandlerTransaction {
197-
todo!()
202+
impl TransactionConverter {
203+
fn convert_consensus_l1_handler_to_internal_l1_handler(
204+
&self,
205+
tx: transaction::L1HandlerTransaction,
206+
) -> TransactionConverterResult<executable_transaction::L1HandlerTransaction> {
207+
let tx_hash = tx.calculate_transaction_hash(&self.chain_id, &TransactionVersion::ZERO)?;
208+
Ok(executable_transaction::L1HandlerTransaction {
209+
tx,
210+
tx_hash,
211+
// TODO(Gilad): Change this once we put real value in paid_fee_on_l1.
212+
paid_fee_on_l1: Fee(1),
213+
})
214+
}
198215
}

0 commit comments

Comments
 (0)