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
1 change: 1 addition & 0 deletions book/src/ref/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Starkli offers the following commands:
- invoke
- declare
- deploy
- upgrade
- completions

To check usage of each command, run with the `--help` option.
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ enum Subcommands {
They might break or be removed anytime."
)]
Lab(Lab),
#[clap(
about = "Upgrade a contract by declaring a new class and invoking the upgrade entrypoint"
)]
Upgrade(Upgrade),
}

#[cfg_attr(target_arch = "wasm32", tokio::main(flavor = "current_thread"))]
Expand Down Expand Up @@ -217,6 +221,7 @@ async fn run_command(cli: Cli) -> Result<()> {
Subcommands::Deploy(cmd) => cmd.run().await,
Subcommands::Completions(cmd) => cmd.run(),
Subcommands::Lab(cmd) => cmd.run(),
Subcommands::Upgrade(cmd) => cmd.run().await,
},
}
}
109 changes: 67 additions & 42 deletions src/subcommands/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,40 @@ use crate::{
#[derive(Debug, Parser)]
pub struct Declare {
#[clap(flatten)]
provider: ProviderArgs,
pub provider: ProviderArgs,
#[clap(flatten)]
account: AccountArgs,
pub account: AccountArgs,
#[clap(flatten)]
casm: CasmArgs,
pub casm: CasmArgs,
#[clap(flatten)]
fee: FeeArgs,
pub fee: FeeArgs,
#[clap(long, help = "Do not publish the ABI of the class")]
no_abi: bool,
pub no_abi: bool,
#[clap(long, help = "Simulate the transaction only")]
simulate: bool,
pub simulate: bool,
#[clap(long, help = "Provide transaction nonce manually")]
nonce: Option<Felt>,
pub nonce: Option<Felt>,
#[clap(long, short, help = "Wait for the transaction to confirm")]
watch: bool,
pub watch: bool,
#[clap(
long,
env = "STARKNET_POLL_INTERVAL",
default_value = "5000",
help = "Transaction result poll interval in milliseconds"
)]
poll_interval: u64,
pub poll_interval: u64,
#[clap(
value_parser = ExpandedPathbufParser,
help = "Path to contract artifact file"
)]
file: PathBuf,
pub file: PathBuf,
#[clap(flatten)]
verbosity: VerbosityArgs,
pub verbosity: VerbosityArgs,
}

pub struct DeclareOutput {
pub class_hash: Felt,
pub transaction_hash: Option<Felt>,
}

enum Declarable {
Expand All @@ -65,6 +70,24 @@ enum Declarable {

impl Declare {
pub async fn run(self) -> Result<()> {
let result = self.run_as_lib().await?;

if let Some(transaction_hash) = result.transaction_hash {
eprintln!(
"Contract declaration transaction: {}",
format!("{:#064x}", transaction_hash).bright_yellow()
);
}

eprintln!("Class hash declared:");

// Only the class hash goes to stdout so this can be easily scripted
println!("{}", format!("{:#064x}", result.class_hash).bright_yellow());

Ok(())
}

pub async fn run_as_lib(self) -> Result<DeclareOutput> {
self.verbosity.setup_logging();

let fee_setting = self.fee.into_setting()?;
Expand Down Expand Up @@ -121,7 +144,10 @@ impl Declare {

// TODO: add option to skip checking
if Self::check_already_declared(&provider, class_hash).await? {
return Ok(());
return Ok(DeclareOutput {
class_hash,
transaction_hash: None,
});
}

// Reconstructs an original Sierra class just for CASM compilation purposes. It's a
Expand Down Expand Up @@ -205,7 +231,10 @@ impl Declare {
format!("{}", felt_to_bigdecimal(estimated_fee, 18))
.bright_yellow(),
);
return Ok(());
return Ok(DeclareOutput {
class_hash,
transaction_hash: None,
});
}
TokenFeeSetting::Manual(fee) => {
let declaration = if let Some(l1_gas) = fee.l1_gas {
Expand Down Expand Up @@ -245,43 +274,39 @@ impl Declare {

if self.simulate {
print_colored_json(&declaration.simulate(false, false).await?)?;
return Ok(());
return Ok(DeclareOutput {
class_hash,
transaction_hash: None,
});
}

let declaration_result =
declaration.send().await.map_err(account_error_mapper)?;

if self.watch {
watch_tx(
&provider,
declaration_result.transaction_hash,
Duration::from_millis(self.poll_interval),
)
.await?;
}

declaration.send().await
(
declaration_result.class_hash,
declaration_result.transaction_hash,
)
}
}
.map_err(account_error_mapper)?
.transaction_hash;
};

(class_hash, declare_tx)
}
};

eprintln!(
"Contract declaration transaction: {}",
format!("{:#064x}", declaration_tx_hash).bright_yellow()
);

if self.watch {
eprintln!(
"Waiting for transaction {} to confirm...",
format!("{:#064x}", declaration_tx_hash).bright_yellow(),
);
watch_tx(
&provider,
declaration_tx_hash,
Duration::from_millis(self.poll_interval),
)
.await?;
}

eprintln!("Class hash declared:");

// Only the class hash goes to stdout so this can be easily scripted
println!("{}", format!("{:#064x}", class_hash).bright_yellow());

Ok(())
Ok(DeclareOutput {
class_hash,
transaction_hash: Some(declaration_tx_hash.1),
})
}

async fn check_already_declared<P>(provider: P, class_hash: Felt) -> Result<bool>
Expand Down
24 changes: 12 additions & 12 deletions src/subcommands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ const DEFAULT_UDC_ADDRESS: Felt =
#[derive(Debug, Parser)]
pub struct Deploy {
#[clap(flatten)]
provider: ProviderArgs,
pub provider: ProviderArgs,
#[clap(flatten)]
account: AccountArgs,
pub account: AccountArgs,
#[clap(long, help = "Do not derive contract address from deployer address")]
not_unique: bool,
pub not_unique: bool,
#[clap(flatten)]
fee: FeeArgs,
pub fee: FeeArgs,
#[clap(long, help = "Simulate the transaction only")]
simulate: bool,
pub simulate: bool,
#[clap(long, help = "Use the given salt to compute contract deploy address")]
salt: Option<String>,
pub salt: Option<String>,
#[clap(long, help = "Provide transaction nonce manually")]
nonce: Option<Felt>,
pub nonce: Option<Felt>,
#[clap(long, short, help = "Wait for the transaction to confirm")]
watch: bool,
pub watch: bool,
#[clap(
long,
env = "STARKNET_POLL_INTERVAL",
default_value = "5000",
help = "Transaction result poll interval in milliseconds"
)]
poll_interval: u64,
pub poll_interval: u64,
#[clap(help = "Class hash")]
class_hash: String,
pub class_hash: String,
#[clap(help = "Raw constructor arguments")]
ctor_args: Vec<String>,
pub ctor_args: Vec<String>,
#[clap(flatten)]
verbosity: VerbosityArgs,
pub verbosity: VerbosityArgs,
}

impl Deploy {
Expand Down
18 changes: 9 additions & 9 deletions src/subcommands/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ use crate::{
#[derive(Debug, Parser)]
pub struct Invoke {
#[clap(flatten)]
provider: ProviderArgs,
pub provider: ProviderArgs,
#[clap(flatten)]
account: AccountArgs,
pub account: AccountArgs,
#[clap(flatten)]
fee: FeeArgs,
pub fee: FeeArgs,
#[clap(long, help = "Simulate the transaction only")]
simulate: bool,
pub simulate: bool,
#[clap(long, help = "Provide transaction nonce manually")]
nonce: Option<Felt>,
pub nonce: Option<Felt>,
#[clap(long, short, help = "Wait for the transaction to confirm")]
watch: bool,
pub watch: bool,
#[clap(
long,
env = "STARKNET_POLL_INTERVAL",
default_value = "5000",
help = "Transaction result poll interval in milliseconds"
)]
poll_interval: u64,
pub poll_interval: u64,
#[clap(help = "One or more contract calls. See documentation for more details")]
calls: Vec<String>,
pub calls: Vec<String>,
#[clap(flatten)]
verbosity: VerbosityArgs,
pub verbosity: VerbosityArgs,
}

impl Invoke {
Expand Down
3 changes: 3 additions & 0 deletions src/subcommands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ pub use transaction_status::TransactionStatus;

mod abi;
pub use abi::Abi;

mod upgrade;
pub use upgrade::Upgrade;
Loading