Skip to content

Commit a17d6e6

Browse files
authored
refactor(rpc): remove Backend from StarknetApi (#355)
1 parent fe85ddc commit a17d6e6

File tree

40 files changed

+716
-694
lines changed

40 files changed

+716
-694
lines changed

Cargo.lock

Lines changed: 2 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/katana/src/cli/init/mod.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ use anyhow::Context;
6262
use clap::builder::NonEmptyStringValueParser;
6363
use clap::{Args, Subcommand};
6464
use deployment::DeploymentOutcome;
65-
use katana_chain_spec::rollup::{ChainConfigDir, FeeContract};
66-
use katana_chain_spec::{rollup, SettlementLayer};
65+
use katana_chain_spec::rollup::{ChainConfigDir, DEFAULT_APPCHAIN_FEE_TOKEN_ADDRESS};
66+
use katana_chain_spec::{rollup, FeeContracts, SettlementLayer};
6767
use katana_genesis::allocation::DevAllocationsGenerator;
6868
use katana_genesis::constant::DEFAULT_PREFUNDED_ACCOUNT_BALANCE;
6969
use katana_genesis::Genesis;
@@ -246,8 +246,12 @@ impl RollupArgs {
246246
slot::add_paymasters_to_genesis(&mut genesis, &output.slot_paymasters.unwrap_or_default());
247247

248248
// At the moment, the fee token is limited to a predefined token.
249-
let fee_contract = FeeContract::default();
250-
let chain_spec = rollup::ChainSpec { id, genesis, settlement, fee_contract };
249+
let fee_contracts = FeeContracts {
250+
eth: DEFAULT_APPCHAIN_FEE_TOKEN_ADDRESS,
251+
strk: DEFAULT_APPCHAIN_FEE_TOKEN_ADDRESS,
252+
};
253+
254+
let chain_spec = rollup::ChainSpec { id, genesis, settlement, fee_contracts };
251255

252256
if let Some(path) = self.output_path {
253257
let dir = ChainConfigDir::create(path)?;
@@ -384,8 +388,13 @@ impl SovereignArgs {
384388
slot::add_paymasters_to_genesis(&mut genesis, &output.slot_paymasters.unwrap_or_default());
385389

386390
// At the moment, the fee token is limited to a predefined token.
387-
let fee_contract = FeeContract::default();
388-
let chain_spec = rollup::ChainSpec { id, genesis, settlement, fee_contract };
391+
// At the moment, the fee token is limited to a predefined token.
392+
let fee_contracts = FeeContracts {
393+
eth: DEFAULT_APPCHAIN_FEE_TOKEN_ADDRESS,
394+
strk: DEFAULT_APPCHAIN_FEE_TOKEN_ADDRESS,
395+
};
396+
397+
let chain_spec = rollup::ChainSpec { id, genesis, settlement, fee_contracts };
389398

390399
if let Some(path) = self.output_path {
391400
let dir = ChainConfigDir::create(path)?;

crates/chain-spec/src/dev.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ use katana_primitives::utils::split_u256;
2020
use katana_primitives::version::StarknetVersion;
2121
use katana_primitives::Felt;
2222
use lazy_static::lazy_static;
23-
use serde::{Deserialize, Serialize};
2423
use starknet::core::utils::cairo_short_string_to_felt;
2524

26-
use crate::SettlementLayer;
25+
use crate::{FeeContracts, SettlementLayer};
2726

2827
#[derive(Debug, Clone, PartialEq, Eq)]
2928
pub struct ChainSpec {
@@ -106,17 +105,6 @@ impl ChainSpec {
106105
}
107106
}
108107

109-
/// Tokens that can be used for transaction fee payments in the chain. As
110-
/// supported on Starknet.
111-
// TODO: include both l1 and l2 addresses
112-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
113-
pub struct FeeContracts {
114-
/// L2 ETH fee token address. Used for paying pre-V3 transactions.
115-
pub eth: ContractAddress,
116-
/// L2 STRK fee token address. Used for paying V3 transactions.
117-
pub strk: ContractAddress,
118-
}
119-
120108
impl Default for ChainSpec {
121109
fn default() -> Self {
122110
DEV.clone()

crates/chain-spec/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ impl ChainSpec {
4444
Self::Rollup(spec) => Some(&spec.settlement),
4545
}
4646
}
47+
48+
pub fn fee_contracts(&self) -> &FeeContracts {
49+
match self {
50+
Self::Dev(spec) => &spec.fee_contracts,
51+
Self::Rollup(spec) => &spec.fee_contracts,
52+
}
53+
}
4754
}
4855

4956
impl From<dev::ChainSpec> for ChainSpec {
@@ -106,3 +113,14 @@ pub enum SettlementLayer {
106113
// availability layer to the chain spec for Katana to sync from it.
107114
},
108115
}
116+
117+
/// Tokens that can be used for transaction fee payments in the chain. As
118+
/// supported on Starknet.
119+
// TODO: include both l1 and l2 addresses
120+
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
121+
pub struct FeeContracts {
122+
/// L2 ETH fee token address. Used for paying pre-V3 transactions.
123+
pub eth: ContractAddress,
124+
/// L2 STRK fee token address. Used for paying V3 transactions.
125+
pub strk: ContractAddress,
126+
}

crates/chain-spec/src/rollup/file.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use std::path::{Path, PathBuf};
55
use katana_genesis::json::GenesisJson;
66
use katana_genesis::Genesis;
77
use katana_primitives::chain::ChainId;
8+
use katana_primitives::ContractAddress;
89
use serde::{Deserialize, Serialize};
910

10-
use super::FeeContract;
1111
use crate::rollup::ChainSpec;
12-
use crate::SettlementLayer;
12+
use crate::{FeeContracts, SettlementLayer};
1313

1414
#[derive(Debug, thiserror::Error)]
1515
pub enum Error {
@@ -86,7 +86,7 @@ pub fn read(dir: &ChainConfigDir) -> Result<ChainSpec, Error> {
8686
genesis,
8787
id: chain_spec.id,
8888
settlement: chain_spec.settlement,
89-
fee_contract: chain_spec.fee_contract,
89+
fee_contracts: chain_spec.fee_contract.into(),
9090
})
9191
}
9292

@@ -95,7 +95,7 @@ pub fn write(dir: &ChainConfigDir, chain_spec: &ChainSpec) -> Result<(), Error>
9595
let cfg = ChainSpecFile {
9696
id: chain_spec.id,
9797
settlement: chain_spec.settlement.clone(),
98-
fee_contract: chain_spec.fee_contract.clone(),
98+
fee_contract: chain_spec.fee_contracts.clone().into(),
9999
};
100100

101101
let content = toml::to_string_pretty(&cfg)?;
@@ -140,11 +140,28 @@ fn list_at<P: AsRef<Path>>(dir: P) -> Result<Vec<ChainId>, Error> {
140140
Ok(chains)
141141
}
142142

143+
#[derive(Debug, Serialize, Deserialize)]
144+
pub struct FileFeeContract {
145+
pub strk: ContractAddress,
146+
}
147+
148+
impl From<FileFeeContract> for FeeContracts {
149+
fn from(fee_contract: FileFeeContract) -> Self {
150+
Self { strk: fee_contract.strk, eth: fee_contract.strk }
151+
}
152+
}
153+
154+
impl From<FeeContracts> for FileFeeContract {
155+
fn from(fee_contracts: FeeContracts) -> Self {
156+
Self { strk: fee_contracts.strk }
157+
}
158+
}
159+
143160
#[derive(Debug, Serialize, Deserialize)]
144161
#[serde(rename_all = "kebab-case")]
145162
struct ChainSpecFile {
146163
id: ChainId,
147-
fee_contract: FeeContract,
164+
fee_contract: FileFeeContract,
148165
settlement: SettlementLayer,
149166
}
150167

@@ -294,8 +311,8 @@ mod tests {
294311

295312
use super::Error;
296313
use crate::rollup::file::{local_dir, ChainConfigDir, LocalChainConfigDir, KATANA_LOCAL_DIR};
297-
use crate::rollup::{ChainSpec, FeeContract};
298-
use crate::SettlementLayer;
314+
use crate::rollup::ChainSpec;
315+
use crate::{FeeContracts, SettlementLayer};
299316

300317
static TEMPDIR: OnceLock<TempDir> = OnceLock::new();
301318

@@ -333,7 +350,10 @@ mod tests {
333350
ChainSpec {
334351
id: ChainId::default(),
335352
genesis: Genesis::default(),
336-
fee_contract: FeeContract { strk: ContractAddress::default() },
353+
fee_contracts: FeeContracts {
354+
eth: ContractAddress::default(),
355+
strk: ContractAddress::default(),
356+
},
337357
settlement: SettlementLayer::Starknet {
338358
block: 0,
339359
id: ChainId::default(),
@@ -353,7 +373,7 @@ mod tests {
353373
let read_spec = read(&id).unwrap();
354374

355375
assert_eq!(chain_spec.id, read_spec.id);
356-
assert_eq!(chain_spec.fee_contract, read_spec.fee_contract);
376+
assert_eq!(chain_spec.fee_contracts, read_spec.fee_contracts);
357377
assert_eq!(chain_spec.settlement, read_spec.settlement);
358378
}
359379

0 commit comments

Comments
 (0)