Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions forc-plugins/forc-client/src/cmd/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ pub struct Command {
#[clap(long, short = 'o', default_value = "default", help_heading = "OUTPUT")]
pub output: OutputFormat,

/// Contract call variable output count
#[clap(long, alias = "variable-output", help_heading = "VARIABLE OUTPUT")]
pub variable_output: Option<usize>,

/// Set verbosity levels; currently only supports max 2 levels
/// - `-v=1`: Print decoded logs
/// - `-v=2`: Additionally print receipts and script json
Expand Down
33 changes: 17 additions & 16 deletions forc-plugins/forc-client/src/op/call/call_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub async fn call_function(
mut output,
external_contracts,
contract_abis,
variable_output,
..
} = cmd;

Expand Down Expand Up @@ -88,7 +89,9 @@ pub async fn call_function(
};

// Setup variable output policy and log decoder
let variable_output_policy = VariableOutputPolicy::Exactly(call_parameters.amount as usize);
let variable_output_policy = variable_output
.map(VariableOutputPolicy::Exactly)
.unwrap_or(VariableOutputPolicy::EstimateMinimum);
let error_codes = abi
.unified
.error_codes
Expand Down Expand Up @@ -275,8 +278,6 @@ pub async fn call_function(
let fuel_tx::Transaction::Script(script) = &tx else {
bail!("Transaction is not a script");
};
let script_json = serde_json::to_value(script)
.map_err(|e| anyhow!("Failed to convert script to JSON: {e}"))?;

// Parse the result based on output format
let mut receipt_parser =
Expand Down Expand Up @@ -330,7 +331,7 @@ pub async fn call_function(

super::display_detailed_call_info(
&tx_execution,
&script_json,
script,
&abi_map,
cmd.verbosity,
&mut output,
Expand All @@ -357,7 +358,7 @@ pub async fn call_function(
result: Some(result),
total_gas: *tx_execution.result.total_gas(),
receipts: tx_execution.result.receipts().to_vec(),
script_json: Some(script_json),
script: Some(script.to_owned()),
trace_events,
})
}
Expand Down Expand Up @@ -466,6 +467,7 @@ pub mod tests {
cmd,
op::call::{call, get_wallet, PrivateKeySigner},
};
use fuel_tx::field::Outputs;
use fuels::{crypto::SecretKey, prelude::*};
use std::path::PathBuf;

Expand Down Expand Up @@ -493,6 +495,7 @@ pub mod tests {
label: None,
output: cmd::call::OutputFormat::Raw,
list_functions: false,
variable_output: None,
verbosity: 0,
debug: false,
}
Expand Down Expand Up @@ -948,15 +951,9 @@ pub mod tests {
gas_forwarded: None,
};
// validate balance is unchanged (dry-run)
assert_eq!(
call(operation.clone(), cmd.clone())
.await
.unwrap()
.result
.unwrap(),
"()"
);
assert_eq!(get_contract_balance(id_2, provider.clone()).await, 0);
let call_response = call(operation.clone(), cmd.clone()).await.unwrap();
assert_eq!(call_response.result.unwrap(), "()");
assert_eq!(call_response.script.unwrap().outputs().len(), 2);
cmd.mode = cmd::call::ExecutionMode::Live;
assert_eq!(call(operation, cmd).await.unwrap().result.unwrap(), "()");
assert_eq!(get_contract_balance(id_2, provider.clone()).await, 1);
Expand All @@ -983,7 +980,9 @@ pub mod tests {
};
cmd.mode = cmd::call::ExecutionMode::Live;
let operation = cmd.validate_and_get_operation().unwrap();
assert_eq!(call(operation, cmd).await.unwrap().result.unwrap(), "()");
let call_response = call(operation, cmd).await.unwrap();
assert_eq!(call_response.result.unwrap(), "()");
assert_eq!(call_response.script.unwrap().outputs().len(), 3);
assert_eq!(
get_recipient_balance(random_wallet.address(), provider.clone()).await,
2
Expand Down Expand Up @@ -1041,7 +1040,9 @@ pub mod tests {
};
cmd.mode = cmd::call::ExecutionMode::Live;
let operation = cmd.validate_and_get_operation().unwrap();
assert_eq!(call(operation, cmd).await.unwrap().result.unwrap(), "()");
let call_response = call(operation, cmd).await.unwrap();
assert_eq!(call_response.result.unwrap(), "()");
assert_eq!(call_response.script.unwrap().outputs().len(), 3);
assert_eq!(
get_recipient_balance(random_wallet.address(), provider.clone()).await,
3
Expand Down
6 changes: 3 additions & 3 deletions forc-plugins/forc-client/src/op/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct CallResponse {
#[serde(skip_serializing_if = "Vec::is_empty")]
pub trace_events: Vec<trace::TraceEvent>,
#[serde(rename = "Script", skip_serializing_if = "Option::is_none")]
pub script_json: Option<serde_json::Value>,
pub script: Option<fuel_tx::Script>,
}

/// A command for calling a contract function.
Expand Down Expand Up @@ -266,7 +266,7 @@ pub(crate) fn display_tx_info(
/// Prints receipts and trace to the writer based on verbosity level
pub(crate) fn display_detailed_call_info(
tx: &TransactionExecutionStatus,
script_json: &serde_json::Value,
script: &fuel_tx::Script,
abis: &HashMap<ContractId, Abi>,
verbosity: u8,
writer: &mut impl std::io::Write,
Expand All @@ -276,7 +276,7 @@ pub(crate) fn display_detailed_call_info(
if verbosity >= 4 {
forc_tracing::println_label_green(
"transaction script:\n",
&serde_json::to_string_pretty(script_json).unwrap(),
&serde_json::to_string_pretty(script).unwrap(),
);
}
if verbosity >= 3 {
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-client/src/op/call/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub async fn transfer(
total_gas: tx_response.tx_status.total_gas,
result: None,
receipts: tx_response.tx_status.receipts,
script_json: None,
script: None,
trace_events: vec![],
})
}
Expand Down
3 changes: 3 additions & 0 deletions forc-plugins/forc-mcp/src/forc_call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ fn build_call_command(
gas,
external_contracts: None,
output: OutputFormat::Json,
variable_output: None,
verbosity,
debug: false,
})
Expand Down Expand Up @@ -582,6 +583,7 @@ fn build_list_command(contract_id: &str, abi: &str) -> anyhow::Result<forc_clien
gas: None,
external_contracts: None,
output: OutputFormat::Default,
variable_output: None,
verbosity: 0,
debug: false,
})
Expand Down Expand Up @@ -641,6 +643,7 @@ fn build_transfer_command(
gas: None,
external_contracts: None,
output: OutputFormat::Json,
variable_output: None,
verbosity,
debug: false,
})
Expand Down
Loading