Skip to content

Commit

Permalink
Merge branch 'master' into feature/utxo_caching
Browse files Browse the repository at this point in the history
  • Loading branch information
MujkicA authored Oct 2, 2023
2 parents ca0834b + 3b87f37 commit 65a5f9c
Show file tree
Hide file tree
Showing 113 changed files with 3,684 additions and 1,257 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
RUSTFLAGS: "-D warnings"
FUEL_CORE_VERSION: 0.20.4
RUST_VERSION: 1.71.1
FORC_VERSION: 0.44.0
FORC_VERSION: 0.45.0
FORC_PATCH_BRANCH: ""
FORC_PATCH_REVISION: ""

Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
working-directory: packages/fuels

- name: Build Sway test projects
run: forc build --terse
run: forc build --terse --error-on-warnings
working-directory: packages/fuels

- uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -173,6 +173,8 @@ jobs:
install_fuel_core: true
- cargo_command: test
args: --doc --workspace
- cargo_command: machete
args: --skip-target-dir
- command: test_wasm
args:
- command: check_doc_anchors_valid
Expand Down Expand Up @@ -215,6 +217,10 @@ jobs:
if: ${{ matrix.cargo_command == 'nextest' }}
uses: taiki-e/install-action@nextest

- name: Install cargo-machete
if: ${{ matrix.cargo_command == 'machete' }}
uses: taiki-e/install-action@cargo-machete

- name: Cargo (workspace-level)
if: ${{ matrix.cargo_command && !matrix.package }}
run: cargo ${{ matrix.cargo_command }} ${{ matrix.args }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ packages/fuels/tests/**/**/target/
packages/fuels/tests/**/**/.gitignore

# Don't add lock files in the fuels directory.
packages/fuels/Forc.lock
packages/fuels/Forc.lock
64 changes: 33 additions & 31 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@
# https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html#details
resolver = "2"
members = [
"examples/abigen",
"examples/contracts",
"examples/cookbook",
"examples/debugging",
"examples/predicates",
"examples/providers",
"examples/rust_bindings",
"examples/types",
"examples/wallets",
"packages/fuels",
"packages/fuels-accounts",
"packages/fuels-code-gen",
"packages/fuels-core",
"packages/fuels-macros",
"packages/fuels-programs",
"packages/fuels-test-helpers",
"packages/wasm-tests",
"scripts/check-docs",
"examples/codec",
"examples/contracts",
"examples/cookbook",
"examples/debugging",
"examples/macros",
"examples/predicates",
"examples/providers",
"examples/rust_bindings",
"examples/types",
"examples/wallets",
"packages/fuels",
"packages/fuels-accounts",
"packages/fuels-code-gen",
"packages/fuels-core",
"packages/fuels-macros",
"packages/fuels-programs",
"packages/fuels-test-helpers",
"packages/wasm-tests",
"scripts/check-docs",
]

[workspace.package]
Expand All @@ -34,14 +35,14 @@ readme = "README.md"
license = "Apache-2.0"
repository = "https://github.com/FuelLabs/fuels-rs"
rust-version = "1.71.1"
version = "0.46.0"
version = "0.48.0"

[workspace.dependencies]
Inflector = "0.11.4"
async-trait = { version = "0.1.73", default-features = false }
bech32 = "0.9.1"
bytes = { version = "1.4.0", default-features = false }
chrono = "0.4.26"
chrono = "0.4.27"
elliptic-curve = { version = "0.13.5", default-features = false }
eth-keystore = "0.5.0"
fuel-abi-types = "0.3.0"
Expand All @@ -51,18 +52,19 @@ itertools = "0.11.0"
portpicker = "0.1.1"
proc-macro2 = "1.0.66"
quote = "1.0.32"
rand = { version = "0.8.5", default-features = false, features = ["std_rng", "getrandom"] }
rand = { version = "0.8.5", default-features = false, features = [
"std_rng",
"getrandom",
] }
regex = "1.9.3"
serde = { version = "1.0.183", default-features = false }
serde_json = "1.0.104"
serde_with = { version = "3.2.0", default-features = false }
sha2 = { version = "0.10.7", default-features = false }
strum = "0.25.0"
strum_macros = "0.25.2"
syn = "2.0.28"
tai64 = { version = "4.0.0", default-features = false }
tempfile = { version = "3.7.1", default-features = false }
thiserror = { version = "1.0.46", default-features = false }
thiserror = { version = "1.0.47", default-features = false }
tokio = { version = "1.31.0", default-features = false }
trybuild = "1.0.82"
which = { version = "4.4.0", default-features = false }
Expand All @@ -83,10 +85,10 @@ fuel-types = { version = "0.35.3", default-features = false }
fuel-vm = "0.35.3"

# Workspace projects
fuels = { version = "0.46.0", path = "./packages/fuels" }
fuels-accounts = { version = "0.46.0", path = "./packages/fuels-accounts", default-features = false }
fuels-code-gen = { version = "0.46.0", path = "./packages/fuels-code-gen", default-features = false }
fuels-core = { version = "0.46.0", path = "./packages/fuels-core", default-features = false }
fuels-macros = { version = "0.46.0", path = "./packages/fuels-macros", default-features = false }
fuels-programs = { version = "0.46.0", path = "./packages/fuels-programs", default-features = false }
fuels-test-helpers = { version = "0.46.0", path = "./packages/fuels-test-helpers", default-features = false }
fuels = { version = "0.48.0", path = "./packages/fuels" }
fuels-accounts = { version = "0.48.0", path = "./packages/fuels-accounts", default-features = false }
fuels-code-gen = { version = "0.48.0", path = "./packages/fuels-code-gen", default-features = false }
fuels-core = { version = "0.48.0", path = "./packages/fuels-core", default-features = false }
fuels-macros = { version = "0.48.0", path = "./packages/fuels-macros", default-features = false }
fuels-programs = { version = "0.48.0", path = "./packages/fuels-programs", default-features = false }
fuels-test-helpers = { version = "0.48.0", path = "./packages/fuels-test-helpers", default-features = false }
7 changes: 6 additions & 1 deletion docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [Running a short-lived Fuel node with the SDK](./connecting/short-lived.md)
- [Rocksdb](./connecting/rocksdb.md)
- [Querying the blockchain](./connecting/querying.md)
- [Retrying upon errors](./connecting/retrying.md)
- [Accounts](./accounts.md)
- [Managing wallets](./wallets/index.md)
- [Creating a wallet from a private key](./wallets/private-keys.md)
Expand All @@ -22,6 +23,7 @@
- [The `abigen!` macro](abigen/the-abigen-macro.md)
- [Deploying contracts](./deploying/index.md)
- [Configurable constants](./deploying/configurable-constants.md)
- [Storage slots](./deploying/storage-slots.md)
- [Interacting with contracts](./deploying/interacting-with-contracts.md)
- [The FuelVM Binary file](./deploying/the-fuelvm-binary-file.md)
- [Calling contracts](./calling-contracts/index.md)
Expand Down Expand Up @@ -54,6 +56,9 @@
- [B512](./types/B512.md)
- [EvmAddress](./types/evm_address.md)
- [Vectors](./types/vectors.md)
- [Codec](./codec/index.md)
- [Encoding](./codec/encoding.md)
- [Decoding](./codec/decoding.md)
- [API Reference](./reference.md)
- [Testing](./testing/index.md)
- [Testing basics](./testing/basics.md)
Expand All @@ -66,7 +71,7 @@
- [Debugging](./debugging/index.md)
- [The Function selector](./debugging/function-selector.md)
- [Glossary](./glossary.md)
- [Contributing](./contributing/contributing.md)
- [Contributing](./contributing/CONTRIBUTING.md)
- [Integration tests structure](./contributing/tests-structure.md)
- [Command Line Interfaces](./cli/index.md)
- [`fuels-abi-cli`](./cli/fuels-abi-cli.md)
2 changes: 1 addition & 1 deletion docs/src/abigen/the-abigen-macro.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where:
So, an `abigen!` which generates bindings for two contracts and one script looks like this:

```rust,ignore
{{#include ../../../examples/abigen/src/lib.rs:multiple_abigen_program_types}}
{{#include ../../../examples/macros/src/lib.rs:multiple_abigen_program_types}}
```

## How does the generated code look?
Expand Down
8 changes: 7 additions & 1 deletion docs/src/calling-contracts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ Here's an example. Suppose your Sway contract has two ABI methods called `initia

The example above uses all the default configurations and performs a simple contract call.

Next, we'll see how we can further configure the many different parameters in a contract call
Furthermore, if you need to separate submission from value retrieval for any reason, you can do so as follows:

```rust,ignore
{{#include ../../../examples/contracts/src/lib.rs:submit_response_contract}}
```

Next, we'll see how we can further configure the many different parameters in a contract call.
2 changes: 1 addition & 1 deletion docs/src/calling-contracts/low-level-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Your caller contract should call `std::low_level_call::call_with_function_select
{{#include ../../../packages/fuels/tests/contracts/low_level_caller/src/main.sw:low_level_call_contract}}
```

On the SDK side, you can construct an encoded function selector using the `fuels::core::fn_selector` macro, and encoded calldata using the `fuels::core::calldata` macro.
On the SDK side, you can construct an encoded function selector using the `fuels::core::fn_selector!` macro, and encoded calldata using the `fuels::core::calldata!` macro.

E.g. to call the following function on the target contract:

Expand Down
6 changes: 6 additions & 0 deletions docs/src/calling-contracts/multicalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Next, you provide the prepared calls to your `MultiContractCallHandler` and opti

> **Note:** any transaction parameters configured on separate contract calls are disregarded in favor of the parameters provided to `MultiContractCallHandler`.
Furthermore, if you need to separate submission from value retrieval for any reason, you can do so as follows:

```rust,ignore
{{#include ../../../examples/contracts/src/lib.rs:submit_response_multicontract}}
```

## Output values

To get the output values of the bundled calls, you need to provide explicit type annotations when saving the result of `call()` or `simulate()` to a variable:
Expand Down
6 changes: 1 addition & 5 deletions docs/src/calling-contracts/tx-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ You can configure these parameters by creating an instance of `TxParameters` and

<!-- This section should explain how to use the defauly tx params -->
<!-- tx_params_default:example:start -->
You can also use `TxParameters::default()` to use the default values:
You can also use `TxParameters::default()` to use the default values. If `gas_price` or `gas_limit` is set to `None`, the SDK will use the network's default value:
<!-- tx_params_default:example:end -->

```rust,ignore
{{#include ../../../packages/fuels-core/src/utils/constants.rs:default_tx_parameters}}
```

This way:

```rust,ignore
Expand Down
49 changes: 49 additions & 0 deletions docs/src/codec/decoding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Decoding

Be sure to read the [prerequisites](./index.md#prerequisites-for-decodingencoding) to decoding.

Decoding is done via the [`ABIDecoder`](https://docs.rs/fuels/latest/fuels/core/codec/struct.ABIDecoder.html):

```rust,ignore
{{#include ../../../examples/codec/src/lib.rs:decoding_example}}
```

First into a [`Token`](https://docs.rs/fuels/latest/fuels/types/enum.Token.html), then via the [`Tokenizable`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Tokenizable.html) trait, into the desired type.

If the type came from [`abigen!`](../abigen/index.md) (or uses the [`::fuels::macros::TryFrom`](https://docs.rs/fuels/latest/fuels/macros/derive.TryFrom.html) derivation) then you can also use `try_into` to convert bytes into a type that implements both [`Parameterize`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Parameterize.html) and [`Tokenizable`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Tokenizable.html):

```rust,ignore
{{#include ../../../examples/codec/src/lib.rs:decoding_example_try_into}}
```

Under the hood, [`try_from_bytes`](https://docs.rs/fuels/latest/fuels/core/codec/fn.try_from_bytes.html) is being called, which does what the preceding example did.

## Configuring the decoder

The decoder can be configured to limit its resource expenditure:

```rust,ignore
{{#include ../../../examples/codec/src/lib.rs:configuring_the_decoder}}
```

<!-- TODO: Add a link once a release is made -->
<!-- https://docs.rs/fuels/latest/fuels/core/codec/struct.DecoderConfig.html -->
For an explanation of each configuration value visit the `DecoderConfig`.

<!-- TODO: add a link once a release is made -->
<!-- https://docs.rs/fuels/latest/fuels/core/codec/struct.DecoderConfig.html -->
The default values for the `DecoderConfig` are:

```rust,ignore
{{#include ../../../packages/fuels-core/src/codec/abi_decoder.rs:default_decoder_config}}
```

## Configuring the decoder for contract/script calls

You can also configure the decoder used to decode the return value of the contract method:

```rust,ignore
{{#include ../../../examples/contracts/src/lib.rs:contract_decoder_config}}
```

The same method is available for script calls.
20 changes: 20 additions & 0 deletions docs/src/codec/encoding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Encoding

Be sure to read the [prerequisites](./index.md#prerequisites-for-decodingencoding) to encoding.

Encoding is done via the [`ABIEncoder`](https://docs.rs/fuels/latest/fuels/core/codec/struct.ABIEncoder.html):

```rust,ignore
{{#include ../../../examples/codec/src/lib.rs:encoding_example}}
```

Note that the return type of `encode` is `UnresolvedBytes`. The encoding cannot be finished until we know at which memory address this data is to be loaded. If you don't use heap types (`::std::vec::Vec`, `::fuels::types::Bytes`, `::std::string::String`), then you can safely `.resolve(0)` to get the encoded bytes.

There is also a shortcut-macro that can encode multiple types which implement [`Tokenizable`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Tokenizable.html):

```rust,ignore
{{#include ../../../examples/codec/src/lib.rs:encoding_example_w_macro}}
```

> Note:
> The above example will call `.resolve(0)`. Don't use it if you're encoding heap types.
45 changes: 45 additions & 0 deletions docs/src/codec/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Codec

Encoding and decoding are done as per [the fuel spec](https://specs.fuel.network/master/abi/argument-encoding.html). To this end, `fuels` makes use of the [ABIEncoder](https://docs.rs/fuels/latest/fuels/core/codec/struct.ABIEncoder.html) and the [ABIDecoder](https://docs.rs/fuels/latest/fuels/core/codec/struct.ABIDecoder.html).

## Prerequisites for decoding/encoding

To encode a type, you must first convert it into a [`Token`](https://docs.rs/fuels/latest/fuels/types/enum.Token.html). This is commonly done by implementing the [Tokenizable](https://docs.rs/fuels/latest/fuels/core/traits/trait.Tokenizable.html) trait.

To decode, you also need to provide a [`ParamType`](https://docs.rs/fuels/latest/fuels/types/param_types/enum.ParamType.html) describing the schema of the type in question. This is commonly done by implementing the [Parameterize](https://docs.rs/fuels/latest/fuels/core/traits/trait.Parameterize.html) trait.

All types generated by the [`abigen!`](../abigen/index.md) macro implement both the [`Tokenizable`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Tokenizable.html) and [`Parameterize`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Parameterize.html) traits.

`fuels` also contains implementations for:

- [`Tokenizable`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Tokenizable.html) for the `fuels`-owned types listed [here](https://docs.rs/fuels/latest/fuels/core/traits/trait.Tokenizable.html#implementors) as well as [for some foreign types](https://docs.rs/fuels/latest/fuels/core/traits/trait.Tokenizable.html#foreign-impls) (such as `u8`, `u16`, `std::vec::Vec<T: Tokenizable>`, etc.).
- [`Parameterize`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Parameterize.html) for the `fuels`-owned types listed [here](https://docs.rs/fuels/latest/fuels/core/traits/trait.Parameterize.html#implementors) as well as [for some foreign types](https://docs.rs/fuels/latest/fuels/core/traits/trait.Parameterize.html#foreign-impls) (such as `u8`, `u16`, `std::vec::Vec<T: Parameterize>`, etc.).

## Deriving the traits

Both [`Tokenizable`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Tokenizable.html) and [`Parameterize`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Parameterize.html) can be derived for `struct`s and `enum`s if all inner types implement the derived traits:

```rust,ignore
{{#include ../../../examples/macros/src/lib.rs:deriving_traits}}
```

> Note:
> Deriving [`Tokenizable`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Tokenizable.html) on `enum`s requires that all variants also implement [`Parameterize`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Parameterize.html).
### Tweaking the derivation

#### Changing the location of imports

The derived code expects that the `fuels` package is accessible through `::fuels`. If this is not the case then the derivation macro needs to be given the locations of `fuels::types` and `fuels::core`.

```rust,ignore
{{#include ../../../examples/macros/src/lib.rs:deriving_traits_paths}}
```

#### Generating no-std code

If you want `no-std` generated code:

```rust,ignore
{{#include ../../../examples/macros/src/lib.rs:deriving_traits_nostd}}
```
2 changes: 1 addition & 1 deletion docs/src/connecting/external-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ In the code example, we connected a new provider to the Testnet node and created

> **Note:** New wallets on the Testnet will not have any assets! They can be obtained by providing the wallet address to the faucet at
>
>[faucet-beta-3.fuel.network](https://faucet-beta-3.fuel.network)
>[faucet-beta-4.fuel.network](https://faucet-beta-4.fuel.network)
>
> Once the assets have been transferred to the wallet, you can reuse it in other tests by providing the private key!
>
Expand Down
Loading

0 comments on commit 65a5f9c

Please sign in to comment.