Skip to content

Commit fde2d2b

Browse files
committed
wip
1 parent 2db8472 commit fde2d2b

File tree

4 files changed

+62
-7
lines changed

4 files changed

+62
-7
lines changed

crates/katana/primitives/src/fee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[derive(Debug, Clone, PartialEq, Eq)]
1+
#[derive(Debug, Clone, PartialEq, Eq, Default)]
22
#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
33
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
44
pub struct ResourceBounds {
@@ -8,7 +8,7 @@ pub struct ResourceBounds {
88
pub max_price_per_unit: u128,
99
}
1010

11-
#[derive(Debug, Clone, PartialEq, Eq)]
11+
#[derive(Debug, Clone, PartialEq, Eq, Default)]
1212
#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
1313
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1414
pub struct ResourceBoundsMapping {

crates/katana/primitives/src/feeder_gateway.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ use starknet::providers::sequencer::models::{
55
};
66

77
use crate::block::{FinalityStatus, GasPrices, Header, SealedBlock, SealedBlockWithStatus};
8-
use crate::da::L1DataAvailabilityMode;
8+
use crate::da::{DataAvailabilityMode, L1DataAvailabilityMode};
99
use crate::state::StateUpdates;
10-
use crate::transaction::TxWithHash;
10+
use crate::transaction::{InvokeTx, InvokeTxV1, InvokeTxV3, Tx, TxWithHash};
1111
use crate::version::ProtocolVersion;
1212
use crate::ContractAddress;
13+
use crate::Felt;
1314

1415
impl From<FgwBlock> for SealedBlockWithStatus {
1516
fn from(value: FgwBlock) -> Self {
@@ -109,8 +110,37 @@ impl From<ResourcePrice> for GasPrices {
109110
}
110111
}
111112

112-
impl From<InvokeFunctionTransaction> for TxWithHash {
113-
fn from(value: InvokeFunctionTransaction) -> Self {
114-
todo!()
113+
impl TryFrom<InvokeFunctionTransaction> for TxWithHash {
114+
type Error = ();
115+
116+
fn try_from(value: InvokeFunctionTransaction) -> Result<Self, Self::Error> {
117+
let tx = if value.version == Felt::ONE {
118+
InvokeTx::V1(InvokeTxV1 {
119+
chain_id: Default::default(),
120+
sender_address: value.sender_address.into(),
121+
nonce: value.nonce.unwrap_or_default(),
122+
calldata: value.calldata,
123+
signature: value.signature,
124+
max_fee: value.max_fee.and_then(|f| f.to_u128()).unwrap_or_default(),
125+
})
126+
} else if value.version == Felt::THREE {
127+
InvokeTx::V3(InvokeTxV3 {
128+
chain_id: Default::default(),
129+
sender_address: value.sender_address.into(),
130+
nonce: value.nonce.unwrap_or_default(),
131+
calldata: value.calldata,
132+
signature: value.signature,
133+
resource_bounds: Default::default(),
134+
tip: value.tip.unwrap_or_default(),
135+
paymaster_data: value.paymaster_data.unwrap_or_default(),
136+
account_deployment_data: value.account_deployment_data.unwrap_or_default(),
137+
nonce_data_availability_mode: DataAvailabilityMode::L1,
138+
fee_data_availability_mode: DataAvailabilityMode::L1,
139+
})
140+
} else {
141+
panic!("Unsupported invoke transaction version")
142+
};
143+
144+
Ok(TxWithHash { hash: value.transaction_hash.into(), transaction: Tx::Invoke(tx) })
115145
}
116146
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::block::{BlockHash, BlockNumber, GasPrices};
2+
use crate::da::L1DataAvailabilityMode;
3+
use crate::version::ProtocolVersion;
4+
use crate::{ContractAddress, Felt};
5+
6+
#[derive(Debug, Clone, PartialEq, Eq)]
7+
#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
8+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9+
pub struct Header {
10+
pub parent_hash: BlockHash,
11+
pub number: BlockNumber,
12+
pub state_diff_length: u32,
13+
pub state_diff_commitment: Felt,
14+
pub transactions_commitment: Felt,
15+
pub receipts_commitment: Felt,
16+
pub events_commitment: Felt,
17+
pub state_root: Felt,
18+
pub timestamp: u64,
19+
pub sequencer_address: ContractAddress,
20+
pub l1_gas_prices: GasPrices,
21+
pub l1_data_gas_prices: GasPrices,
22+
pub l1_da_mode: L1DataAvailabilityMode,
23+
pub protocol_version: ProtocolVersion,
24+
}

crates/katana/primitives/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod event;
1111
pub mod fee;
1212
pub mod feeder_gateway;
1313
pub mod genesis;
14+
pub mod header;
1415
pub mod message;
1516
pub mod receipt;
1617
pub mod trace;

0 commit comments

Comments
 (0)