Skip to content

Commit

Permalink
fix: run precompute method when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
iqdecay committed Jun 20, 2023
1 parent bb8b031 commit 5972fca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
32 changes: 29 additions & 3 deletions packages/fuels-core/src/types/wrappers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use fuel_tx::{
field::{
GasLimit, GasPrice, Inputs, Maturity, Outputs, Script as ScriptField, ScriptData, Witnesses,
},
Bytes32, Chargeable, ConsensusParameters, Create, FormatValidityChecks, Input as FuelInput,
Output, Salt as FuelSalt, Script, StorageSlot, Transaction as FuelTransaction, TransactionFee,
UniqueIdentifier, Witness,
Bytes32, Cacheable, Chargeable, ConsensusParameters, Create, FormatValidityChecks,
Input as FuelInput, Output, Salt as FuelSalt, Script, StorageSlot,
Transaction as FuelTransaction, TransactionFee, UniqueIdentifier, Witness,
};

use crate::{
Expand Down Expand Up @@ -75,6 +75,10 @@ pub trait Transaction: Into<FuelTransaction> + Send {
parameters: &ConsensusParameters,
) -> Result<(), Error>;

fn precompute(&mut self, chain_id: u64) -> Result<(), Error>;

fn is_computed(&self) -> bool;

fn id(&self, chain_id: u64) -> Bytes32;

fn maturity(&self) -> u32;
Expand Down Expand Up @@ -121,6 +125,20 @@ impl Transaction for TransactionType {
}
}

fn is_computed(&self) -> bool {
match self {
TransactionType::Script(tx) => tx.is_computed(),
TransactionType::Create(tx) => tx.is_computed(),
}
}

fn precompute(&mut self, chain_id: u64) -> Result<(), Error> {
Ok(match self {
TransactionType::Script(tx) => tx.precompute(chain_id)?,
TransactionType::Create(tx) => tx.precompute(chain_id)?,
})
}

fn check_without_signatures(
&self,
block_height: u32,
Expand Down Expand Up @@ -277,6 +295,14 @@ macro_rules! impl_tx_wrapper {
.check_without_signatures(block_height.into(), parameters)?)
}

fn is_computed(&self) -> bool {
self.tx.is_computed()
}

fn precompute(&mut self, chain_id: u64) -> Result<(), Error> {
Ok(self.tx.precompute(&chain_id.into())?)
}

fn id(&self, chain_id: u64) -> Bytes32 {
self.tx.id(&chain_id.into())
}
Expand Down
11 changes: 5 additions & 6 deletions packages/fuels-programs/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl Contract {
tx_parameters,
);

let tx = account
let mut tx = account
.add_fee_resources(tb, 0, Some(1))
.await
.map_err(|err| error!(ProviderError, "{err}"))?;
Expand All @@ -257,12 +257,11 @@ impl Contract {
.try_provider()
.map_err(|_| error!(ProviderError, "Failed to get_provider"))?;
let chain_info = provider.chain_info().await?;
let consensus_params = provider.consensus_parameters();

tx.check_without_signatures(
chain_info.latest_block.header.height,
&provider.consensus_parameters(),
)?;
provider.send_transaction(&tx).await?;
tx.precompute(consensus_params.chain_id.into())?;
tx.check_without_signatures(chain_info.latest_block.header.height, &consensus_params)?;
provider.send_transaction(&mut tx).await?;

Ok(self.contract_id.into())
}
Expand Down

0 comments on commit 5972fca

Please sign in to comment.