diff --git a/crates/pop-cli/src/commands/call/contract.rs b/crates/pop-cli/src/commands/call/contract.rs index 93a434ab..c8125089 100644 --- a/crates/pop-cli/src/commands/call/contract.rs +++ b/crates/pop-cli/src/commands/call/contract.rs @@ -386,9 +386,8 @@ impl CallContractCommand { // Perform signing steps with wallet integration, skipping secure signing for query-only // operations. if self.use_wallet && !self.dry_run && self.execute { - // TODO: Check how to do dry-run if flag - self.execute_call_secure_signing(call_exec, cli).await?; - self.finalize_execute_call(cli, prompt_to_repeat_call).await + self.execute_with_secure_signing(call_exec, cli).await?; + return self.finalize_execute_call(cli, prompt_to_repeat_call).await; } if self.dry_run { let spinner = spinner(); @@ -467,20 +466,15 @@ impl CallContractCommand { } } - async fn execute_call_secure_signing( + /// Execute the smart contract call using wallet integration. + async fn execute_with_secure_signing( &self, call_exec: CallExec, cli: &mut impl Cli, ) -> Result<()> { - let call_data = match self.get_contract_data(&call_exec).await { - Ok(data) => data, - Err(e) => { - return Err(anyhow!(format!( - "An error occurred getting the call data: {}", - e.to_string() - ))); - }, - }; + let call_data = self.get_contract_data(&call_exec).map_err(|err| { + anyhow!("An error occurred getting the call data: {}", err.to_string()) + })?; let maybe_payload = wait_for_signature(call_data, self.url.to_string()).await?; if let Some(payload) = maybe_payload { @@ -495,23 +489,23 @@ impl CallContractCommand { cli.info(call_result)?; } else { - display_message("Signed payload doesn't exist.", false, cli)?; + display_message("No signed payload received.", false, cli)?; } Ok(()) } - /// Get the call data and contract code hash - async fn get_contract_data( + // Get the call data. + fn get_contract_data( &self, call_exec: &CallExec, ) -> anyhow::Result> { let weight_limit = if self.gas_limit.is_some() && self.proof_size.is_some() { Weight::from_parts(self.gas_limit.unwrap(), self.proof_size.unwrap()) } else { - // Frontend will do dry run and update call data. + // TODO: Frontend will do dry run and update call data. Weight::from_parts(0, 0) }; - let call_data = get_call_payload(call_exec, weight_limit).await?; + let call_data = get_call_payload(call_exec, weight_limit)?; Ok(call_data) } diff --git a/crates/pop-cli/src/common/wallet.rs b/crates/pop-cli/src/common/wallet.rs index 2c521ce5..be8274b1 100644 --- a/crates/pop-cli/src/common/wallet.rs +++ b/crates/pop-cli/src/common/wallet.rs @@ -75,7 +75,6 @@ mod tests { subxt::OnlineClient::::from_rpc_client(rpc_client).await?; let signer = dev::alice(); - // let signer = dev::bob(); let payload = CallData(payload.call_data()); let ext_params = Params::new().build(); diff --git a/crates/pop-contracts/src/call.rs b/crates/pop-contracts/src/call.rs index 80ff8194..0e77b8b6 100644 --- a/crates/pop-contracts/src/call.rs +++ b/crates/pop-contracts/src/call.rs @@ -176,11 +176,19 @@ pub async fn call_smart_contract( Ok(output) } +/// Executes a smart contract call using a signed payload. +/// +/// # Arguments +/// +/// * `call_exec` - A struct containing the details of the contract call. +/// * `payload` - The signed payload string to be submitted for executing the call. +/// * `url` - The endpoint of the node where the call is executed. pub async fn call_smart_contract_from_signed_payload( call_exec: CallExec, payload: String, url: &Url, ) -> anyhow::Result { + println!("payload: {:?}", payload); let token_metadata = TokenMetadata::query::(url).await?; let metadata = call_exec.client().metadata(); let events = submit_signed_payload(url.as_str(), payload).await?; @@ -193,7 +201,12 @@ pub async fn call_smart_contract_from_signed_payload( Ok(output) } -pub async fn get_call_payload( +/// Generates the payload for executing a smart contract call. +/// +/// # Arguments +/// * `call_exec` - A struct containing the details of the contract call. +/// * `gas_limit` - The maximum amount of gas allocated for executing the contract call. +pub fn get_call_payload( call_exec: &CallExec, gas_limit: Weight, ) -> anyhow::Result> {