Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Nov 28, 2024
1 parent 2db8472 commit fde2d2b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/katana/primitives/src/fee.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ResourceBounds {
Expand All @@ -8,7 +8,7 @@ pub struct ResourceBounds {
pub max_price_per_unit: u128,
}

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ResourceBoundsMapping {
Expand Down
40 changes: 35 additions & 5 deletions crates/katana/primitives/src/feeder_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use starknet::providers::sequencer::models::{
};

use crate::block::{FinalityStatus, GasPrices, Header, SealedBlock, SealedBlockWithStatus};
use crate::da::L1DataAvailabilityMode;
use crate::da::{DataAvailabilityMode, L1DataAvailabilityMode};
use crate::state::StateUpdates;
use crate::transaction::TxWithHash;
use crate::transaction::{InvokeTx, InvokeTxV1, InvokeTxV3, Tx, TxWithHash};
use crate::version::ProtocolVersion;
use crate::ContractAddress;
use crate::Felt;

impl From<FgwBlock> for SealedBlockWithStatus {
fn from(value: FgwBlock) -> Self {
Expand Down Expand Up @@ -109,8 +110,37 @@ impl From<ResourcePrice> for GasPrices {
}
}

impl From<InvokeFunctionTransaction> for TxWithHash {
fn from(value: InvokeFunctionTransaction) -> Self {
todo!()
impl TryFrom<InvokeFunctionTransaction> for TxWithHash {
type Error = ();

fn try_from(value: InvokeFunctionTransaction) -> Result<Self, Self::Error> {
let tx = if value.version == Felt::ONE {
InvokeTx::V1(InvokeTxV1 {
chain_id: Default::default(),
sender_address: value.sender_address.into(),
nonce: value.nonce.unwrap_or_default(),
calldata: value.calldata,
signature: value.signature,
max_fee: value.max_fee.and_then(|f| f.to_u128()).unwrap_or_default(),
})
} else if value.version == Felt::THREE {
InvokeTx::V3(InvokeTxV3 {
chain_id: Default::default(),
sender_address: value.sender_address.into(),
nonce: value.nonce.unwrap_or_default(),
calldata: value.calldata,
signature: value.signature,
resource_bounds: Default::default(),
tip: value.tip.unwrap_or_default(),
paymaster_data: value.paymaster_data.unwrap_or_default(),
account_deployment_data: value.account_deployment_data.unwrap_or_default(),
nonce_data_availability_mode: DataAvailabilityMode::L1,
fee_data_availability_mode: DataAvailabilityMode::L1,
})
} else {
panic!("Unsupported invoke transaction version")
};

Ok(TxWithHash { hash: value.transaction_hash.into(), transaction: Tx::Invoke(tx) })
}
}
24 changes: 24 additions & 0 deletions crates/katana/primitives/src/header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::block::{BlockHash, BlockNumber, GasPrices};
use crate::da::L1DataAvailabilityMode;
use crate::version::ProtocolVersion;
use crate::{ContractAddress, Felt};

#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Header {
pub parent_hash: BlockHash,
pub number: BlockNumber,
pub state_diff_length: u32,
pub state_diff_commitment: Felt,
pub transactions_commitment: Felt,
pub receipts_commitment: Felt,
pub events_commitment: Felt,
pub state_root: Felt,
pub timestamp: u64,
pub sequencer_address: ContractAddress,
pub l1_gas_prices: GasPrices,
pub l1_data_gas_prices: GasPrices,
pub l1_da_mode: L1DataAvailabilityMode,
pub protocol_version: ProtocolVersion,
}
1 change: 1 addition & 0 deletions crates/katana/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod event;
pub mod fee;
pub mod feeder_gateway;
pub mod genesis;
pub mod header;
pub mod message;
pub mod receipt;
pub mod trace;
Expand Down

0 comments on commit fde2d2b

Please sign in to comment.