Skip to content

Commit 1fe6776

Browse files
Refactor declare (#3726)
<!-- Reference any GitHub issues resolved by this PR --> Towards #3587 **Stack**: - #3729 - #3727 - #3726 ⬅ ## Introduced changes Move common logic of declaration to separate function. ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [ ] Updated relevant documentation - [ ] Added relevant tests - [x] Performed self-review of the code - [ ] Added changes to `CHANGELOG.md`
1 parent 6730722 commit 1fe6776

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

crates/sncast/src/starknet_commands/declare.rs

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,46 @@ pub async fn declare(
6767
let casm_contract_definition: CompiledClass =
6868
serde_json::from_str(&contract_artifacts.casm).context("Failed to parse casm artifact")?;
6969

70-
let casm_class_hash = casm_contract_definition
71-
.class_hash()
72-
.map_err(anyhow::Error::from)?;
70+
declare_with_artifacts(
71+
contract_definition,
72+
casm_contract_definition,
73+
declare.fee_args,
74+
declare.nonce,
75+
account,
76+
wait_config,
77+
skip_on_already_declared,
78+
ui,
79+
)
80+
.await
81+
}
7382

74-
let class_hash = contract_definition
75-
.class_hash()
76-
.map_err(anyhow::Error::from)?;
83+
#[allow(clippy::too_many_arguments)]
84+
pub(crate) async fn declare_with_artifacts(
85+
sierra_class: SierraClass,
86+
compiled_casm: CompiledClass,
87+
fee_args: FeeArgs,
88+
nonce: Option<Felt>,
89+
account: &SingleOwnerAccount<&JsonRpcClient<HttpTransport>, LocalWallet>,
90+
wait_config: WaitForTx,
91+
skip_on_already_declared: bool,
92+
ui: &UI,
93+
) -> Result<DeclareResponse, StarknetCommandError> {
94+
let casm_class_hash = compiled_casm.class_hash().map_err(anyhow::Error::from)?;
95+
let class_hash = sierra_class.class_hash().map_err(anyhow::Error::from)?;
7796

7897
let declaration = account.declare_v3(
79-
Arc::new(contract_definition.flatten().map_err(anyhow::Error::from)?),
98+
Arc::new(sierra_class.flatten().map_err(anyhow::Error::from)?),
8099
casm_class_hash,
81100
);
82101

83-
let fee_settings = if declare.fee_args.max_fee.is_some() {
102+
let fee_settings = if fee_args.max_fee.is_some() {
84103
let fee_estimate = declaration
85104
.estimate_fee()
86105
.await
87106
.expect("Failed to estimate fee");
88-
declare.fee_args.try_into_fee_settings(Some(&fee_estimate))
107+
fee_args.try_into_fee_settings(Some(&fee_estimate))
89108
} else {
90-
declare.fee_args.try_into_fee_settings(None)
109+
fee_args.try_into_fee_settings(None)
91110
};
92111

93112
let FeeSettings {
@@ -109,7 +128,7 @@ pub async fn declare(
109128
l1_data_gas => DeclarationV3::l1_data_gas,
110129
l1_data_gas_price => DeclarationV3::l1_data_gas_price,
111130
tip => DeclarationV3::tip,
112-
declare.nonce => DeclarationV3::nonce
131+
nonce => DeclarationV3::nonce
113132
);
114133

115134
let declared = declaration.send().await;

0 commit comments

Comments
 (0)