Skip to content

Commit

Permalink
gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcaron committed Sep 10, 2024
1 parent 0606505 commit 38256b5
Show file tree
Hide file tree
Showing 49 changed files with 2,004 additions and 84 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
workflow_dispatch:
pull_request:
branches: [main]
types: [opened, synchronize, reopened, ready_for_review]

concurrency:
group: pr-checks-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand All @@ -16,24 +17,29 @@ permissions:
jobs:
changelog:
name: Enforce CHANGELOG
if: github.event.pull_request.draft == false
uses: ./.github/workflows/changelog.yml

linters:
name: Run linters
if: github.event.pull_request.draft == false
uses: ./.github/workflows/linters.yml
needs: changelog

rust_check:
name: Run check
if: github.event.pull_request.draft == false
uses: ./.github/workflows/rust-check.yml
needs: changelog

linters_cargo:
name: Run Cargo linters
if: github.event.pull_request.draft == false
uses: ./.github/workflows/linters-cargo.yml
needs: rust_check

coverage:
name: Run Coverage
if: github.event.pull_request.draft == false
uses: ./.github/workflows/coverage.yml
needs: changelog
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- feat: new crate gateway client & server
- feat: add devnet via `--devnet` cli argument
- refactor: class import from FGW
- code docs: documented how get_storage_at is implemented
Expand Down
79 changes: 75 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"crates/client/sync",
"crates/client/eth",
"crates/client/rpc",
"crates/client/gateway",
"crates/client/telemetry",
"crates/client/metrics",
"crates/client/devnet",
Expand All @@ -15,6 +16,7 @@ members = [
"crates/primitives/convert",
"crates/primitives/transactions",
"crates/primitives/class",
"crates/primitives/gateway",
"crates/primitives/receipt",
"crates/primitives/state_update",
"crates/primitives/chain_config",
Expand All @@ -28,6 +30,7 @@ default-members = [
"crates/client/exec",
"crates/client/sync",
"crates/client/eth",
"crates/client/gateway",
"crates/client/rpc",
"crates/client/telemetry",
"crates/client/metrics",
Expand All @@ -39,6 +42,7 @@ default-members = [
"crates/primitives/convert",
"crates/primitives/transactions",
"crates/primitives/class",
"crates/primitives/gateway",
"crates/primitives/receipt",
"crates/primitives/state_update",
"crates/primitives/chain_config",
Expand Down Expand Up @@ -88,6 +92,7 @@ mp-block = { path = "crates/primitives/block", default-features = false }
mp-convert = { path = "crates/primitives/convert", default-features = false }
mp-transactions = { path = "crates/primitives/transactions", default-features = false }
mp-class = { path = "crates/primitives/class", default-features = false }
mp-gateway = { path = "crates/primitives/gateway", default-features = false }
mp-receipt = { path = "crates/primitives/receipt", default-features = false }
mp-state-update = { path = "crates/primitives/state_update", default-features = false }
mp-utils = { path = "crates/primitives/utils", default-features = false }
Expand All @@ -98,6 +103,7 @@ mc-telemetry = { path = "crates/client/telemetry" }
mc-db = { path = "crates/client/db" }
mc-exec = { path = "crates/client/exec" }
mc-rpc = { path = "crates/client/rpc" }
mc-gateway = { path = "crates/client/gateway" }
mc-sync = { path = "crates/client/sync" }
mc-eth = { path = "crates/client/eth" }
mc-metrics = { path = "crates/client/metrics" }
Expand Down Expand Up @@ -158,6 +164,7 @@ rand = "0.8"
reqwest = { version = "0.12", features = ["json"] }
rstest = "0.18"
serde = { version = "1.0", default-features = false, features = ["std"] }
serde_with = "3.9"
serde_json = { version = "1.0", default-features = false, features = ["std"] }
thiserror = "1.0"
tokio = { version = "1.34", features = ["signal"] }
Expand Down
8 changes: 4 additions & 4 deletions crates/client/block_import/src/verify_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ fn block_hash(
parent_block_hash,
block_number,
global_state_root,
sequencer_address,
sequencer_address: Some(sequencer_address),
block_timestamp,
transaction_count,
transaction_commitment,
event_count,
event_commitment,
state_diff_length,
state_diff_commitment,
receipt_commitment,
state_diff_length: Some(state_diff_length),
state_diff_commitment: Some(state_diff_commitment),
receipt_commitment: Some(receipt_commitment),
protocol_version,
l1_gas_price,
l1_da_mode,
Expand Down
2 changes: 1 addition & 1 deletion crates/client/exec/src/block_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl ExecutionContext {
block.header.protocol_version,
block.header.block_number,
block.header.block_timestamp,
block.header.sequencer_address,
block.header.sequencer_address.unwrap_or_default(),
block.header.l1_gas_price.clone(),
block.header.l1_da_mode,
),
Expand Down
38 changes: 38 additions & 0 deletions crates/client/gateway/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
description = "Madara client rpc service"
name = "mc-gateway"
authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true
homepage.workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]

# Deoxys
mc-db = { workspace = true }
mp-block = { workspace = true }
mp-gateway = { workspace = true }
mp-utils = { workspace = true }

# Starknet
starknet-core = { workspace = true }
starknet-types-core = { workspace = true }

# Other
anyhow = { workspace = true }
hyper = { workspace = true }
log = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
url = { workspace = true }

[dev-dependencies]
tokio = { workspace = true }
45 changes: 45 additions & 0 deletions crates/client/gateway/src/client/builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use std::collections::HashMap;

use reqwest::Client;
use url::Url;

#[derive(Debug, Clone)]
pub struct FeederClient {
pub(crate) client: Client,
pub(crate) gateway_url: Url,
pub(crate) feeder_gateway_url: Url,
pub(crate) headers: HashMap<String, String>,
}

impl FeederClient {
pub fn new(gateway_url: Url, feeder_gateway_url: Url) -> Self {
Self { client: Client::new(), gateway_url, feeder_gateway_url, headers: HashMap::new() }
}

pub fn new_with_headers(gateway_url: Url, feeder_gateway_url: Url, headers: &[(String, String)]) -> Self {
let headers = headers.iter().cloned().collect();
Self { client: Client::new(), gateway_url, feeder_gateway_url, headers }
}

pub fn add_header(&mut self, key: &str, value: &str) {
self.headers.insert(key.to_string(), value.to_string());
}

pub fn remove_header(&mut self, key: &str) -> Option<String> {
self.headers.remove(key)
}

pub fn starknet_alpha_mainnet() -> Self {
Self::new(
Url::parse("https://alpha-mainnet.starknet.io/gateway/").unwrap(),
Url::parse("https://alpha-mainnet.starknet.io/feeder_gateway/").unwrap(),
)
}

pub fn starknet_alpha_sepolia() -> Self {
Self::new(
Url::parse("https://alpha-sepolia.starknet.io/gateway/").unwrap(),
Url::parse("https://alpha-sepolia.starknet.io/feeder_gateway/").unwrap(),
)
}
}
Loading

0 comments on commit 38256b5

Please sign in to comment.