Skip to content

Commit

Permalink
Merge pull request #367 from eqlabs/sequencer_builder
Browse files Browse the repository at this point in the history
feat: sequencer builder
  • Loading branch information
Mirko-von-Leipzig authored Jun 14, 2022
2 parents 2bdb9dc + 4616be7 commit 0b4d20b
Show file tree
Hide file tree
Showing 8 changed files with 1,211 additions and 750 deletions.
47 changes: 47 additions & 0 deletions crates/pathfinder/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ pub struct EthereumTransactionIndex(pub u64);
#[derive(Debug, Copy, Clone, PartialEq, Hash, Eq)]
pub struct EthereumLogIndex(pub u64);

/// A way of identifying a specific block.
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum BlockId {
Number(StarknetBlockNumber),
Hash(StarknetBlockHash),
Latest,
Pending,
}

impl StarknetBlockNumber {
pub const GENESIS: StarknetBlockNumber = StarknetBlockNumber(0);
}
Expand Down Expand Up @@ -276,3 +285,41 @@ impl From<u64> for GasPrice {
Self(u128::from(src))
}
}

impl From<crate::rpc::types::BlockNumberOrTag> for BlockId {
fn from(block: crate::rpc::types::BlockNumberOrTag) -> Self {
use crate::rpc::types::BlockNumberOrTag::*;
use crate::rpc::types::Tag::*;

match block {
Number(number) => Self::Number(number),
Tag(Latest) => Self::Latest,
Tag(Pending) => Self::Pending,
}
}
}

impl From<crate::rpc::types::BlockHashOrTag> for BlockId {
fn from(block: crate::rpc::types::BlockHashOrTag) -> Self {
use crate::rpc::types::BlockHashOrTag::*;
use crate::rpc::types::Tag::*;

match block {
Hash(hash) => Self::Hash(hash),
Tag(Latest) => Self::Latest,
Tag(Pending) => Self::Pending,
}
}
}

impl From<StarknetBlockNumber> for BlockId {
fn from(number: StarknetBlockNumber) -> Self {
Self::Number(number)
}
}

impl From<StarknetBlockHash> for BlockId {
fn from(hash: StarknetBlockHash) -> Self {
Self::Hash(hash)
}
}
12 changes: 6 additions & 6 deletions crates/pathfinder/src/rpc/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl RpcApi {
BlockHashOrTag::Tag(Tag::Pending) => {
let block = self
.sequencer
.block_by_hash(block_hash)
.block(block_hash.into())
.await
.map_err(internal_server_error)?;

Expand Down Expand Up @@ -218,7 +218,7 @@ impl RpcApi {
BlockNumberOrTag::Tag(Tag::Pending) => {
let block = self
.sequencer
.block_by_number(block_number)
.block(block_number.into())
.await
.context("Fetch block from sequencer")
.map_err(internal_server_error)?;
Expand Down Expand Up @@ -514,7 +514,7 @@ impl RpcApi {
BlockHashOrTag::Tag(Tag::Pending) => {
let block = self
.sequencer
.block_by_hash(block_hash)
.block(block_hash.into())
.await
.context("Fetch block from sequencer")
.map_err(internal_server_error)?;
Expand Down Expand Up @@ -589,7 +589,7 @@ impl RpcApi {
BlockNumberOrTag::Tag(Tag::Pending) => {
let block = self
.sequencer
.block_by_number(block_number)
.block(block_number.into())
.await
.context("Fetch block from sequencer")
.map_err(internal_server_error)?;
Expand Down Expand Up @@ -747,7 +747,7 @@ impl RpcApi {
BlockHashOrTag::Tag(Tag::Pending) => {
let block = self
.sequencer
.block_by_hash(block_hash)
.block(block_hash.into())
.await
.context("Fetch block from sequencer")
.map_err(internal_server_error)?;
Expand Down Expand Up @@ -814,7 +814,7 @@ impl RpcApi {
BlockNumberOrTag::Tag(Tag::Pending) => {
let block = self
.sequencer
.block_by_number(block_number)
.block(block_number.into())
.await
.context("Fetch block from sequencer")
.map_err(internal_server_error)?;
Expand Down
Loading

0 comments on commit 0b4d20b

Please sign in to comment.