From 2dd3eada036c68ad6740c0ea6473107d816bbeed Mon Sep 17 00:00:00 2001 From: Ammar Arif Date: Sat, 18 Jan 2025 19:00:58 -0500 Subject: [PATCH] feat(katana): remove support for initializing custom settlement chain (#2927) We can't support custom chain for now as we're relying heavily on the Atlantic service for setting the proofs and currently it is limited to only Starknet Sepolia. --- Cargo.lock | 1 + bin/katana/Cargo.toml | 2 ++ bin/katana/src/cli/init/mod.rs | 41 ++++++++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49d8ec1f03..7569fed7c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8453,6 +8453,7 @@ dependencies = [ "shellexpand", "spinoff", "starknet 0.12.0", + "strum_macros 0.25.3", "thiserror 1.0.63", "tokio", "toml 0.8.19", diff --git a/bin/katana/Cargo.toml b/bin/katana/Cargo.toml index 859eab2c8f..9ca65ae85e 100644 --- a/bin/katana/Cargo.toml +++ b/bin/katana/Cargo.toml @@ -28,6 +28,7 @@ serde.workspace = true shellexpand = "3.1.0" spinoff.workspace = true starknet.workspace = true +strum_macros.workspace = true thiserror.workspace = true tokio.workspace = true toml.workspace = true @@ -41,5 +42,6 @@ starknet.workspace = true [features] default = [ "jemalloc", "katana-cli/slot" ] +init-custom-settlement-chain = [ ] jemalloc = [ ] starknet-messaging = [ "katana-cli/starknet-messaging" ] diff --git a/bin/katana/src/cli/init/mod.rs b/bin/katana/src/cli/init/mod.rs index 908e907265..2c41426588 100644 --- a/bin/katana/src/cli/init/mod.rs +++ b/bin/katana/src/cli/init/mod.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use anyhow::{Context, Result}; use clap::Args; -use inquire::{Confirm, CustomType, Text}; +use inquire::{Confirm, CustomType, Select, Text}; use katana_primitives::{ContractAddress, Felt}; use serde::{Deserialize, Serialize}; use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount}; @@ -19,6 +19,8 @@ use starknet::providers::{JsonRpcClient, Provider, Url}; use starknet::signers::{LocalWallet, SigningKey}; use tokio::runtime::Runtime; +const CARTRIDGE_SN_SEPOLIA_PROVIDER: &str = "https://api.cartridge.gg/x/starknet/sepolia"; + #[derive(Debug)] struct InitInput { /// the account address that is used to send the transactions for contract @@ -117,12 +119,37 @@ impl InitArgs { fn prompt(&self, rt: &Runtime) -> Result { let chain_id = Text::new("Id").prompt()?; - let url = CustomType::::new("Settlement RPC URL") - .with_default(Url::parse("http://localhost:5050")?) - .with_error_message("Please enter a valid URL") - .prompt()?; + #[derive(Debug, strum_macros::Display)] + enum SettlementChainOpt { + Sepolia, + #[cfg(feature = "init-custom-settlement-chain")] + Custom, + } + + // Right now we only support settling on Starknet Sepolia because we're limited to what + // network the Atlantic service could settle the proofs to. Supporting a custom + // network here (eg local devnet) would require that the proving service we're using + // be able to settle the proofs there. + let network_opts = vec![ + SettlementChainOpt::Sepolia, + #[cfg(feature = "init-custom-settlement-chain")] + SettlementChainOpt::Custom, + ]; + + let network_type = Select::new("Select settlement chain", network_opts).prompt()?; + + let settlement_url = match network_type { + SettlementChainOpt::Sepolia => Url::parse(CARTRIDGE_SN_SEPOLIA_PROVIDER)?, + + // Useful for testing the program flow without having to run it against actual network. + #[cfg(feature = "init-custom-settlement-chain")] + SettlementChainOpt::Custom => CustomType::::new("Settlement RPC URL") + .with_default(Url::parse("http://localhost:5050")?) + .with_error_message("Please enter a valid URL") + .prompt()?, + }; - let l1_provider = Arc::new(JsonRpcClient::new(HttpTransport::new(url.clone()))); + let l1_provider = Arc::new(JsonRpcClient::new(HttpTransport::new(settlement_url.clone()))); let contract_exist_parser = &|input: &str| { let block_id = BlockId::Tag(BlockTag::Pending); @@ -192,7 +219,7 @@ impl InitArgs { settlement_id: parse_cairo_short_string(&l1_chain_id)?, id: chain_id, fee_token, - rpc_url: url, + rpc_url: settlement_url, output_path, }) }