@@ -17,7 +17,7 @@ use sncast::helpers::rpc::RpcArgs;
17
17
use sncast:: response:: structs:: AccountCreateResponse ;
18
18
use sncast:: {
19
19
check_class_hash_exists, check_if_legacy_contract, extract_or_generate_salt, get_chain_id,
20
- get_keystore_password, handle_account_factory_error,
20
+ get_keystore_password, handle_account_factory_error, Network ,
21
21
} ;
22
22
use starknet:: accounts:: {
23
23
AccountDeploymentV1 , AccountFactory , ArgentAccountFactory , OpenZeppelinAccountFactory ,
@@ -44,7 +44,7 @@ pub struct Create {
44
44
pub salt : Option < Felt > ,
45
45
46
46
/// If passed, a profile with provided name and corresponding data will be created in snfoundry.toml
47
- #[ clap( long) ]
47
+ #[ clap( long, conflicts_with = "network" ) ]
48
48
pub add_profile : Option < String > ,
49
49
50
50
/// Custom contract class hash of declared contract
@@ -61,7 +61,6 @@ pub struct Create {
61
61
62
62
#[ allow( clippy:: too_many_arguments) ]
63
63
pub async fn create (
64
- rpc_url : String ,
65
64
account : & str ,
66
65
accounts_file : & Utf8PathBuf ,
67
66
keystore : Option < Utf8PathBuf > ,
@@ -112,24 +111,38 @@ pub async fn create(
112
111
legacy,
113
112
) ?;
114
113
115
- let deploy_command = generate_deploy_command_with_keystore ( account, & keystore, & rpc_url) ;
114
+ let deploy_command = generate_deploy_command_with_keystore (
115
+ account,
116
+ & keystore,
117
+ create. rpc . url . as_deref ( ) ,
118
+ create. rpc . network . as_ref ( ) ,
119
+ ) ;
116
120
message. push_str ( & deploy_command) ;
117
121
} else {
118
122
write_account_to_accounts_file ( account, accounts_file, chain_id, account_json. clone ( ) ) ?;
119
123
120
- let deploy_command = generate_deploy_command ( accounts_file, & rpc_url, account) ;
124
+ let deploy_command = generate_deploy_command (
125
+ accounts_file,
126
+ create. rpc . url . as_deref ( ) ,
127
+ create. rpc . network . as_ref ( ) ,
128
+ account,
129
+ ) ;
121
130
message. push_str ( & deploy_command) ;
122
131
}
123
132
124
133
if add_profile. is_some ( ) {
125
- let config = CastConfig {
126
- url : rpc_url,
127
- account : account. into ( ) ,
128
- accounts_file : accounts_file. into ( ) ,
129
- keystore,
130
- ..Default :: default ( )
131
- } ;
132
- add_created_profile_to_configuration ( create. add_profile . as_deref ( ) , & config, None ) ?;
134
+ if let Some ( url) = & create. rpc . url {
135
+ let config = CastConfig {
136
+ url : url. clone ( ) ,
137
+ account : account. into ( ) ,
138
+ accounts_file : accounts_file. into ( ) ,
139
+ keystore,
140
+ ..Default :: default ( )
141
+ } ;
142
+ add_created_profile_to_configuration ( create. add_profile . as_deref ( ) , & config, None ) ?;
143
+ } else {
144
+ unreachable ! ( "Conflicting arguments should be handled in clap" ) ;
145
+ }
133
146
}
134
147
135
148
Ok ( AccountCreateResponse {
@@ -328,7 +341,22 @@ fn write_account_to_file(
328
341
Ok ( ( ) )
329
342
}
330
343
331
- fn generate_deploy_command ( accounts_file : & Utf8PathBuf , rpc_url : & str , account : & str ) -> String {
344
+ fn generate_network_flag ( rpc_url : Option < & str > , network : Option < & Network > ) -> String {
345
+ if let Some ( rpc_url) = rpc_url {
346
+ format ! ( "--url {rpc_url}" )
347
+ } else if let Some ( network) = network {
348
+ format ! ( "--network {network}" )
349
+ } else {
350
+ unreachable ! ( "Either `--rpc_url` or `--network` must be provided." )
351
+ }
352
+ }
353
+
354
+ fn generate_deploy_command (
355
+ accounts_file : & Utf8PathBuf ,
356
+ rpc_url : Option < & str > ,
357
+ network : Option < & Network > ,
358
+ account : & str ,
359
+ ) -> String {
332
360
let accounts_flag = if accounts_file
333
361
. to_string ( )
334
362
. contains ( "starknet_accounts/starknet_open_zeppelin_accounts.json" )
@@ -338,19 +366,24 @@ fn generate_deploy_command(accounts_file: &Utf8PathBuf, rpc_url: &str, account:
338
366
format ! ( " --accounts-file {accounts_file}" )
339
367
} ;
340
368
369
+ let network_flag = generate_network_flag ( rpc_url, network) ;
370
+
341
371
format ! (
342
372
"\n \n After prefunding the address, run:\n \
343
- sncast{accounts_flag} account deploy --url {rpc_url } --name {account} --fee-token strk"
373
+ sncast{accounts_flag} account deploy {network_flag } --name {account} --fee-token strk"
344
374
)
345
375
}
346
376
347
377
fn generate_deploy_command_with_keystore (
348
378
account : & str ,
349
379
keystore : & Utf8PathBuf ,
350
- rpc_url : & str ,
380
+ rpc_url : Option < & str > ,
381
+ network : Option < & Network > ,
351
382
) -> String {
383
+ let network_flag = generate_network_flag ( rpc_url, network) ;
384
+
352
385
format ! (
353
386
"\n \n After prefunding the address, run:\n \
354
- sncast --account {account} --keystore {keystore} account deploy --url {rpc_url } --fee-token strk"
387
+ sncast --account {account} --keystore {keystore} account deploy {network_flag } --fee-token strk"
355
388
)
356
389
}
0 commit comments