Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pub mod account;
pub mod account_factory;
pub mod address_book;
pub mod block_id;
pub mod casm;
pub mod chain_id;
pub mod compiler;
pub mod decode;
pub mod error;
pub mod fee;
pub mod hd_path;
pub mod network;
pub mod path;
pub mod profile;
pub mod provider;
pub mod signer;
pub mod subcommands;
pub mod utils;
pub mod verbosity;
191 changes: 2 additions & 189 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use anyhow::Result;
use clap::{CommandFactory, Parser, Subcommand};
use clap::Parser;
use colored::Colorize;

use crate::{provider::ProviderArgs, subcommands::*};
use crate::utils::*;

mod account;
mod account_factory;
Expand All @@ -24,196 +23,10 @@ mod subcommands;
mod utils;
mod verbosity;

pub(crate) const JSON_RPC_VERSION: &str = "0.7.1";

const VERSION_STRING: &str = concat!(env!("CARGO_PKG_VERSION"), " (", env!("VERGEN_GIT_SHA"), ")");
const VERSION_STRING_VERBOSE: &str = concat!(
env!("CARGO_PKG_VERSION"),
" (",
env!("VERGEN_GIT_SHA"),
")\n",
"JSON-RPC version: 0.7.1"
);

#[derive(Debug, Parser)]
#[clap(author, about)]
struct Cli {
#[clap(subcommand)]
command: Option<Subcommands>,
#[clap(long = "version", short = 'V', help = "Print version info and exit")]
version: bool,
#[clap(
long = "verbose",
short = 'v',
help = "Use verbose output (currently only applied to version)"
)]
verbose: bool,
}

#[derive(Debug, Subcommand)]
enum Subcommands {
//
// Local utilities
//
#[clap(about = "Calculate selector from name")]
Selector(Selector),
#[clap(about = "Calculate class hash from any contract artifacts (Sierra, casm, legacy)")]
ClassHash(ClassHash),
#[clap(about = "Extract contract ABI from a class artifact (Sierra or legacy)")]
Abi(Abi),
#[clap(about = "Encode string into felt with the Cairo short string representation")]
ToCairoString(ToCairoString),
#[clap(about = "Decode string from felt with the Cairo short string representation")]
ParseCairoString(ParseCairoString),
#[clap(about = "Print the montgomery representation of a field element")]
Mont(Mont),
//
// JSON-RPC query client
//
#[clap(about = "Call contract functions without sending transactions")]
Call(Call),
#[clap(alias = "tx", about = "Get Starknet transaction by hash")]
Transaction(Transaction),
#[clap(alias = "bn", about = "Get latest block number")]
BlockNumber(BlockNumber),
#[clap(about = "Get latest block hash")]
BlockHash(BlockHash),
#[clap(about = "Get Starknet block")]
Block(Block),
#[clap(about = "Get Starknet block timestamp only")]
BlockTime(BlockTime),
#[clap(about = "Get state update from a certain block")]
StateUpdate(StateUpdate),
#[clap(about = "Get all traces from a certain block")]
BlockTraces(BlockTraces),
#[clap(
aliases = ["tx-status", "transaction-status"],
about = "Get transaction status by hash"
)]
Status(TransactionStatus),
#[clap(
aliases = ["tx-receipt", "transaction-receipt"],
about = "Get transaction receipt by hash"
)]
Receipt(TransactionReceipt),
#[clap(about = "Get transaction trace by hash")]
Trace(TransactionTrace),
#[clap(about = "Get Starknet network ID")]
ChainId(ChainId),
#[clap(about = "Get native gas token (currently ETH) balance")]
Balance(Balance),
#[clap(about = "Get nonce for a certain contract")]
Nonce(Nonce),
#[clap(about = "Get storage value for a slot at a contract")]
Storage(Storage),
#[clap(about = "Get contract class hash deployed at a certain address")]
ClassHashAt(ClassHashAt),
#[clap(about = "Get contract class by hash")]
ClassByHash(ClassByHash),
#[clap(about = "Get contract class deployed at a certain address")]
ClassAt(ClassAt),
#[clap(about = "Get node syncing status")]
Syncing(Syncing),
#[clap(about = "Get node spec version")]
SpecVersion(SpecVersion),
//
// Signer management
//
#[clap(about = "Signer management commands")]
Signer(Signer),
#[clap(about = "Shortcut for `starkli signer ledger`")]
Ledger(crate::subcommands::signer::ledger::Ledger),
#[clap(aliases = ["erc2645"], about = "EIP-2645 helper commands")]
Eip2645(Eip2645),
//
// Account management
//
#[clap(about = "Account management commands")]
Account(Account),
//
// Sending out transactions
//
#[clap(about = "Send an invoke transaction from an account contract")]
Invoke(Invoke),
#[clap(about = "Declare a contract class")]
Declare(Declare),
#[clap(about = "Deploy contract via the Universal Deployer Contract")]
Deploy(Deploy),
//
// Misc
//
#[clap(about = "Generate shell completions script")]
Completions(Completions),
//
// Experimental
//
#[clap(
about = "Experimental commands for fun and profit",
long_about = "Experimental new commands that are shipped with no stability guarantee. \
They might break or be removed anytime."
)]
Lab(Lab),
}

#[tokio::main]
async fn main() {
if let Err(err) = run_command(Cli::parse()).await {
eprintln!("{}", format!("Error: {err}").red());
std::process::exit(1);
}
}

async fn run_command(cli: Cli) -> Result<()> {
match (cli.version, cli.command) {
(false, None) => Ok(Cli::command().print_help()?),
(true, _) => {
println!(
"{}",
if cli.verbose {
VERSION_STRING_VERBOSE
} else {
VERSION_STRING
}
);

Ok(())
}
(false, Some(command)) => match command {
Subcommands::Selector(cmd) => cmd.run(),
Subcommands::ClassHash(cmd) => cmd.run(),
Subcommands::Abi(cmd) => cmd.run(),
Subcommands::ToCairoString(cmd) => cmd.run(),
Subcommands::ParseCairoString(cmd) => cmd.run(),
Subcommands::Mont(cmd) => cmd.run(),
Subcommands::Call(cmd) => cmd.run().await,
Subcommands::Transaction(cmd) => cmd.run().await,
Subcommands::BlockNumber(cmd) => cmd.run().await,
Subcommands::BlockHash(cmd) => cmd.run().await,
Subcommands::Block(cmd) => cmd.run().await,
Subcommands::BlockTime(cmd) => cmd.run().await,
Subcommands::StateUpdate(cmd) => cmd.run().await,
Subcommands::BlockTraces(cmd) => cmd.run().await,
Subcommands::Status(cmd) => cmd.run().await,
Subcommands::Receipt(cmd) => cmd.run().await,
Subcommands::Trace(cmd) => cmd.run().await,
Subcommands::ChainId(cmd) => cmd.run().await,
Subcommands::Balance(cmd) => cmd.run().await,
Subcommands::Nonce(cmd) => cmd.run().await,
Subcommands::Storage(cmd) => cmd.run().await,
Subcommands::ClassHashAt(cmd) => cmd.run().await,
Subcommands::ClassByHash(cmd) => cmd.run().await,
Subcommands::ClassAt(cmd) => cmd.run().await,
Subcommands::Syncing(cmd) => cmd.run().await,
Subcommands::SpecVersion(cmd) => cmd.run().await,
Subcommands::Signer(cmd) => cmd.run().await,
Subcommands::Ledger(cmd) => cmd.run().await,
Subcommands::Eip2645(cmd) => cmd.run(),
Subcommands::Account(cmd) => cmd.run().await,
Subcommands::Invoke(cmd) => cmd.run().await,
Subcommands::Declare(cmd) => cmd.run().await,
Subcommands::Deploy(cmd) => cmd.run().await,
Subcommands::Completions(cmd) => cmd.run(),
Subcommands::Lab(cmd) => cmd.run(),
},
}
}
2 changes: 1 addition & 1 deletion src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
profile::{
FreeProviderVendor, NetworkProvider, Profile, Profiles, RpcProvider, DEFAULT_PROFILE_NAME,
},
JSON_RPC_VERSION,
utils::JSON_RPC_VERSION,
};

const CHAIN_ID_MAINNET: Felt = short_string!("SN_MAIN");
Expand Down
32 changes: 25 additions & 7 deletions src/subcommands/account/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use crate::{
error::account_factory_error_mapper,
fee::{FeeArgs, FeeSetting, FeeToken, TokenFeeSetting},
path::ExpandedPathbufParser,
provider::ProviderArgs,
signer::SignerArgs,
utils::{felt_to_bigdecimal, print_colored_json, watch_tx},
verbosity::VerbosityArgs,
ProviderArgs,
};

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -52,6 +52,8 @@ pub struct Deploy {
file: PathBuf,
#[clap(flatten)]
verbosity: VerbosityArgs,
#[clap(long)]
skip_manual_confirmation: bool,
}

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -246,7 +248,12 @@ impl Deploy {
return Ok(());
}

fee_prompt(fee_type, target_deployment_address, FeeToken::Eth)?;
fee_prompt(
fee_type,
target_deployment_address,
FeeToken::Eth,
self.skip_manual_confirmation,
)?;

account_deployment.send().await
}
Expand Down Expand Up @@ -368,7 +375,12 @@ impl Deploy {
return Ok(());
}

fee_prompt(fee_type, target_deployment_address, FeeToken::Strk)?;
fee_prompt(
fee_type,
target_deployment_address,
FeeToken::Strk,
self.skip_manual_confirmation,
)?;

account_deployment.send().await
}
Expand Down Expand Up @@ -420,7 +432,12 @@ impl Deploy {
}
}

fn fee_prompt(fee_type: MaxFeeType, deployed_address: Felt, fee_token: FeeToken) -> Result<()> {
fn fee_prompt(
fee_type: MaxFeeType,
deployed_address: Felt,
fee_token: FeeToken,
skip_manual_confirmation: bool,
) -> Result<()> {
match fee_type {
MaxFeeType::Manual { max_fee } => {
eprintln!(
Expand Down Expand Up @@ -453,9 +470,10 @@ fn fee_prompt(fee_type: MaxFeeType, deployed_address: Felt, fee_token: FeeToken)
format!("{:#064x}", deployed_address).bright_yellow()
);

// TODO: add flag for skipping this manual confirmation step
eprint!("Press [ENTER] once you've funded the address.");
std::io::stdin().read_line(&mut String::new())?;
if !skip_manual_confirmation {
eprint!("Press [ENTER] once you've funded the address.");
std::io::stdin().read_line(&mut String::new())?;
}

Ok(())
}
2 changes: 1 addition & 1 deletion src/subcommands/account/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::{
BraavosMultisigConfig, BraavosSigner, BraavosStarkSigner, DeployedStatus, DeploymentStatus,
OzAccountConfig, KNOWN_ACCOUNT_CLASSES,
},
provider::ProviderArgs,
verbosity::VerbosityArgs,
ProviderArgs,
};

#[derive(Debug, Parser)]
Expand Down
3 changes: 2 additions & 1 deletion src/subcommands/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use starknet::{
};

use crate::{
address_book::AddressBookResolver, decode::FeltDecoder, verbosity::VerbosityArgs, ProviderArgs,
address_book::AddressBookResolver, decode::FeltDecoder, provider::ProviderArgs,
verbosity::VerbosityArgs,
};

/// The default ETH address: 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7.
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::Parser;
use colored_json::{ColorMode, Output};
use starknet::{core::types::BlockId, providers::Provider};

use crate::{block_id::BlockIdParser, verbosity::VerbosityArgs, ProviderArgs};
use crate::{block_id::BlockIdParser, provider::ProviderArgs, verbosity::VerbosityArgs};

#[derive(Debug, Parser)]
pub struct Block {
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/block_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use clap::Parser;
use starknet::providers::Provider;

use crate::{verbosity::VerbosityArgs, ProviderArgs};
use crate::{provider::ProviderArgs, verbosity::VerbosityArgs};

#[derive(Debug, Parser)]
pub struct BlockHash {
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/block_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use clap::Parser;
use starknet::providers::Provider;

use crate::{verbosity::VerbosityArgs, ProviderArgs};
use crate::{provider::ProviderArgs, verbosity::VerbosityArgs};

#[derive(Debug, Parser)]
pub struct BlockNumber {
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/block_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use starknet::{
providers::Provider,
};

use crate::{block_id::BlockIdParser, verbosity::VerbosityArgs, ProviderArgs};
use crate::{block_id::BlockIdParser, provider::ProviderArgs, verbosity::VerbosityArgs};

#[derive(Debug, Parser)]
pub struct BlockTime {
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/block_traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::Parser;
use colored_json::{ColorMode, Output};
use starknet::{core::types::BlockId, providers::Provider};

use crate::{block_id::BlockIdParser, verbosity::VerbosityArgs, ProviderArgs};
use crate::{block_id::BlockIdParser, provider::ProviderArgs, verbosity::VerbosityArgs};

#[derive(Debug, Parser)]
pub struct BlockTraces {
Expand Down
Loading