Skip to content

Commit

Permalink
chore!: remove unused response method (#1263)
Browse files Browse the repository at this point in the history
The `response` method from `ScriptCallHandler`, `ContractCallHandler`
and `MultiContractCallHandler` was unreachable because of:
```rust
let tx_id = self.cached_tx_id.expect("Cached tx_id is missing");
```
Which means that if there is no cached `tx_id` this method will panic.
The only way to get a `tx_id` is by calling `call`, `simulate` or
`submit` and these methods return other types that handle the response.

Even though this method was never used, I will mark the PR as breaking
as the method was `pub`.

BREAKING CHANGE: remove `response` method from `ScriptCallHandler`,
`ContractCallHandler` and `MultiContractCallHandler`.
  • Loading branch information
hal3e authored Feb 5, 2024
1 parent 1221632 commit fcc6f8c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 41 deletions.
31 changes: 2 additions & 29 deletions packages/fuels-programs/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,21 +603,8 @@ where
Ok(SubmitResponse::new(tx_id, self))
}

pub async fn response(self) -> Result<FuelCallResponse<D>> {
let provider = self.account.try_provider()?;
let tx_id = self.cached_tx_id.expect("Cached tx_id is missing");

let receipts = provider
.tx_status(&tx_id)
.await?
.take_receipts_checked(Some(&self.log_decoder))?;

self.get_response(receipts)
}

/// Call a contract's method on the node, in a simulated manner, meaning the state of the
/// blockchain is *not* modified but simulated.
///
pub async fn simulate(&mut self) -> Result<FuelCallResponse<D>> {
self.call_or_simulate(true).await
}
Expand All @@ -626,8 +613,7 @@ where
let tx = self.build_tx().await?;
let provider = self.account.try_provider()?;

let chain_id = provider.chain_id();
self.cached_tx_id = Some(tx.id(chain_id));
self.cached_tx_id = Some(tx.id(provider.chain_id()));

let tx_status = if simulate {
provider.checked_dry_run(tx).await?
Expand Down Expand Up @@ -903,18 +889,6 @@ impl<T: Account> MultiContractCallHandler<T> {
Ok(SubmitResponseMultiple::new(tx_id, self))
}

pub async fn response<D: Tokenizable + Debug>(self) -> Result<FuelCallResponse<D>> {
let provider = self.account.try_provider()?;
let tx_id = self.cached_tx_id.expect("Cached tx_id is missing");

let receipts = provider
.tx_status(&tx_id)
.await?
.take_receipts_checked(Some(&self.log_decoder))?;

self.get_response(receipts)
}

/// Call contract methods on the node, in a simulated manner, meaning the state of the
/// blockchain is *not* modified but simulated.
/// It is the same as the [call] method because the API is more user-friendly this way.
Expand All @@ -930,9 +904,8 @@ impl<T: Account> MultiContractCallHandler<T> {
) -> Result<FuelCallResponse<D>> {
let tx = self.build_tx().await?;
let provider = self.account.try_provider()?;
let chain_id = provider.chain_id();

self.cached_tx_id = Some(tx.id(chain_id));
self.cached_tx_id = Some(tx.id(provider.chain_id()));

let tx_status = if simulate {
provider.checked_dry_run(tx).await?
Expand Down
12 changes: 0 additions & 12 deletions packages/fuels-programs/src/script_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,6 @@ where
Ok(SubmitResponse::new(tx_id, self))
}

pub async fn response(self) -> Result<FuelCallResponse<D>> {
let tx_id = self.cached_tx_id.expect("Cached tx_id is missing");

let receipts = self
.provider
.tx_status(&tx_id)
.await?
.take_receipts_checked(Some(&self.log_decoder))?;

self.get_response(receipts)
}

/// Call a script on the node, in a simulated manner, meaning the state of the
/// blockchain is *not* modified but simulated.
/// It is the same as the [`call`] method because the API is more user-friendly this way.
Expand Down

0 comments on commit fcc6f8c

Please sign in to comment.