Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: transaction builder no_input_to_cover_fees #1302

Merged
merged 7 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions examples/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ mod tests {

#[cfg(feature = "fuel-core-lib")]
use fuels::prelude::Config;
use fuels::prelude::Result;
use fuels::types::{Bits256, EvmAddress, Identity};
use fuels::{
prelude::Result,
types::{Bits256, EvmAddress, Identity},
};

#[tokio::test]
async fn bytes32() -> Result<()> {
Expand Down
19 changes: 9 additions & 10 deletions packages/fuels-core/src/types/transaction_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use fuel_asm::{op, GTFArgs, RegId};
use fuel_crypto::{Message as CryptoMessage, Signature};
use fuel_tx::{
field::{Inputs, Policies as PoliciesField, WitnessLimit, Witnesses},
input::coin::{CoinPredicate, CoinSigned},
policies::{Policies, PolicyType},
Buildable, Chargeable, ConsensusParameters, Create, Input as FuelInput, Output, Script,
StorageSlot, Transaction as FuelTransaction, TransactionFee, TxPointer, UniqueIdentifier,
Expand Down Expand Up @@ -405,14 +406,12 @@ impl ScriptTransactionBuilder {
.collect()
}

fn no_spendable_input<'a, I: IntoIterator<Item = &'a FuelInput>>(inputs: I) -> bool {
fn no_input_to_cover_fees<'a, I: IntoIterator<Item = &'a FuelInput>>(inputs: I) -> bool {
!inputs.into_iter().any(|i| {
matches!(
i,
FuelInput::CoinSigned(_)
hal3e marked this conversation as resolved.
Show resolved Hide resolved
| FuelInput::CoinPredicate(_)
| FuelInput::MessageCoinSigned(_)
| FuelInput::MessageCoinPredicate(_)
FuelInput::CoinSigned(CoinSigned{asset_id, ..})
| FuelInput::CoinPredicate(CoinPredicate{asset_id, ..}) if *asset_id == BASE_ASSET_ID
)
})
}
Expand All @@ -424,10 +423,10 @@ impl ScriptTransactionBuilder {
) -> Result<()> {
let consensus_params = provider.consensus_parameters();

// The dry-run validation will check if there is any spendable input present in
// the transaction. If we are dry-running without inputs we have to add a temporary one.
let no_spendable_input = Self::no_spendable_input(tx.inputs());
if no_spendable_input {
// The dry-run validation will check if there is any input that can cover the fees.
// If we are dry-running without inputs we have to add a temporary one.
let no_input_to_cover_fees = Self::no_input_to_cover_fees(tx.inputs());
if no_input_to_cover_fees {
tx.inputs_mut().push(FuelInput::coin_signed(
Default::default(),
Default::default(),
Expand All @@ -453,7 +452,7 @@ impl ScriptTransactionBuilder {
.await?;

// Remove dry-run input and witness.
if no_spendable_input {
if no_input_to_cover_fees {
tx.inputs_mut().pop();
tx.witnesses_mut().pop();
tx.set_witness_limit(tx.witness_limit() - WITNESS_STATIC_SIZE as u64);
Expand Down