Skip to content

Commit

Permalink
feat: add build_tx to ScriptCallHandler (#1076)
Browse files Browse the repository at this point in the history
  • Loading branch information
hal3e authored Aug 14, 2023
1 parent 324d85f commit aa1fab8
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/fuels-programs/src/script_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use fuels_core::{
bech32::Bech32ContractId,
errors::Result,
input::Input,
transaction::{Transaction, TxParameters},
transaction::{ScriptTransaction, Transaction, TxParameters},
transaction_builders::ScriptTransactionBuilder,
unresolved_bytes::UnresolvedBytes,
},
Expand Down Expand Up @@ -208,18 +208,25 @@ where
.sum()
}

/// Call a script on the node. If `simulate == true`, then the call is done in a
/// read-only manner, using a `dry-run`. The [`FuelCallResponse`] struct contains the `main`'s value
/// in its `value` field as an actual typed value `D` (if your method returns `bool`,
/// it will be a bool, works also for structs thanks to the `abigen!()`).
/// The other field of [`FuelCallResponse`], `receipts`, contains the receipts of the transaction.
async fn call_or_simulate(&mut self, simulate: bool) -> Result<FuelCallResponse<D>> {
/// Returns the transaction that executes the script call
pub async fn build_tx(&self) -> Result<ScriptTransaction> {
let tb = self.prepare_builder().await?;
let base_amount = self.calculate_base_asset_sum();
let tx = self
.account
.add_fee_resources(tb, base_amount, None)
.await?;

Ok(tx)
}

/// Call a script on the node. If `simulate == true`, then the call is done in a
/// read-only manner, using a `dry-run`. The [`FuelCallResponse`] struct contains the `main`'s value
/// in its `value` field as an actual typed value `D` (if your method returns `bool`,
/// it will be a bool, works also for structs thanks to the `abigen!()`).
/// The other field of [`FuelCallResponse`], `receipts`, contains the receipts of the transaction.
async fn call_or_simulate(&mut self, simulate: bool) -> Result<FuelCallResponse<D>> {
let tx = self.build_tx().await?;
let consensus_parameters = self.provider.consensus_parameters();
self.cached_tx_id = Some(tx.id(consensus_parameters.chain_id.into()));

Expand Down

0 comments on commit aa1fab8

Please sign in to comment.