fuels-rs

Fuel Network Rust SDK

APACHE-2.0 License

Downloads
1.9M
Stars
44.7K
Committers
30

Bot releases are hidden (Show)

fuels-rs - v0.49.0

Published by digorithm about 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.48.0...v0.49.0

fuels-rs - v0.48.0

Published by digorithm about 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.47.0...v0.48.0

Breaking changes and new features

Predicate gas estimation fix

Recently, we've had an issue with estimating gas in predicates. This release fixes it but introduces some small API changes: calculate_base_amount_with_fee() now returns an Option<64>. We also went from fn fee_checked_from_tx(&self, params: &ConsensusParameters) -> Option<TransactionFee>; to fn fee_checked_from_tx(&self, params: &ConsensusParameters) -> Result<Option<TransactionFee>>;

Storage slots autoload

Automatic Loading of Storage Slots: Storage slots are now autoloaded by default to simplify and optimize the integration process. Should you wish to opt-out, an option is readily available.

When the StorageConfiguration indicates that autoload should be enabled, Contract::load_from will attempt to find the storage slots file within the same directory as the contract binary. This ensures a seamless experience without needing additional configuration in typical setups.

Enhancements related to this feature:

Guided Error Handling: The SDK will generate an error if the storage slots file is missing. In this scenario, you will be given guidance to source the required file or deactivate the autoload feature to help the user.

Priority Configuration: Users can still manually configure storage slots in StorageConfiguration. This manual configuration will precede the default settings autoloaded from the storage slots file.

Bug Fix: Rectified an error exposed by the autoload feature. Previously, the system did not properly account for storage slots during the computation of the heap data offset for predicates. This has now been addressed.

Breaking Changes:

Updated Storage Configuration Interface: As you know, modifications have been made to the storage configuration interface. Please review the documentation to understand these changes and adjust your setups accordingly.

Behavioural Adjustments with Autoloading: Since storage slots are now autoloaded by default, some users may notice differences in system behaviour. Assessing this feature in your context is important to ensure it aligns with your project's requirements.

This is how the usage around storage slots look like:

#[tokio::test]
async fn storage_slots_override() -> Result<()> {
    {
        // ANCHOR: storage_slots_override
        use fuels::{programs::contract::Contract, tx::StorageSlot};
        let slot_override = StorageSlot::new([1; 32].into(), [2; 32].into());
        let storage_config =
            StorageConfiguration::default().add_slot_overrides([slot_override]);

        let load_config =
            LoadConfiguration::default().with_storage_configuration(storage_config);
        let _: Result<Contract> = Contract::load_from("...", load_config);
        // ANCHOR_END: storage_slots_override
    }

    {
        // ANCHOR: storage_slots_disable_autoload
        use fuels::programs::contract::Contract;
        let storage_config = StorageConfiguration::default().with_autoload(false);

        let load_config =
            LoadConfiguration::default().with_storage_configuration(storage_config);
        let _: Result<Contract> = Contract::load_from("...", load_config);
        // ANCHOR_END: storage_slots_disable_autoload
    }

    Ok(())
}
fuels-rs - v0.47.0

Published by digorithm about 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.46.0...v0.47.0

Breaking changes

*_set methods renamed to *_with

Some *_set methods were renamed to *_with to reflect better the ownership model they follow.

For instance, this:

let configuration = LoadConfiguration::default()
    .set_storage_configuration(storage_configuration)
    .set_salt(salt);

// Optional: Configure deployment parameters
let tx_parameters = TxParameters::default()
    .set_gas_price(0)
    .set_gas_limit(1_000_000)
    .set_maturity(0);

Becomes:

let configuration = LoadConfiguration::default()
    .with_storage_configuration(storage_configuration)
    .with_salt(salt);

// Optional: Configure deployment parameters
let tx_parameters = TxParameters::default()
    .with_gas_price(0)
    .with_gas_limit(1_000_000)
    .with_maturity(0);

As well as

  1. set_contract_ids -> with_contract_ids
  2. set_gas_forwarded -> with_gas_forwarded
  3. CallParameters::default().set_amount(deposit_amount).set_asset_id(base_asset_id); -> CallParameters::default().with_amount(deposit_amount).with_asset_id(base_asset_id);
  4. set_consensus_parameters(consensus_parameters); -> with_consensus_parameters(consensus_parameters);

So, when migrating to this version, some things will break, and to fix it is easy: rename these methods with set in them to with, and it should work seamlessly.

String types

Sway's String type is equivalent to the Rust String. This change was impossible before because the String name was already taken for statically-sized strings, now called StringArrays.

This only affects you if you use ParamTypes directly: ParamType::String(len) is now ParamType::StringArray(len) and ParamType::StdString is now ParamType::String.

Sending transactions doesn't return receipts anymore, only the transaction ID

send_transaction(&tx) used to wait for the transaction to be completed and then it would return the receipts. That's not the case anymore; Now, it returns the transactions ID and then you use this ID to query for the receipts:

let receipts = self.try_provider()?.send_transaction(&tx).await?;

Becomes

let tx_id = self.try_provider()?.send_transaction(&tx).await?;
let receipts = provider.get_receipts(&tx_id).await?;

This allows more flexibility to send transactions asynchronously and then grab the receipts if needed.

fuels-rs - v0.46.0

Published by digorithm about 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.45.1...v0.46.0

fuels-rs - v0.45.1

Published by digorithm about 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.45.0...v0.45.1

fuels-rs - v0.45.0

Published by digorithm about 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.44.0...v0.45.0

New features

Support for Sway's dynamic string and string slices type;

Usage example:

let contract_methods = contract_instance.methods();
{
    let resp = contract_methods.return_dynamic_string().call().await?.value;
    assert_eq!(resp, "Hello World");
}
{
    let _resp = contract_methods
        .accepts_dynamic_string(String::from("Hello World"))
        .call()
        .await?;
}

See the documentation for more details.

Automatic macro recompile

This means abigen! and setup_program_test! macros can now detect file changes.

Improve log decoder error

The log decoder error object now has a data field.

Support for fuel-core 0.20

This means support for the upcoming beta-4 release of the network.

fuels-rs - v0.44.0

Published by digorithm over 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.43.0...v0.44.0

New features and breaking changes

Transaction dependencies estimation for script calls

Similar to the same feature for contract calls. This introduces a breaking change: TxDependencyExtension needs to be in scope to use append_variable_outputs and append_contract.

Support for U256 type

Missing types in the prelude and re-exports

Some types were missing from the main umbrella crate. These were added to it so now you can pull these from fuels. Types like fuel_tx::Output, TxPointer, UtxoId, Nonce, and more.

New LogDecoder getter for script instances

Improved error messages for the transaction builder

Support for configuring the client's RocksDB through the SDK

#[tokio::test]
#[cfg(any(not(feature = "fuel-core-lib"), feature = "rocksdb"))]
async fn create_or_use_rocksdb() -> Result<()> {
    use fuels::prelude::*;
    use std::path::PathBuf;

    // ANCHOR: create_or_use_rocksdb
    let provider_config = Config {
        database_path: PathBuf::from("/tmp/.spider/db"),
        database_type: DbType::RocksDb,
        ..Config::local_node()
    };
    // ANCHOR_END: create_or_use_rocksdb

    launch_custom_provider_and_get_wallets(Default::default(), Some(provider_config), None)
        .await;

    Ok(())
}
fuels-rs - v0.41.1

Published by digorithm over 1 year ago

Hotfix to unblock the composability labs team. Adds the predicates configurable feature to the 0.41 version.

fuels-rs - v0.43.0

Published by digorithm over 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.42.0...v0.43.0

Breaking changes

No more .into() when passing contract IDs or addresses to contract methods

Before:

let response = contract_methods
            .transfer_coins_to_output(1_000_000, contract_id.into(), address.into())
            .append_variable_outputs(1)
            .call()
            .await?;

After:

let response = contract_methods
            .transfer_coins_to_output(1_000_000, contract_id, address)
            .append_variable_outputs(1)
            .call()
            .await?;
fuels-rs - v0.42.0

Published by digorithm over 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.41.0...v0.42.0

Breaking changes

Types import path changes

  • Use fuels::types::input::Input instead of fuels::tx::input
  • Use fuels::types::coin::Coin instead of fuels::client::schema::coin::Coin and fuels::tx::Output::Coin
  • Use fuels::types::AssetId instead of fuels::client::schema::AssetId and fuels::tx::AssetId
  • Use fuels::tx::UtxoId instead of fuels::client::schema::UtxoId
  • Use fuels::types::coin::CoinStatus instead of fuels::client::schema::coin::CoinStatus
  • Use fuels::types::resource::Resource instead of fuels::client::schema::resource::Resource
  • Use fuels_types::types::Bytes32 instead of fuel_tx::Bytes32

Configurables for predicates

    abigen!(Predicate(
        name = "MyPredicate",
        abi = "packages/fuels/tests/predicates/predicate_configurables/out/debug/predicate_configurables-abi.json"
    ));

    let new_struct = StructWithGeneric {
        field_1: 32u8,
        field_2: 64,
    };
    let new_enum = EnumWithGeneric::VariantTwo;

    let configurables = MyPredicateConfigurables::new()
        .set_STRUCT(new_struct.clone())
        .set_ENUM(new_enum.clone());

    let predicate_data = MyPredicateEncoder::encode_data(8u8, true, new_struct, new_enum);

    let mut predicate: Predicate = Predicate::load_from(
        "tests/predicates/predicate_configurables/out/debug/predicate_configurables.bin",
    )?
    .with_data(predicate_data)
    .with_configurables(configurable);

fuel-core @ 0.18 changes

Note that some of these changes are subject to subsequent changes in future UX improvements.

  • Signing the transaction and predicate id generation requires ChainId(ConsensusParameters).
  • Now, tokens should be transferred to the contract first, and after you can transfer them via SMO or another transfer. So in some tests, we first need to transfer money to the contract.
  • The produce_blocks function is updated and doesn't require TimeParameters.
  • Removed redundant usage of MessageId. Now the identifier of the message is a Nonce.
  • Removed Output::Message. Now you don't need to specify it in the outputs. Because of that SMO opcode doesn't require a message output index.
  • The proof API is updated with a new design: https://github.com/FuelLabs/fuel-core/issues/1046. To prove the block at height X, you need at least a committed X + 1 block.
  • Predicate::set_provider now returns a Result because it can fail if the "new" provider has different consensus parameters than the consensus parameters used previously
  • Predicate can be loaded with a provider using load_from_with_provider and from_code_and_provider. The from_code and load_from remain and use the default ConsensusParameters value.
  • Provider::new now takes a ConsensusParameters argument, so we can avoid changing the API of downstream clients.
  • setup_test_client now returns ConsensusParameters of the client. This was either this or setup_test_provider would have to change, and the former is much less used than the latter.
fuels-rs - v0.41.0

Published by digorithm over 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.40.0...v0.41.0

Breaking changes

New setup_program_test! macro

The macro setup_contract_test! has been renamed to setup_program_test! and can now generate bindings for scripts and predicates. You can also create a script instance via LoadScript. Example:

    setup_program_test!(
        Wallets("wallet"),
        Abigen(Script(
            name = "MyScript",
            project = "packages/fuels/tests/types/scripts/script_generics"
        )),
        LoadScript(
            name = "script_instance",
            script = "MyScript",
            wallet = "wallet"
        )
    );

The command for generating bindings (Abigen) now requires the program type to be stated. Before: Abigen(name="..., now: Abigen(Contract(name="...".

Read the doc section The setup_program_test! macro for more details.

fuels-rs - v0.40.0

Published by digorithm over 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.39.0...v0.40.0

New Features

Add support for Bytes and RawSlice inputs (#904)

This update introduces support for Bytes and RawSlice input types, giving developers more flexibility when working with byte sequences and raw slices. Thanks to @hal3e for this contribution!

Add LogResult struct (#919)

We have added a new LogResult struct to make it easier to work with and process log results from the Fuel Virtual Machine. This new feature will improve the developer experience when working with logs. Kudos to @Salka1988 for this addition!

Improvements

Separate Contract loading and deploying (#899)

This release includes a significant refactor that separates the Contract loading and deploying process. This change aims to improve code readability and maintainability. Great work by @hal3e!

The biggest change for the user is the way to deploy contracts. Previously the user would use deploy directly:

     let contract_id = Contract::deploy(
        "tests/contracts/configurables/out/debug/configurables.bin",
        &wallet,
        DeployConfiguration::default(),
    )
    .await?;

This function did two things: Load and then deploy the contract. Now, it looks like this:

    let contract_id = Contract::load_from(
        "tests/contracts/configurables/out/debug/configurables.bin",
        LoadConfiguration::default(),
    )?
    .deploy(&wallet, TxParameters::default())
    .await?;

This makes it clear what is being done. It makes the LoadConfiguration simpler, and also, now the user can get the contract_id or state_root easily.

    let contract_id = Contract::load_from(
        "tests/contracts/configurables/out/debug/configurables.bin",
        LoadConfiguration::default(),
    )?
    .contract_id();

Bug Fixes

Fix broken doc link (#922)

A broken documentation link has been fixed, ensuring users can now access the relevant information without issues. Thanks to @sarahschwartz for the quick fix!

Fix Parameterize and Tokenizable for wasm enums (#928)

We have resolved an issue where Parameterize and Tokenizable for wasm enums were broken. This fix ensures that these traits now work as intended for wasm enums. Credit goes to @segfault-magnet for identifying and fixing the issue!

Miscellaneous

Address default-features warnings on cargo nightly (chore) (#921)

We've addressed the default-features warnings on cargo nightly builds to keep the project up-to-date and reduce warnings. Special thanks to @segfault-magnet for taking care of this!

We encourage you to update your Fuels-rs library to v0.40 and take advantage of these new features and improvements. Your feedback is invaluable, so please don't hesitate to report any issues or share your thoughts on this release!

fuels-rs - v0.39.0

Published by digorithm over 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.38.1...v0.39.0

New features

Bytes types

The Sway Bytes type is now supported in the SDK.

Pay for fees using predicate

We've recently introduced the Account trait, which encapsulates all the behavior you commonly see in a wallet. Predicates also implement the Account trait now. This means you can use a Predicate the same way you'd use a wallet, when paying for transaction fees. For instance:

// Instead of passing the wallet used to sign the contract's transaction, we can now pass a predicate
let contract_methods = MyContract::new(contract_id, predicate).methods();
let tx_params = TxParameters::new(1000000, 10000, 0);

assert_eq!(predicate.get_asset_balance(&BASE_ASSET_ID).await?, 192);

let response = contract_methods
    .initialize_counter(42) // Build the ABI call
    .tx_params(tx_params)
    .call()
    .await?;

Note that this new feature introduces many breaking changes. Read more here: https://github.com/FuelLabs/fuels-rs/pull/815.

fuels-rs - v0.38.1

Published by digorithm over 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.38.0...v0.38.1

fuels-rs - v0.38.0

Published by digorithm over 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.37.1...v0.38.0

New features

Message output estimation

The transaction dependencies estimation method that automatically estimates things like contract IDs and variable outputs now also estimates message outputs.

Filtering spendable resources

get_spendable_resources now takes a filter object:

let filter = ResourceFilter {
            from: wallet.address().clone(),
            amount: coin_amount_1,
            excluded_utxos: vec![coin_2_utxo_id],
            excluded_message_ids: vec![message_id],
            ..Default::default()
        };
let resources = provider.get_spendable_resources(filter).await.unwrap();

Retrieving latest block time

The Provider now has a simple way to retrieve the latest block time: latest_block_time:

#[tokio::test]
async fn can_retrieve_latest_block_time() -> Result<()> {
    let provider = given_a_provider().await;
    let since_epoch = 1676039910;

    let latest_timestamp = Utc.timestamp_opt(since_epoch, 0).unwrap();
    let time = TimeParameters {
        start_time: latest_timestamp,
        block_time_interval: Duration::seconds(1),
    };
    provider.produce_blocks(1, Some(time)).await?;

    assert_eq!(
        provider.latest_block_time().await?.unwrap(),
        latest_timestamp
    );

    Ok(())
}

try_from_type_application return type change

try_from_type_application will not panic anymore. Instead, we propagate an InvalidData error. Type::from() is now Type::try_from().

Coins query no longer returns spent coins

Vec as output types for contract methods

The SDK now supports contract methods that return a vector:

Contract deployment configuration object

We've introduced a new builder struct, DeployConfiguration, for contract deployment. If you want to deploy a contract with the default configuration, you can do it like this:

let contract_id = Contract::deploy(
   "tests/contracts/configurables/out/debug/configurables.bin",
    &wallet,
    DeployConfiguration::default(),
)
.await?;

Alternatively, you can set TxParameters, StorageConfiguration, Configurables and Salt like this:

abigen!(Contract(
    name = "MyContract",
    abi = "packages/fuels/tests/contracts/configurables/out/debug/configurables-abi.json"
));

let wallet = launch_provider_and_get_wallet().await;

let tx_parameters = TxParameters::default()
    .set_gas_price(0)
    .set_gas_limit(1_000_000)
    .set_maturity(0);

let key = Bytes32::from([1u8; 32]);
let value = Bytes32::from([2u8; 32]);
let storage_slot = StorageSlot::new(key, value);
let storage_configuration =
    StorageConfiguration::default().set_manual_storage(vec![storage_slot]);

let configurables = MyContractConfigurables::new()
    .set_STR_4("FUEL".try_into()?)
    .set_U8(42u8);

let rng = &mut StdRng::seed_from_u64(2322u64);
let salt: [u8; 32] = rng.gen();

let contract_id = Contract::deploy(
    "tests/contracts/configurables/out/debug/configurables.bin",
    &wallet,
    DeployConfiguration::default()
        .set_tx_parameters(tx_parameters)
        .set_storage_configuration(storage_configuration)
        .set_configurables(configurables)
        .set_salt(salt),
)
.await?;

Type path support and resolution of conflicting types

If you have different types with the same name across multiple files, the previous SDK versions might have had difficulty dealing with them. The teams have been working on fixing this once and for all. The solution is that now you can compile your Sway code with a new flag --json-abi-with-callpaths (which will soon be the default); this will generate the JSON ABI with proper paths (my_mod::MyType instead of just MyType) and the SDK will generate the appropriate Rust code in the appropriate module, solving the conflicting types issue.

fuels-rs - v0.37.1

Published by digorithm over 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.37.0...v0.37.1

fuels-rs - v0.37.0

Published by digorithm over 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.36.1...v0.37.0

New features

New script APIs: ScriptTransaction and CreateTransaction

You can now build a script transaction in a much easier fashion like this:

let mut tx = ScriptTransaction::new(&inputs, &outputs, params)
                .with_script(binary)
                .with_script_data(data);
                
// or to extend inputs/outputs
tx.inputs_mut().extend(other_inputs);
tx.outputs_mut().extend(other_outputs);

This means we've removed ExecutionScript since this abstraction lacked functionality. And also, constants and params were moved from fuels-core to fuels-types to avoid circular dep.

Configurable constants

An exciting new feature recently landed in Sway: constants. Now, we've added support in the Rust SDK so that you can configure these constants without needing to recompile your Sway code. Read more here: https://github.com/FuelLabs/fuels-rs/pull/844.

fuels-rs - v0.36.1

Published by digorithm over 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.36.0...v0.36.1

fuels-rs - v0.36.0

Published by Voxelot over 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.35.1...v0.36.0

fuels-rs - v0.35.1

Published by digorithm over 1 year ago

What's Changed

Full Changelog: https://github.com/FuelLabs/fuels-rs/compare/v0.35.0...v0.35.1