Skip to content

Commit

Permalink
feat: initial profile and free RPC vendors support
Browse files Browse the repository at this point in the history
Changes what `--network` (or `STARKNET_NETWORK`) does: previously it's
for using the sequencer gateway provider, but now it's for selecting a
network in a profile.

Yes, there's now initial profile support. Users can now define custom
networks in their profiles and simply use the network with `--network`.
The support is quite barebone and only allows defining networks. More
features to be added soon (e.g. account shorthands, address books).

In order to maintain backward compatibility, `--network` still works
with `mainnet`, `goerli`, `sepolia` (and their aliases). Under the
hood, a random free RPC vendor is selected and persisted to the default
profile. This allows users to get started with a public network without
having to set up RPC, maintaining the same zero-setup experience as with
the previous sequencer gateway support.
  • Loading branch information
xJonathanLEI committed Dec 28, 2023
1 parent 8c5cd79 commit 27402da
Show file tree
Hide file tree
Showing 28 changed files with 657 additions and 131 deletions.
129 changes: 109 additions & 20 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ clap_complete = "4.3.1"
colored = "2.0.0"
colored_json = "3.2.0"
env_logger = "0.10.0"
etcetera = "0.8.0"
flate2 = "1.0.28"
hex = "0.4.3"
hex-literal = "0.4.1"
indexmap = "2.1.0"
log = "0.4.19"
num-bigint = "0.4.3"
num-integer = "0.1.45"
Expand All @@ -37,6 +39,7 @@ starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "c974e5c
tempfile = "3.8.0"
thiserror = "1.0.40"
tokio = { version = "1.28.2", default-features = false, features = ["macros", "rt-multi-thread"] }
toml = "0.8.8"
url = "2.4.0"

[build-dependencies]
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod decode;
mod fee;
mod network;
mod path;
mod profile;
mod provider;
mod signer;
mod subcommands;
Expand Down
33 changes: 0 additions & 33 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{fmt::Display, str::FromStr};
use anyhow::Result;
use async_trait::async_trait;
use auto_impl::auto_impl;
use clap::{builder::PossibleValue, ValueEnum};
use starknet::{macros::short_string, providers::Provider};

use crate::provider::ExtendedProvider;
Expand All @@ -24,38 +23,6 @@ pub trait NetworkSource {
async fn get_network(&self) -> Result<Option<Network>>;
}

impl ValueEnum for Network {
fn value_variants<'a>() -> &'a [Self] {
&[
Self::Mainnet,
Self::Goerli,
Self::Sepolia,
Self::GoerliIntegration,
Self::SepoliaIntegration,
]
}

fn to_possible_value(&self) -> Option<PossibleValue> {
match self {
Network::Mainnet => Some(PossibleValue::new("mainnet").aliases(["alpha-mainnet"])),
Network::Goerli => Some(PossibleValue::new("goerli-1").aliases([
"goerli",
"goerli1",
"alpha-goerli",
"alpha-goerli1",
"alpha-goerli-1",
])),
Network::Sepolia => {
Some(PossibleValue::new("sepolia").aliases(["alpha-sepolia", "sepolia-testnet"]))
}
Network::GoerliIntegration => {
Some(PossibleValue::new("goerli-integration").aliases(["integration"]))
}
Network::SepoliaIntegration => Some(PossibleValue::new("sepolia-integration")),
}
}
}

impl FromStr for Network {
type Err = anyhow::Error;

Expand Down

0 comments on commit 27402da

Please sign in to comment.