Skip to content

Commit

Permalink
feat: introduce rpc starknet_getMessagesStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
t00ts committed Oct 22, 2024
1 parent a9cab1d commit fb6f46d
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 95 deletions.
111 changes: 111 additions & 0 deletions crates/common/src/l1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
use pathfinder_crypto::Felt;
use primitive_types::H256;

use crate::macros;

/// An Ethereum block number.
#[derive(Copy, Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct L1BlockNumber(u64);

macros::fmt::thin_display!(L1BlockNumber);

macros::i64_backed_u64::new_get_partialeq!(L1BlockNumber);
macros::i64_backed_u64::serdes!(L1BlockNumber);

impl From<L1BlockNumber> for Felt {
fn from(x: L1BlockNumber) -> Self {
Felt::from(x.0)
}
}

impl std::iter::Iterator for L1BlockNumber {
type Item = L1BlockNumber;

fn next(&mut self) -> Option<Self::Item> {
Some(*self + 1)
}
}

impl L1BlockNumber {
pub const GENESIS: L1BlockNumber = L1BlockNumber::new_or_panic(0);
}

impl std::ops::Add<u64> for L1BlockNumber {
type Output = L1BlockNumber;

fn add(self, rhs: u64) -> Self::Output {
Self(self.0 + rhs)
}
}

impl std::ops::AddAssign<u64> for L1BlockNumber {
fn add_assign(&mut self, rhs: u64) {
self.0 += rhs;
}
}

impl std::ops::Sub<u64> for L1BlockNumber {
type Output = L1BlockNumber;

fn sub(self, rhs: u64) -> Self::Output {
Self(self.0 - rhs)
}
}

impl std::ops::SubAssign<u64> for L1BlockNumber {
fn sub_assign(&mut self, rhs: u64) {
self.0 -= rhs;
}
}

/// An Ethereum transaction hash.
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct L1TransactionHash(H256);

macros::fmt::thin_display!(L1TransactionHash);
macros::fmt::thin_debug!(L1TransactionHash);

impl L1TransactionHash {
/// Creates a new `L1TransactionHash` from a `H256`.
pub fn new(hash: H256) -> Self {
Self(hash)
}

/// Returns the raw bytes of the transaction hash.
pub fn as_bytes(&self) -> &[u8] {
self.0.as_bytes()
}

/// Creates a new `L1TransactionHash` from a slice of bytes.
///
/// # Panics
///
/// If the length of the byte slice is not 32.
pub fn from_slice(bytes: &[u8]) -> Self {
Self(H256::from_slice(bytes))
}
}

impl From<H256> for L1TransactionHash {
fn from(hash: H256) -> Self {
Self(hash)
}
}

impl From<L1TransactionHash> for H256 {
fn from(tx_hash: L1TransactionHash) -> Self {
tx_hash.0
}
}

impl From<[u8; 32]> for L1TransactionHash {
fn from(bytes: [u8; 32]) -> Self {
Self(H256::from(bytes))
}
}

impl AsRef<[u8]> for L1TransactionHash {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
15 changes: 13 additions & 2 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub mod error;
pub mod event;
pub mod hash;
mod header;
mod l1;
mod macros;
pub mod message;
pub mod prelude;
pub mod receipt;
pub mod signature;
Expand All @@ -31,7 +31,7 @@ pub mod transaction;
pub mod trie;

pub use header::{BlockHeader, BlockHeaderBuilder, L1DataAvailabilityMode, SignedBlockHeader};
pub use message::L1ToL2MessageLog;
pub use l1::{L1BlockNumber, L1TransactionHash};
pub use signature::BlockCommitmentSignature;
pub use state_update::StateUpdate;

Expand Down Expand Up @@ -435,6 +435,17 @@ impl ChainId {
pub const SEPOLIA_INTEGRATION: Self = Self::from_slice_unwrap(b"SN_INTEGRATION_SEPOLIA");
}

impl From<Chain> for ChainId {
fn from(chain: Chain) -> Self {
match chain {
Chain::Mainnet => ChainId::MAINNET,
Chain::SepoliaTestnet => ChainId::SEPOLIA_TESTNET,
Chain::SepoliaIntegration => ChainId::SEPOLIA_INTEGRATION,
Chain::Custom => panic!("Custom chain is not supported"),
}
}
}

impl std::fmt::Display for Chain {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
8 changes: 0 additions & 8 deletions crates/common/src/message.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ serde_json = { workspace = true }
tokio = { workspace = true, features = ["macros"] }
tracing = { workspace = true }

[dev-dependencies]
Loading

0 comments on commit fb6f46d

Please sign in to comment.