11use crate :: starknet_commands:: account:: {
2- AccountType , add_created_profile_to_configuration, prepare_account_json,
3- write_account_to_accounts_file,
2+ add_created_profile_to_configuration, prepare_account_json, write_account_to_accounts_file,
43} ;
54use anyhow:: { Context , Result , anyhow, bail} ;
65use camino:: Utf8PathBuf ;
@@ -16,8 +15,8 @@ use sncast::helpers::constants::{
1615use sncast:: helpers:: rpc:: RpcArgs ;
1716use sncast:: response:: structs:: AccountCreateResponse ;
1817use sncast:: {
19- Network , check_class_hash_exists, check_if_legacy_contract, extract_or_generate_salt ,
20- get_chain_id, get_keystore_password, handle_account_factory_error,
18+ AccountType , Network , check_class_hash_exists, check_if_legacy_contract,
19+ extract_or_generate_salt , get_chain_id, get_keystore_password, handle_account_factory_error,
2120} ;
2221use starknet:: accounts:: {
2322 AccountDeploymentV1 , AccountFactory , ArgentAccountFactory , OpenZeppelinAccountFactory ,
@@ -27,12 +26,13 @@ use starknet::providers::JsonRpcClient;
2726use starknet:: providers:: jsonrpc:: HttpTransport ;
2827use starknet:: signers:: { LocalWallet , SigningKey } ;
2928use starknet_types_core:: felt:: Felt ;
29+ use std:: str:: FromStr ;
3030
3131#[ derive( Args , Debug ) ]
3232#[ command( about = "Create an account with all important secrets" ) ]
3333pub struct Create {
3434 /// Type of the account
35- #[ clap( value_enum, short = 't' , long = "type" , default_value_t = AccountType :: Oz ) ]
35+ #[ clap( value_enum, short = 't' , long = "type" , value_parser = AccountType :: from_str , default_value_t = AccountType :: OpenZeppelin ) ]
3636 pub account_type : AccountType ,
3737
3838 /// Account name under which account information is going to be saved
@@ -70,14 +70,14 @@ pub async fn create(
7070 let add_profile = create. add_profile . clone ( ) ;
7171 let salt = extract_or_generate_salt ( create. salt ) ;
7272 let class_hash = create. class_hash . unwrap_or ( match create. account_type {
73- AccountType :: Oz => OZ_CLASS_HASH ,
73+ AccountType :: OpenZeppelin => OZ_CLASS_HASH ,
7474 AccountType :: Argent => ARGENT_CLASS_HASH ,
7575 AccountType :: Braavos => BRAAVOS_CLASS_HASH ,
7676 } ) ;
7777 check_class_hash_exists ( provider, class_hash) . await ?;
7878
7979 let ( account_json, max_fee) =
80- generate_account ( provider, salt, class_hash, & create. account_type ) . await ?;
80+ generate_account ( provider, salt, class_hash, create. account_type ) . await ?;
8181
8282 let address: Felt = account_json[ "address" ]
8383 . as_str ( )
@@ -104,7 +104,7 @@ pub async fn create(
104104 private_key,
105105 salt,
106106 class_hash,
107- & create. account_type ,
107+ create. account_type ,
108108 & keystore,
109109 & account_path,
110110 legacy,
@@ -167,14 +167,14 @@ async fn generate_account(
167167 provider : & JsonRpcClient < HttpTransport > ,
168168 salt : Felt ,
169169 class_hash : Felt ,
170- account_type : & AccountType ,
170+ account_type : AccountType ,
171171) -> Result < ( serde_json:: Value , Felt ) > {
172172 let chain_id = get_chain_id ( provider) . await ?;
173173 let private_key = SigningKey :: from_random ( ) ;
174174 let signer = LocalWallet :: from_signing_key ( private_key. clone ( ) ) ;
175175
176176 let ( address, fee_estimate) = match account_type {
177- AccountType :: Oz => {
177+ AccountType :: OpenZeppelin => {
178178 let factory =
179179 OpenZeppelinAccountFactory :: new ( class_hash, chain_id, signer, provider) . await ?;
180180 get_address_and_deployment_fee ( factory, salt) . await ?
@@ -245,7 +245,7 @@ fn create_to_keystore(
245245 private_key : Felt ,
246246 salt : Felt ,
247247 class_hash : Felt ,
248- account_type : & AccountType ,
248+ account_type : AccountType ,
249249 keystore_path : & Utf8PathBuf ,
250250 account_path : & Utf8PathBuf ,
251251 legacy : bool ,
@@ -259,13 +259,12 @@ fn create_to_keystore(
259259 let password = get_keystore_password ( CREATE_KEYSTORE_PASSWORD_ENV_VAR ) ?;
260260 let private_key = SigningKey :: from_secret_scalar ( private_key) ;
261261 private_key. save_as_keystore ( keystore_path, & password) ?;
262-
263262 let account_json = match account_type {
264- AccountType :: Oz => {
263+ AccountType :: OpenZeppelin => {
265264 json ! ( {
266265 "version" : 1 ,
267266 "variant" : {
268- "type" : format! ( "{account_type}" ) ,
267+ "type" : AccountType :: OpenZeppelin ,
269268 "version" : 1 ,
270269 "public_key" : format!( "{:#x}" , private_key. verifying_key( ) . scalar( ) ) ,
271270 "legacy" : legacy,
@@ -281,7 +280,7 @@ fn create_to_keystore(
281280 json ! ( {
282281 "version" : 1 ,
283282 "variant" : {
284- "type" : format! ( "{account_type}" ) ,
283+ "type" : AccountType :: Argent ,
285284 "version" : 1 ,
286285 "owner" : format!( "{:#x}" , private_key. verifying_key( ) . scalar( ) ) ,
287286 "guardian" : "0x0" ,
@@ -298,7 +297,7 @@ fn create_to_keystore(
298297 {
299298 "version" : 1 ,
300299 "variant" : {
301- "type" : format! ( "{account_type}" ) ,
300+ "type" : AccountType :: Braavos ,
302301 "version" : 1 ,
303302 "multisig" : {
304303 "status" : "off"
0 commit comments