v0.38.0
What's Changed
- Add message output estimation by @MujkicA in #846
- Add cname for gh-pages by @Voxelot in #864
- More cnaming for gh-pages by @Voxelot in #865
- Add latest block time and spendable resources with exclusion by @MujkicA in #833
- chore: update PR template by @hal3e in #869
- feat!: return result from
try_from_type_application
by @hal3e in #870 - fix: coins query no longer returns spent coins by @segfault-magnet in #873
- Resolve cyclic deps by @MujkicA in #859
- feat: check for unused md files in docs by @hal3e in #871
- fix minor typo by @K1-R1 in #876
- feat: support returning
Vec<>
types from contracts by @iqdecay in #848 - refactor: contract deployment configuration by @hal3e in #860
- refactor: remove the
Byte
type from the SDK by @iqdecay in #883 - feat: type path support (
forc
flag--json-abi-with-callpaths
) by @segfault-magnet in #872 - enable cargo sparse protocol by @segfault-magnet in #888
- Bump versions to 0.38.0 by @digorithm in #890
New Contributors
Full Changelog: 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.