Releases: FuelLabs/fuels-rs
v0.35.1
What's Changed
- feat: Reintroduce
Abigen
publicly in a new cratefuels-code-gen
by @segfault-magnet in #819 - Bump versions to 0.35.1 by @digorithm in #820
Full Changelog: v0.35.0...v0.35.1
v0.35.0
What's Changed
- style!: use C-style getters naming for SDK methods by @iqdecay in #784
- feat: improve contract deployment error messages by @Salka1988 in #786
- fix: add both chain_config and coins to node config by @Salka1988 in #794
- refactor!: move abigen to fuels-macros crate by @hal3e in #790
- feat: support
raw_slice
returns from scripts and contracts by @iqdecay in #743 - docs: update node-beta-1 to node-beta-2 by @Salka1988 in #797
- Reorganize navigation, add testing basics page by @sarahschwartz in #805
- feat: add custom assets to contract call by @Salka1988 in #778
- cargo doc warnings to become errors in our CI by @Salka1988 in #798
- feat!:
derive
ableParameterize
andTokenizable
by @hal3e in #804 - refactor: fuels-types Error by @hal3e in #796
- fix: sign transaction in
ScriptCallHandler
by @hal3e in #806 - Fuel Core v0.16.1 by @Voxelot in #813
- Update Rust version to 1.67.0 by @digorithm in #814
- Use workspace level package for common crate metadata values by @Voxelot in #816
- Pre-publish verification by @Voxelot in #818
- Bump SDK to v0.35.0 by @Voxelot in #817
New Contributors
- @sarahschwartz made their first contribution in #805
Full Changelog: v0.34.0...v0.35.0
v0.34.0
What's Changed
- feat!: add predicates abigen by @hal3e in #726
- fix: logging with multiple(external) logs by @hal3e in #751
- Remove empty doc section on scripts by @MujkicA in #760
- fix: fix transfer script by @iqdecay in #761
- Add estimate tx dependencies to docs by @MujkicA in #756
- Automatic fee payment with modified inputs by @Salka1988 in #748
- fix: field
time
inHeader
andTransactionResponse
by @cheng404 in #739 - feat!: support logs from external contracts by @hal3e in #762
- fix: do not modify receipts by @hal3e in #777
- refactor: include fuel-abi-types crate by @Salka1988 in #776
- feat!: new
abigen!
,setup_contract_test!
, and handling of shared types by @segfault-magnet in #763 - refactor!: reorganize types by @hal3e in #779
- Bump CI forc to 0.33 by @MujkicA in #782
- Bump versions to 0.34.0 by @digorithm in #787
- Remove --no-verify flag by @digorithm in #788
- Bring back --no-verify flag by @digorithm in #789
New Contributors
Full Changelog: v0.33.0...v0.34.0
Breaking changes
New abigen!
macro
This release includes a huge breaking change to how abigen!
works and how users will interact with it. The main motivation for this change was a pretty big problem we recently discovered: what happens when you use a Sway library
that shares types between contract A and contract B? You'd use a first abigen!()
for the contract A and another abigen!()
call for contract B. Since both contracts' JSON ABIs include the types coming from the library
included... guess what? There's a conflict of generated types: the shared types in the library
would be generated twice and, thus, be different types under the eyes of the Rust compiler. Not a good time!
To fix this, we've rebuilt the macro so that it's called only once, and it takes all necessary contracts, predicates, and scripts that you need. Now it looks like this:
abigen!(
Contract(name="ContractA", abi="contract_a-abi.json"),
Contract(name="ContractB", abi="contract_b-abi.json"),
Script(name="SomeScript", abi="some_script-abi.json"),
Predicate(name="SomePredicate", abi="some_predicate-abi.json"),
// ...
);
Although it's a big breaking change, it's fairly easy to migrate:
abigen!(
MyContract,
"packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json"
);
Becomes
abigen!(
Contract(name="MyContract", abi="packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json"),
);
Read the updated SDK book for more details about the new abigen!
.
New setup_contract_test!
The new abigen!
opened up the possibility of improving the old setup_contract_test!
macro as well. Similarly to the old abigen!
macro, if you had multiple contracts, you'd call setup_contract_test!
multiple times, so you'd have many blocks like this:
setup_contract_test!(
contract_instance,
wallet,
"packages/fuels/tests/contracts/contract_test"
);
Now, you can call setup_contract_test!
just once, passing all your contracts, scripts, predicates, and deployments, all at once:
setup_contract_test!(
Wallets("wallet"),
Abigen(
name = "TestContract",
abi = "packages/fuels/tests/contracts/contract_test"
),
Deploy(
name = "contract_instance",
contract = "TestContract",
wallet = "wallet"
),
);
Generated types with non-unique names can now be accessed only by qualifying the type path (i.e., abigen_bindings::some_contract_a_mod::SomeNonUniqueType
). For more details, read the updated SDK book.
Predicate
new send and receive API
Before, transferring the funds to a predicate looked like this:
wallet.transfer(
predicate_address,
amount_to_predicate,
asset_id,
TxParameters::default(),
).await?;
It started from the wallet
, taking the predicate_address
. Now, it starts from the predicate itself:
predicate.receive(&wallet, amount_to_predicate, asset_id, None).await?;
Similarly, spending a predicate also started from the wallet, which never really made much sense:
wallet.spend_predicate(
predicate_address,
predicate_code,
amount_to_predicate,
asset_id,
receiver.address(),
Some(predicate_data),
TxParameters::default(),
).await?;
Now, it's a lot simpler, and it starts from the predicate, with the addition of a new encode_data()
that you can use to pass the arguments of a predicate:
predicate
.encode_data(signatures) // This is a new method; it'll encode the arguments for you.
.spend(&receiver, amount_to_predicate, asset_id, None)
.await?;
For more details, check the updated predicates in the latest docs.
Logging from external contracts
If your contract method is calling other contracts you will have to add the appropriate Inputs and Outputs to your transaction. For your convenience, the SDK provides two methods that can set those input and outputs for you: set_contracts(&[&contract_instance, ...])
and set_contract_ids(&[&contract_id, ...])
.
set_contracts(&[&contract_instance, ...])
was changed and it now requires contract instances that were created using the abigen
macro. When setting the external contracts with this method, logs and require revert errors originating from the external contract can be propagated and decoded by the calling contract. Here is an example:
let response = contract_caller_instance
.methods()
.increment_from_contract(lib_contract_id.into(), 42)
.set_contracts(&[&lib_contract_instance])
.call()
.await?;
You can also have the old behavior where you used contact ids with the set_contract_ids(&[&contract_id, ...])
method. Please note that you will not get logs or require errors propagated if you use this approach. Here is an example:
let response = contract_caller_instance
.methods()
.increment_from_contract(lib_contract_id.into(), 42)
.set_contract_ids(&[lib_contract_id.clone()])
.call()
.await?;
Better types importing experience
One piece of feedback we've received often is how hard it is to find and import fundamentals types exported by the fuels-rs
crate. We're slowly addressing this by moving these types around to places where it makes sense for them to be.
In this release, we're re-exporting types in a single place — users will only care about this single place to pull types: fuels_types::core
v0.33.0
What's Changed
- fix
setup_test_client
parameters by @Salka1988 in #737 - Update to fuel-core v0.15.1 by @Voxelot in #741
- feat: Add
attributes
toABIFunction
by @anton-trunov in #744 - feat: build test projects concurrently by default by @hal3e in #747
- release: Bump versions to
0.33.0
by @anton-trunov in #750
New Contributors
- @anton-trunov made their first contribution in #744
Full Changelog: v0.32.2...v0.33.0
v0.32.2
What's Changed
- Updated code to use new
fuel-core
0.15.0
by @xgreenx in #710 - feat: Add
messages_types
toProgramABI
by @mohammadfawaz in #738 - release: Bump versions to
0.32.2
by @mohammadfawaz in #740
Full Changelog: v0.32.1...v0.32.2
v0.32.1
What's Changed
- bug: asset ids not collated properly. by @segfault-magnet in #728
- Setting a temporarily no-verify to true so we can bypass the cyclic by @digorithm in #731
- release: Bump versions to 0.32.1 by @digorithm in #732
Full Changelog: v0.32.0...v0.32.1
v0.32.0
What's Changed
- Use non-tagged version of forc in CI by @Salka1988 in #699
- feat: Add support for custom block time by @MujkicA in #684
- ci: update
forc
andrustc
version in CI by @iqdecay in #706 - docs: update forc setup and test workflow by @hal3e in #705
- fix: support empty structs by @hal3e in #708
- feat!: add parsed log to revert error by @hal3e in #690
- feat: support main function arguments in scripts by @iqdecay in #620
- fix: pay tx fees with message by @MujkicA in #715
- feat: get message proof by @MujkicA in #700
- feat: add logs for scripts by @hal3e in #716
- feat: derive additional traits for Identity by @hal3e in #719
- feat: add predicate data encoder method by @digorithm in #720
- Fix some broken links to the Sway book by @mohammadfawaz in #722
- feat!: convert client types to fuels types by @MujkicA in #707
- feat: add vector support for scripts by @hal3e in #718
- release: Bump versions to 0.32.0 by @digorithm in #725
Full Changelog: v0.31.1...v0.32.0
New features and breaking changes
Custom block time
Adds an optional parameter to produce_blocks
to set the start time and the interval of the produced blocks. Useful for testing conditions that require specific times for a block to be produced.
Breaking change
produce_blocks()
now takes an additional parameter:Option<TimeParameters>
.
Parsed and readable revert errors
Revert errors used to be hard to debug, as the SDK would simply dump the hex value of the error coming from the client. Now, this revert error is properly parsed, making debugging a lot easier.
Script arguments support
This release also includes supporting script arguments. I.e., your script main()
functions can take arguments; now they're supported by the SDK. This is done through the new script_abigen!
macro:
script_abigen!(
MyScript,
"packages/fuels/tests/scripts/script_with_arguments/out/debug/script_with_arguments-abi.json"
);
let wallet = launch_provider_and_get_wallet().await;
let bin_path =
"../fuels/tests/scripts/script_with_arguments/out/debug/script_with_arguments.bin";
let instance = MyScript::new(wallet, bin_path);
let bim = Bimbam { val: 90 };
let bam = SugarySnack {
twix: 100,
mars: 1000,
};
let result = instance.main(bim, bam).call().await?;
let expected = Bimbam { val: 2190 };
assert_eq!(result.value, expected);
Pay for transaction fees using Message
s
Before, you could only use Coin
s to pay for tx fees; now, you can use Message
s as well. Which is useful, e.g., if you want to spend ETH
through bridging to pay for fees.
Logs for scripts
Logs can now be decoded when using scripts. The interface is similar to the contract's interface.
Breaking changes
Logs now are pulled through the response
returned from a contract call. Instead of pulling them from the contract instance itself:
let contract_methods = contract_instance.methods();
let response = contract_methods.produce_logs_values().call().await?;
let log_u64 = contract_instance.logs_with_type::<u64>(&response.receipts)?;
let log_u32 = contract_instance.logs_with_type::<u32>(&response.receipts)?;
let log_u16 = contract_instance.logs_with_type::<u16>(&response.receipts)?;
let log_u8 = contract_instance.logs_with_type::<u8>(&response.receipts)?;
Pull the logs from the response:
let contract_methods = contract_instance.methods();
let response = contract_methods.produce_logs_values().call().await?;
let log_u64 = response.get_logs_with_type::<u64>()?;
let log_u32 = response.get_logs_with_type::<u32>()?;
let log_u16 = response.get_logs_with_type::<u16>()?;
let log_u8 = response.get_logs_with_type::<u8>()?;
Predicate data encoder
Instead of having to use the SDK's ABIEncoder
directly and deal with Token
s directly in order to encode the predicate_data
that you're passing to your predicate call, you can now simply use the new interface predicate.encode_data()
.
So, we're going from:
// Here we have some abstraction leakage. Having to go to `Token`-land in order to get the job done.
let arg = Token::U32(12345_u32);
let args: Vec<Token> = vec![arg];
let predicate_data = ABIEncoder::encode(&args).unwrap();
let amount_to_unlock = 500;
let _result = second_wallet
.spend_predicate(
predicate_address,
predicate_code,
amount_to_unlock,
AssetId::default(),
second_wallet.address(),
Some(predicate_data),
TxParameters::default(),
)
.await?;
To this:
// No need to deal with `Token`s, just pass whatever Rust's native data here.
let predicate_data: Vec<u8> = predicate.encode_data(42_u64)?;
let amount_to_unlock = 500;
let _result = second_wallet
.spend_predicate(
predicate_address,
predicate_code,
amount_to_unlock,
AssetId::default(),
second_wallet.address(),
Some(predicate_data),
TxParameters::default(),
)
.await?;
Other breaking changes
Type rename: CallResponse
-> FuelCallResponse
Type rename: Script
-> ExecutableFuelCall
The method get_call_execution_script
is now get_executable_call
.
We also go from:
let script = multi_call_handler.get_call_execution_script().await?;
let receipts = script.call(provider).await.unwrap();
to:
let execution_script = multi_call_handler.get_executable_call().await?;
let receipts = execution_script.execute(provider).await.unwrap();
v0.31.1
What's Changed
- chore: remove unused anchors by @hal3e in #695
- add ´scripts´ section in docs by @Salka1988 in #696
- feat: add B512 support by @hal3e in #694
- Contract input set estimation by @Salka1988 in #628
- chore: update
deploy_with_parameters
in docs by @hal3e in #697 - Bump versions to 0.31.1 by @digorithm in #701
Full Changelog: v0.31.0...v0.31.1
v0.31.0
What's Changed
- Remove note on
--generate-logged-types
in the Book by @mohammadfawaz in #678 - feat: add format and clean to
test-projects
by @hal3e in #685 - feat: support evm address by @MujkicA in #668
- fix: rustc can't prove Send on futures returned by contract methods by @Salka1988 in #669
- fix!: get_asset_inputs_for_amount uses resources by @MujkicA in #692
- release: bump versions to 0.31.0 by @digorithm in #693
Full Changelog: v0.30.0...v0.31.0
Breaking changes
Wallet
's get_asset_inputs_for_amount
now uses Resource
s instead of Coin
s
This means that if you want to cover fees of a transaction using any Resource
, i.e., Coin
and Message
(if you're bridging to Ethereum, for instance) get_asset_inputs_for_amount
will now consider Message
s, which it didn't before.