Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copyable command for deployment #2727

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions crates/sncast/src/helpers/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ impl RpcArgs {

Ok(provider)
}

#[must_use]
pub fn get_url(&self, config: &CastConfig) -> String {
self.url.clone().unwrap_or_else(|| config.url.clone())
}
}
3 changes: 2 additions & 1 deletion crates/sncast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,10 @@ async fn run_async_command(
.clone()
.context("Required argument `--name` not provided")?
} else {
config.account
config.account.clone()
};
let result = starknet_commands::account::create::create(
create.rpc.get_url(&config),
&account,
&config.accounts_file,
config.keystore,
Expand Down
23 changes: 20 additions & 3 deletions crates/sncast/src/starknet_commands/account/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sncast::helpers::braavos::BraavosAccountFactory;
use sncast::helpers::configuration::CastConfig;
use sncast::helpers::constants::{
ARGENT_CLASS_HASH, BRAAVOS_BASE_ACCOUNT_CLASS_HASH, BRAAVOS_CLASS_HASH,
CREATE_KEYSTORE_PASSWORD_ENV_VAR, OZ_CLASS_HASH,
CREATE_KEYSTORE_PASSWORD_ENV_VAR, DEFAULT_ACCOUNTS_FILE, OZ_CLASS_HASH,
};
use sncast::helpers::rpc::RpcArgs;
use sncast::response::structs::AccountCreateResponse;
Expand Down Expand Up @@ -57,6 +57,7 @@ pub struct Create {

#[allow(clippy::too_many_arguments)]
pub async fn create(
rpc_url: String,
account: &str,
accounts_file: &Utf8PathBuf,
keystore: Option<Utf8PathBuf>,
Expand All @@ -81,6 +82,8 @@ pub async fn create(
.context("Invalid address")?
.parse()?;

let mut message = "Account successfully created. Prefund generated address with at least <max_fee> STRK tokens or an equivalent amount of ETH tokens. It is good to send more in the case of higher demand.".to_string();

if let Some(keystore) = keystore.clone() {
let account_path = Utf8PathBuf::from(&account);
if account_path == Utf8PathBuf::default() {
Expand All @@ -106,11 +109,25 @@ pub async fn create(
)?;
} else {
write_account_to_accounts_file(account, accounts_file, chain_id, account_json.clone())?;
message.push_str(
format!(
"\n\nAfter prefunding the address run:\n\
sncast{} account deploy --url {} --name {} --fee-token strk",
if accounts_file.to_string().contains(DEFAULT_ACCOUNTS_FILE) {
format!(" --accounts-file {accounts_file}")
} else {
String::new()
},
rpc_url,
account
)
.as_str(),
);
kkawula marked this conversation as resolved.
Show resolved Hide resolved
}

if add_profile.is_some() {
let config = CastConfig {
url: create.rpc.url.clone().unwrap_or_default(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't work in case where url is provided from profile

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rare but possible

url: rpc_url,
account: account.into(),
accounts_file: accounts_file.into(),
keystore,
Expand All @@ -131,7 +148,7 @@ pub async fn create(
"--add-profile flag was not set. No profile added to snfoundry.toml".to_string()
},
message: if account_json["deployed"] == json!(false) {
"Account successfully created. Prefund generated address with at least <max_fee> STRK tokens or an equivalent amount of ETH tokens. It is good to send more in the case of higher demand.".to_string()
message
} else {
"Account already deployed".to_string()
},
Expand Down
3 changes: 3 additions & 0 deletions crates/sncast/tests/e2e/account/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub async fn test_happy_case(account_type: &str) {
max_fee: [..]
message: Account successfully created. Prefund generated address with at least <max_fee> STRK tokens or an equivalent amount of ETH tokens. It is good to send more in the case of higher demand.

After prefunding the address run:
sncast account deploy --url http://127.0.0.1:5055/rpc --name my_account --fee-token strk

To see account creation details, visit:
account: [..]
"},
Expand Down
Loading