Skip to content

Commit

Permalink
docs: improve docs functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexD10S committed Dec 12, 2024
1 parent d1d18ef commit 8450d11
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
30 changes: 12 additions & 18 deletions crates/pop-cli/src/commands/call/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<DefaultConfig, DefaultEnvironment, Keypair>,
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 {
Expand All @@ -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<DefaultConfig, DefaultEnvironment, Keypair>,
) -> anyhow::Result<Vec<u8>> {
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)
}

Expand Down
1 change: 0 additions & 1 deletion crates/pop-cli/src/common/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ mod tests {
subxt::OnlineClient::<subxt::SubstrateConfig>::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();
Expand Down
15 changes: 14 additions & 1 deletion crates/pop-contracts/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DefaultConfig, DefaultEnvironment, Keypair>,
payload: String,
url: &Url,
) -> anyhow::Result<String, Error> {
println!("payload: {:?}", payload);
let token_metadata = TokenMetadata::query::<DefaultConfig>(url).await?;
let metadata = call_exec.client().metadata();
let events = submit_signed_payload(url.as_str(), payload).await?;
Expand All @@ -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<DefaultConfig, DefaultEnvironment, Keypair>,
gas_limit: Weight,
) -> anyhow::Result<Vec<u8>> {
Expand Down

0 comments on commit 8450d11

Please sign in to comment.