Skip to content

v0.32.0

Compare
Choose a tag to compare
@digorithm digorithm released this 07 Dec 04:55
· 452 commits to master since this release
85b5c07

What's Changed

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 Messages

Before, you could only use Coins to pay for tx fees; now, you can use Messages 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 Tokens 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();