Skip to content

Commit 53a59b9

Browse files
Move get commands under sncast get (#4215)
<!-- Reference any GitHub issues resolved by this PR --> Towards #4144 ## Stack - #4215 - #4210 ## Introduced changes <!-- A brief description of the changes --> - moved `sncast balance`->`sncast get balance` - moved `sncast tx-status`->`sncast get tx-status` - add warnings to old commands ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md` --------- Co-authored-by: ddoktorski <45050160+ddoktorski@users.noreply.github.com>
1 parent 14fab92 commit 53a59b9

15 files changed

Lines changed: 184 additions & 117 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Bug with invalid function name mappings for functions with `#[test]` attribute
1818
- `--exit-first` flag now correctly stops execution for all packages when tests are run in a workspace
1919

20+
### Cast
21+
22+
#### Changed
23+
24+
- `sncast balance` and `sncast tx-status` commands have been moved under `sncast get` subcommand (`sncast get balance`, `sncast get tx-status`). The old commands still work, but will be removed in the future.
25+
2026
## [0.57.0] - 2026-02-24
2127

2228
### Forge

crates/sncast/src/main.rs

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
use std::str::FromStr;
22

3-
use crate::starknet_commands::balance::Balance;
43
use crate::starknet_commands::declare::declare;
54
use crate::starknet_commands::declare_from::{ContractSource, DeclareFrom};
65
use crate::starknet_commands::deploy::{DeployArguments, DeployCommonArgs};
6+
use crate::starknet_commands::get::Get;
7+
use crate::starknet_commands::get::balance::Balance;
78
use crate::starknet_commands::invoke::InvokeCommonArgs;
8-
use crate::starknet_commands::multicall;
99
use crate::starknet_commands::script::run_script_command;
1010
use crate::starknet_commands::utils::{self, Utils};
1111
use crate::starknet_commands::{
1212
account, account::Account as AccountCommand, call::Call, declare::Declare, deploy::Deploy,
13-
invoke::Invoke, multicall::Multicall, script::Script, show_config::ShowConfig,
14-
tx_status::TxStatus,
13+
get::tx_status::TxStatus, invoke::Invoke, multicall::Multicall, script::Script,
14+
show_config::ShowConfig,
1515
};
16+
use crate::starknet_commands::{get, multicall};
1617
use anyhow::{Context, Result, bail};
1718
use camino::Utf8PathBuf;
1819
use clap::{CommandFactory, Parser, Subcommand};
1920
use configuration::load_config;
2021
use conversions::IntoConv;
2122
use data_transformer::transform;
23+
use foundry_ui::components::warning::WarningMessage;
2224
use shared::auto_completions::{Completions, generate_completions};
2325
use sncast::helpers::command::process_command_result;
2426
use sncast::helpers::config::{combine_cast_configs, get_global_config_path};
@@ -42,7 +44,6 @@ use sncast::{
4244
get_contract_class,
4345
};
4446
use starknet_commands::verify::Verify;
45-
use starknet_rust::accounts::Account;
4647
use starknet_rust::core::types::ContractClass;
4748
use starknet_rust::core::types::contract::{AbiEntry, SierraClass};
4849
use starknet_rust::core::utils::get_selector_from_name;
@@ -126,6 +127,7 @@ struct Cli {
126127
impl Cli {
127128
fn command_name(&self) -> String {
128129
match self.command {
130+
Commands::Get(_) => "get",
129131
Commands::Declare(_) => "declare",
130132
Commands::DeclareFrom(_) => "declare-from",
131133
Commands::Deploy(_) => "deploy",
@@ -147,6 +149,9 @@ impl Cli {
147149

148150
#[derive(Subcommand)]
149151
enum Commands {
152+
/// Get various data from the network
153+
Get(Get),
154+
150155
/// Declare a contract
151156
Declare(Declare),
152157

@@ -643,6 +648,8 @@ async fn run_async_command(cli: Cli, config: CastConfig, ui: &UI) -> Result<()>
643648
Ok(())
644649
}
645650

651+
Commands::Get(get) => get::get(get, config, ui).await,
652+
646653
Commands::Utils(utils) => {
647654
utils::utils(
648655
utils,
@@ -676,16 +683,10 @@ async fn run_async_command(cli: Cli, config: CastConfig, ui: &UI) -> Result<()>
676683
Ok(())
677684
}
678685

686+
// TODO(#4214): Remove moved sncast commands
679687
Commands::TxStatus(tx_status) => {
680-
let provider = tx_status.rpc.get_provider(&config, ui).await?;
681-
682-
let result =
683-
starknet_commands::tx_status::tx_status(&provider, tx_status.transaction_hash)
684-
.await
685-
.context("Failed to get transaction status");
686-
687-
process_command_result("tx-status", result, ui, None);
688-
Ok(())
688+
print_cmd_move_warning("tx-status", "get tx-status", ui);
689+
get::tx_status::tx_status(tx_status, config, ui).await
689690
}
690691

691692
Commands::Verify(verify) => {
@@ -721,23 +722,10 @@ async fn run_async_command(cli: Cli, config: CastConfig, ui: &UI) -> Result<()>
721722
Ok(())
722723
}
723724

725+
// TODO(#4214): Remove moved sncast commands
724726
Commands::Balance(balance) => {
725-
let provider = balance.rpc.get_provider(&config, ui).await?;
726-
let account = get_account(
727-
&config,
728-
&provider,
729-
&balance.rpc,
730-
config.keystore.as_ref(),
731-
ui,
732-
)
733-
.await?;
734-
735-
let result =
736-
starknet_commands::balance::balance(account.address(), &provider, &balance).await?;
737-
738-
process_command_result("balance", Ok(result), ui, None);
739-
740-
Ok(())
727+
print_cmd_move_warning("balance", "get balance", ui);
728+
get::balance::balance(balance, config, ui).await
741729
}
742730

743731
Commands::Script(_) => unreachable!(),
@@ -790,3 +778,10 @@ fn get_cast_config(cli: &Cli, ui: &UI) -> Result<CastConfig> {
790778
config_with_cli(&mut combined_config, cli);
791779
Ok(combined_config)
792780
}
781+
782+
fn print_cmd_move_warning(command_name: &str, new_command_name: &str, ui: &UI) {
783+
ui.print_warning(WarningMessage::new(format!(
784+
"`sncast {command_name}` has moved to `sncast {new_command_name}`. `sncast {command_name}` will be removed in the next version."
785+
)));
786+
ui.print_blank_line();
787+
}

crates/sncast/src/starknet_commands/balance.rs renamed to crates/sncast/src/starknet_commands/get/balance.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
use anyhow::{Error, Result};
22
use clap::Args;
33
use primitive_types::U256;
4-
use sncast::get_block_id;
4+
use sncast::helpers::command::process_command_result;
5+
use sncast::helpers::configuration::CastConfig;
56
use sncast::helpers::rpc::RpcArgs;
67
use sncast::helpers::token::Token;
78
use sncast::response::balance::BalanceResponse;
89
use sncast::response::errors::SNCastProviderError;
910
use sncast::response::errors::StarknetCommandError;
11+
use sncast::response::ui::UI;
12+
use sncast::{get_account, get_block_id};
13+
use starknet_rust::accounts::Account;
1014
use starknet_rust::{
1115
core::{types::FunctionCall, utils::get_selector_from_name},
1216
providers::{JsonRpcClient, Provider, jsonrpc::HttpTransport},
1317
};
1418
use starknet_types_core::felt::Felt;
19+
1520
#[derive(Args, Debug, Clone)]
1621
#[group(multiple = false)]
1722
pub struct TokenIdentifier {
@@ -67,7 +72,25 @@ pub struct Balance {
6772
pub rpc: RpcArgs,
6873
}
6974

70-
pub async fn balance(
75+
pub async fn balance(balance: Balance, config: CastConfig, ui: &UI) -> anyhow::Result<()> {
76+
let provider = balance.rpc.get_provider(&config, ui).await?;
77+
let account = get_account(
78+
&config,
79+
&provider,
80+
&balance.rpc,
81+
config.keystore.as_ref(),
82+
ui,
83+
)
84+
.await?;
85+
86+
let result = get_balance(account.address(), &provider, &balance).await?;
87+
88+
process_command_result("get balance", Ok(result), ui, None);
89+
90+
Ok(())
91+
}
92+
93+
pub async fn get_balance(
7194
account_address: Felt,
7295
provider: &JsonRpcClient<HttpTransport>,
7396
balance: &Balance,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use clap::{Args, Subcommand};
2+
use sncast::helpers::configuration::CastConfig;
3+
use sncast::response::ui::UI;
4+
5+
pub mod balance;
6+
pub mod tx_status;
7+
8+
#[derive(Args)]
9+
#[command(about = "Commands for querying Starknet state")]
10+
pub struct Get {
11+
#[command(subcommand)]
12+
pub command: GetCommands,
13+
}
14+
15+
#[derive(Debug, Subcommand)]
16+
pub enum GetCommands {
17+
/// Get the status of a transaction
18+
TxStatus(tx_status::TxStatus),
19+
20+
/// Fetch balance of the account for specified token
21+
Balance(balance::Balance),
22+
}
23+
24+
pub async fn get(get: Get, config: CastConfig, ui: &UI) -> anyhow::Result<()> {
25+
match get.command {
26+
GetCommands::TxStatus(status) => tx_status::tx_status(status, config, ui).await?,
27+
28+
GetCommands::Balance(balance) => balance::balance(balance, config, ui).await?,
29+
}
30+
31+
Ok(())
32+
}

crates/sncast/src/starknet_commands/tx_status.rs renamed to crates/sncast/src/starknet_commands/get/tx_status.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
use anyhow::Context;
12
use clap::Args;
3+
use sncast::helpers::command::process_command_result;
4+
use sncast::helpers::configuration::CastConfig;
25
use sncast::helpers::rpc::RpcArgs;
36
use sncast::response::errors::StarknetCommandError;
47
use sncast::response::tx_status::{ExecutionStatus, FinalityStatus, TransactionStatusResponse};
8+
use sncast::response::ui::UI;
59
use starknet_rust::core::types::{TransactionExecutionStatus, TransactionStatus};
610
use starknet_rust::providers::jsonrpc::HttpTransport;
711
use starknet_rust::providers::{JsonRpcClient, Provider};
812
use starknet_types_core::felt::Felt;
913

10-
#[derive(Args)]
14+
#[derive(Debug, Args)]
1115
#[command(about = "Get the status of a transaction")]
1216
pub struct TxStatus {
1317
/// Hash of the transaction
@@ -17,7 +21,18 @@ pub struct TxStatus {
1721
pub rpc: RpcArgs,
1822
}
1923

20-
pub async fn tx_status(
24+
pub async fn tx_status(tx_status: TxStatus, config: CastConfig, ui: &UI) -> anyhow::Result<()> {
25+
let provider = tx_status.rpc.get_provider(&config, ui).await?;
26+
27+
let result = get_tx_status(&provider, tx_status.transaction_hash)
28+
.await
29+
.context("Failed to get transaction status");
30+
31+
process_command_result("get tx-status", result, ui, None);
32+
Ok(())
33+
}
34+
35+
pub async fn get_tx_status(
2136
provider: &JsonRpcClient<HttpTransport>,
2237
transaction_hash: Felt,
2338
) -> Result<TransactionStatusResponse, StarknetCommandError> {
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
pub mod account;
2-
pub mod balance;
32
pub mod call;
43
pub mod declare;
54
pub mod declare_from;
65
pub mod deploy;
6+
pub mod get;
77
pub mod invoke;
88
pub mod multicall;
99
pub mod script;
1010
pub mod show_config;
11-
pub mod tx_status;
1211
pub mod utils;
1312
pub mod verify;

crates/sncast/src/starknet_commands/script/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::starknet_commands::{call, declare, deploy, invoke, tx_status};
1+
use crate::starknet_commands::{call, declare, deploy, get::tx_status, invoke};
22
use crate::{WaitForTx, get_account};
33
use anyhow::{Context, Result, anyhow};
44
use blockifier::execution::contract_class::TrackedResource;
@@ -254,7 +254,7 @@ impl<'a> ExtensionLogic for CastScriptExtension<'a> {
254254

255255
let tx_status_result = self
256256
.tokio_runtime
257-
.block_on(tx_status::tx_status(self.provider, transaction_hash));
257+
.block_on(tx_status::get_tx_status(self.provider, transaction_hash));
258258

259259
Ok(CheatcodeHandlingResult::from_serializable(tx_status_result))
260260
}

crates/sncast/tests/e2e/balance.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub async fn happy_case() {
1717
accounts_json_path.as_str(),
1818
"--account",
1919
"balance-test",
20+
"get",
2021
"balance",
2122
"--url",
2223
URL,
@@ -29,6 +30,30 @@ pub async fn happy_case() {
2930
"});
3031
}
3132

33+
#[tokio::test]
34+
pub async fn happy_case_old_command() {
35+
let tempdir = tempdir().unwrap();
36+
let accounts_json_path = get_accounts_path("tests/data/accounts/accounts.json");
37+
38+
let args = vec![
39+
"--accounts-file",
40+
accounts_json_path.as_str(),
41+
"--account",
42+
"balance-test",
43+
"balance",
44+
"--url",
45+
URL,
46+
];
47+
48+
let snapbox = runner(&args).current_dir(tempdir.path());
49+
50+
snapbox.assert().stdout_eq(indoc! {r"
51+
[WARNING] `sncast balance` has moved to `sncast get balance`. `sncast balance` will be removed in the next version.
52+
53+
Balance: 109394843313476728397 fri
54+
"});
55+
}
56+
3257
#[tokio::test]
3358
pub async fn happy_case_json() {
3459
let tempdir = tempdir().unwrap();
@@ -40,6 +65,7 @@ pub async fn happy_case_json() {
4065
accounts_json_path.as_str(),
4166
"--account",
4267
"user1",
68+
"get",
4369
"balance",
4470
"--url",
4571
URL,
@@ -48,7 +74,7 @@ pub async fn happy_case_json() {
4874
let snapbox = runner(&args).current_dir(tempdir.path());
4975

5076
snapbox.assert().stdout_eq(indoc! {r#"
51-
{"balance":"[..]","command":"balance","token_unit":"fri","type":"response"}
77+
{"balance":"[..]","command":"get balance","token_unit":"fri","type":"response"}
5278
"#});
5379
}
5480

@@ -66,6 +92,7 @@ pub async fn happy_case_with_token(token: &Token) {
6692
accounts_json_path.as_str(),
6793
"--account",
6894
"user1",
95+
"get",
6996
"balance",
7097
"--token",
7198
&token,
@@ -90,6 +117,7 @@ pub async fn happy_case_with_block_id() {
90117
accounts_json_path.as_str(),
91118
"--account",
92119
"user1",
120+
"get",
93121
"balance",
94122
"--block-id",
95123
"latest",
@@ -114,6 +142,7 @@ pub async fn invalid_token() {
114142
accounts_json_path.as_str(),
115143
"--account",
116144
"user1",
145+
"get",
117146
"balance",
118147
"--token",
119148
"xyz",
@@ -142,6 +171,7 @@ pub async fn happy_case_with_token_address() {
142171
accounts_json_path.as_str(),
143172
"--account",
144173
"user1",
174+
"get",
145175
"balance",
146176
"--token-address",
147177
strk_address,
@@ -167,6 +197,7 @@ pub async fn happy_case_json_with_token_address() {
167197
accounts_json_path.as_str(),
168198
"--account",
169199
"user1",
200+
"get",
170201
"balance",
171202
"--url",
172203
URL,
@@ -193,6 +224,7 @@ pub async fn nonexistent_token_address() {
193224
accounts_json_path.as_str(),
194225
"--account",
195226
"user1",
227+
"get",
196228
"balance",
197229
"--token-address",
198230
"0x123",

0 commit comments

Comments
 (0)