Skip to content

Commit

Permalink
fix doc links
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Sagdati committed May 11, 2024
1 parent 0024c6f commit ab94801
Show file tree
Hide file tree
Showing 25 changed files with 46 additions and 46 deletions.
4 changes: 2 additions & 2 deletions docs/src/calling-contracts/call-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can use these to forward coins to a contract. You can configure these parame
For instance, suppose the following contract that uses Sway's `msg_amount()` to return the amount sent in that transaction.

```rust,ignore
{{#include ../../../packages/fuels/tests/contracts/contract_test/src/main.sw:msg_amount}}
{{#include ../../../e2e/sway/contracts/contract_test/src/main.sw:msg_amount}}
```

Then, in Rust, after setting up and deploying the above contract, you can configure the amount being sent in the transaction like this:
Expand All @@ -31,7 +31,7 @@ Then, in Rust, after setting up and deploying the above contract, you can config
In the following example, we try to forward an amount of `100` of the base asset to `non_payable`. As its name suggests, `non_payable` isn't annotated with `#[payable]` in the contract code. Passing `CallParameters` with an amount other than `0` leads to an error:

```rust,ignore
{{#include ../../../packages/fuels/tests/contracts.rs:non_payable_params}}
{{#include ../../../e2e/tests/contracts.rs:non_payable_params}}
```

> **Note:** forwarding gas to a contract call is always possible, regardless of the contract method being non-payable.
Expand Down
6 changes: 3 additions & 3 deletions docs/src/calling-contracts/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ Whenever you log a value within a contract method, the resulting log entry is ad
Consider the following contract method:

```rust,ignore
{{#include ../../../packages/fuels/tests/logs/contract_logs/src/main.sw:produce_logs}}
{{#include ../../../e2e/sway/logs/contract_logs/src/main.sw:produce_logs}}
```

You can access the logged values in Rust by calling `decode_logs_with_type::<T>` from a `FuelCallResponse`, where `T` is the type of the logged variables you want to retrieve. The result will be a `Vec<T>`:

```rust,ignore
{{#include ../../../packages/fuels/tests/logs.rs:produce_logs}}
{{#include ../../../e2e/tests/logs.rs:produce_logs}}
```

You can use the `decode_logs()` function to retrieve a `LogResult` struct containing a `results` field that is a vector of `Result<String>` values representing the success or failure of decoding each log.

```rust, ignore
{{#include ../../../packages/fuels/tests/logs.rs:decode_logs}}
{{#include ../../../e2e/tests/logs.rs:decode_logs}}
```

Due to possible performance hits, it is not recommended to use `decode_logs()` outside of a debugging scenario.
Expand Down
4 changes: 2 additions & 2 deletions docs/src/calling-contracts/low-level-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Your caller contract should call `std::low_level_call::call_with_function_select
- `std::low_level_call::CallParams`

```rust,ignore
{{#include ../../../packages/fuels/tests/contracts/low_level_caller/src/main.sw:low_level_call_contract}}
{{#include ../../../e2e/sway/contracts/low_level_caller/src/main.sw:low_level_call_contract}}
```

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

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

```rust,ignore
{{#include ../../../packages/fuels/tests/contracts/contract_test/src/main.sw:low_level_call}}
{{#include ../../../e2e/sway/contracts/contract_test/src/main.sw:low_level_call}}
```

you would construct the function selector and the calldata as such, and provide them to the caller contract (like the one above):
Expand Down
4 changes: 2 additions & 2 deletions docs/src/calling-contracts/other-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ If your contract method is calling other contracts you will have to add the appr
`with_contracts(&[&contract_instance, ...])` 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.

```rust,ignore
{{#include ../../../packages/fuels/tests/contracts.rs:external_contract}}
{{#include ../../../e2e/tests/contracts.rs:external_contract}}
```

If however, you do not need do decode logs or you do not have a contract instance that was generated using the `abigen` macro you can use `with_contract_ids(&[&contract_id, ...])` and provide the required contract ids.

```rust,ignore
{{#include ../../../packages/fuels/tests/contracts.rs:external_contract_ids}}
{{#include ../../../e2e/tests/contracts.rs:external_contract_ids}}
```
2 changes: 1 addition & 1 deletion docs/src/calling-contracts/variable-outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Sometimes, the contract you call might transfer funds to a specific address, dep
Let's say you deployed a contract with the following method:

```rust,ignore
{{#include ../../../packages/fuels/tests/contracts/token_ops/src/main.sw:variable_outputs}}
{{#include ../../../e2e/sway/contracts/token_ops/src/main.sw:variable_outputs}}
```

When calling `transfer_coins_to_output` with the SDK, you can specify the number of variable outputs by chaining `append_variable_outputs(amount)` to your call. Like this:
Expand Down
2 changes: 1 addition & 1 deletion docs/src/cookbook/deposit-and-withdraw.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Consider the following contract:

```rust,ignore
{{#include ../../../packages/fuels/tests/contracts/liquidity_pool/src/main.sw}}
{{#include ../../../e2e/sway/contracts/liquidity_pool/src/main.sw}}
```

As its name suggests, it represents a simplified example of a liquidity pool contract. The method `deposit()` expects you to supply an arbitrary amount of the `BASE_TOKEN`. As a result, it mints double the amount of the liquidity asset to the calling address. Analogously, if you call `withdraw()` supplying it with the liquidity asset, it will transfer half that amount of the `BASE_TOKEN` back to the calling address except for deducting it from the contract balance instead of minting it.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/custom-transactions/custom-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ When preparing a contract call via `ContractCallHandler` or a script call via `S
## Custom script call

```rust,ignore
{{#include ../../../packages/fuels/tests/scripts.rs:script_call_tb}}
{{#include ../../../e2e/tests/scripts.rs:script_call_tb}}
```
2 changes: 1 addition & 1 deletion docs/src/custom-transactions/transaction-builders.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Finally, we verify the transaction succeeded and that the cold storage indeed ho
If you need to build the transaction without signatures, which is useful when estimating transaction costs or simulations, you can use the `build_without_signatures(&provider)` method and later sign the built transaction.

```rust,ignore
{{#include ../../../packages/fuels/tests/contracts.rs:tb_build_without_signatures}}
{{#include ../../../e2e/tests/contracts.rs:tb_build_without_signatures}}
```

> **Note** In contrast to adding signers to a transaction builder, when signing a built transaction, you must ensure that the order of signatures matches the order of signed inputs. Multiple signed inputs with the same owner will have the same witness index.
4 changes: 2 additions & 2 deletions docs/src/deploying/configurable-constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
In Sway, you can define `configurable` constants which can be changed during the contract deployment in the SDK. Here is an example how the constants are defined.

```rust,ignore
{{#include ../../../packages/fuels/tests/contracts/configurables/src/main.sw}}
{{#include ../../../e2e/sway/contracts/configurables/src/main.sw}}
```

Each of the configurable constants will get a dedicated `with` method in the SDK. For example, the constant `STR_4` will get the `with_STR_4` method which accepts the same type as defined in the contract code. Below is an example where we chain several `with` methods and deploy the contract with the new constants.

```rust,ignore
{{#include ../../../packages/fuels/tests/configurables.rs:contract_configurables}}
{{#include ../../../e2e/tests/configurables.rs:contract_configurables}}
```
2 changes: 1 addition & 1 deletion docs/src/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ use fuels::prelude::*;

## The Fuel Rust SDK source code

Another way to experience the SDK is to look at the source code. The `packages/fuels/tests/` folder is full of integration tests that go through almost all aspects of the SDK.
Another way to experience the SDK is to look at the source code. The `e2e/tests/` folder is full of integration tests that go through almost all aspects of the SDK.

> **Note** Before running the tests, we need to build all the Sway test projects. The file `packages/fuels/Forc.toml` contains a `[workspace], which members are the paths to all integration tests.
> To build these tests, run the following command:
Expand Down
6 changes: 3 additions & 3 deletions docs/src/predicates/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Predicates, in Sway, are programs that return a Boolean value and do not have an
Let's consider the following predicate example:

```rust,ignore
{{#include ../../../packages/fuels/tests/predicates/basic_predicate/src/main.sw}}
{{#include ../../../e2e/sway/predicates/basic_predicate/src/main.sw}}
```

We will look at a complete example of using the SDK to send and receive funds from a predicate.
Expand Down Expand Up @@ -46,10 +46,10 @@ Then we can transfer assets owned by the predicate via the [Account](../accounts
Same as contracts and scripts, you can define configurable constants in `predicates`, which can be changed during the predicate execution. Here is an example of how the constants are defined.

```rust,ignore
{{#include ../../../packages/fuels/tests/predicates/predicate_configurables/src/main.sw:predicate_configurables}}
{{#include ../../../e2e/sway/predicates/predicate_configurables/src/main.sw:predicate_configurables}}
```

Each configurable constant will get a dedicated `with` method in the SDK. For example, the constant `U8` will get the `with_U8` method which accepts the same type defined in sway. Below is an example where we chain several `with` methods and update the predicate with the new constants.

```rust,ignore
{{#include ../../../packages/fuels/tests/predicates.rs:predicate_configurables}}
{{#include ../../../e2e/tests/predicates.rs:predicate_configurables}}
2 changes: 1 addition & 1 deletion docs/src/predicates/send-spend-predicate.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This is a more involved example where the predicate accepts three signatures and matches them to three predefined public keys. The `ec_recover_address` function is used to recover the public key from the signatures. If two of the three extracted public keys match the predefined public keys, the funds can be spent. Note that the signature order has to match the order of the predefined public keys.

```rust,ignore
{{#include ../../../packages/fuels/tests/predicates/signatures/src/main.sw}}
{{#include ../../../e2e/sway/predicates/signatures/src/main.sw}}
```

Let's use the SDK to interact with the predicate. First, let's create three wallets with specific keys. Their hashed public keys are already hard-coded in the predicate. Then we create the receiver wallet, which we will use to spend the predicate funds.
Expand Down
16 changes: 8 additions & 8 deletions docs/src/running-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
You can run a script using its JSON-ABI and the path to its binary file. You can run the scripts with arguments. For this, you have to use the `abigen!` macro seen [previously](./abigen/the-abigen-macro.md).

````rust,ignore
{{#include ../../packages/fuels/tests/scripts.rs:script_with_arguments}}
{{#include ../../e2e/tests/scripts.rs:script_with_arguments}}
````

Furthermore, if you need to separate submission from value retrieval for any reason, you can do so as follows:

```rust,ignore
{{#include ../../packages/fuels/tests/scripts.rs:submit_response_script}}
{{#include ../../e2e/tests/scripts.rs:submit_response_script}}
```

## Running scripts with transaction policies

The method for passing transaction policies is the same as [with contracts](./calling-contracts/tx-policies.md). As a reminder, the workflow would look like this:

```rust,ignore
{{#include ../../packages/fuels/tests/scripts.rs:script_with_tx_policies}}
{{#include ../../e2e/tests/scripts.rs:script_with_tx_policies}}
```

## Logs

Script calls provide the same logging functions, `decode_logs()` and `decode_logs_with_type<T>()`, as contract calls. As a reminder, the workflow looks like this:

```rust,ignore
{{#include ../../packages/fuels/tests/logs.rs:script_logs}}
{{#include ../../e2e/tests/logs.rs:script_logs}}
```

## Calling contracts from scripts
Expand All @@ -35,24 +35,24 @@ Scripts use the same interfaces for setting external contracts as [contract meth
Below is an example that uses `with_contracts(&[&contract_instance, ...])`.

```rust,ignore
{{#include ../../packages/fuels/tests/logs.rs:external_contract}}
{{#include ../../e2e/tests/logs.rs:external_contract}}
```

And this is an example that uses `with_contract_ids(&[&contract_id, ...])`.

```rust,ignore
{{#include ../../packages/fuels/tests/logs.rs:external_contract_ids}}
{{#include ../../e2e/tests/logs.rs:external_contract_ids}}
```

## Configurable constants

Same as contracts, you can define `configurable` constants in `scripts` which can be changed during the script execution. Here is an example how the constants are defined.

```rust,ignore
{{#include ../../packages/fuels/tests/scripts/script_configurables/src/main.sw}}
{{#include ../../e2e/sway/scripts/script_configurables/src/main.sw}}
```

Each configurable constant will get a dedicated `with` method in the SDK. For example, the constant `STR_4` will get the `with_STR_4` method which accepts the same type defined in sway. Below is an example where we chain several `with` methods and execute the script with the new constants.

```rust,ignore
{{#include ../../packages/fuels/tests/configurables.rs:script_configurables}}
{{#include ../../e2e/tests/configurables.rs:script_configurables}}
4 changes: 2 additions & 2 deletions docs/src/testing/chains.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ You can use `produce_blocks` to help achieve an arbitrary block height; this is
> **Note**: For the `produce_blocks` API to work, it is imperative to have `manual_blocks_enabled = true` in the config for the running node. See example below.
````rust,ignore
{{#include ../../../packages/fuels/tests/providers.rs:use_produce_blocks_to_increase_block_height}}
{{#include ../../../e2e/tests/providers.rs:use_produce_blocks_to_increase_block_height}}
````

You can also set a custom block time as the second, optional argument. Here is an example:

````rust,ignore
{{#include ../../../packages/fuels/tests/providers.rs:use_produce_blocks_custom_time}}
{{#include ../../../e2e/tests/providers.rs:use_produce_blocks_custom_time}}
````
4 changes: 2 additions & 2 deletions docs/src/testing/the-setup-program-test-macro.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ The setup code that you have seen in previous sections gets reduced to:
> **Note** The same contract can be deployed several times as the macro deploys the contracts with salt. You can also deploy different contracts to the same provider by referencing the same wallet in the `Deploy` command.
```rust,ignore
{{#include ../../../packages/fuels/tests/contracts.rs:contract_setup_macro_multi}}
{{#include ../../../e2e/tests/contracts.rs:contract_setup_macro_multi}}
```

In this example, three contracts are deployed on the same provider using the `wallet` generated by the `Wallets` command. The second and third macros use the same contract but have different IDs because of the deployment with salt. Both of them can call the first contract by using their ID.

In addition, you can manually create the `wallet` variable and then use it inside the macro. This is useful if you want to create custom wallets or providers but still want to use the macro to reduce boilerplate code. Below is an example of this approach.

```rust,ignore
{{#include ../../../packages/fuels/tests/contracts.rs:contract_setup_macro_manual_wallet}}
{{#include ../../../e2e/tests/contracts.rs:contract_setup_macro_manual_wallet}}
```
2 changes: 1 addition & 1 deletion docs/src/types/B512.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ In the Rust SDK, the `B512` definition matches the Sway standard library type wi
Here's an example:

```rust,ignore
{{#include ../../../packages/fuels/tests/types_contracts.rs:b512_example}}
{{#include ../../../e2e/tests/types_contracts.rs:b512_example}}
```
2 changes: 1 addition & 1 deletion docs/src/types/bits256.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ In Fuel, a type called `b256` represents hashes and holds a 256-bit value. The R
Here's an example:

```rust,ignore
{{#include ../../../packages/fuels/tests/types_contracts.rs:256_arg}}
{{#include ../../../e2e/tests/types_contracts.rs:256_arg}}
```

If you have a hexadecimal value as a string and wish to convert it to `Bits256`, you may do so with `from_hex_str`:
Expand Down
2 changes: 1 addition & 1 deletion docs/src/types/bytes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
In Fuel, a type called `Bytes` represents a collection of tightly-packed bytes. The Rust SDK represents `Bytes` as `Bytes(Vec<u8>)`. Here's an example of using `Bytes` in a contract call:

```rust,ignore
{{#include ../../../packages/fuels/tests/types_contracts.rs:bytes_arg}}
{{#include ../../../e2e/tests/types_contracts.rs:bytes_arg}}
```

If you have a hexadecimal value as a string and wish to convert it to `Bytes`, you may do so with `from_hex_str`:
Expand Down
4 changes: 2 additions & 2 deletions docs/src/types/conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Convert a hex string to a `ContractId`:
Convert a contract instance to a `ContractId`:

```rust,ignore
{{#include ../../../packages/fuels/tests/logs.rs:instance_to_contract_id}}
{{#include ../../../e2e/tests/logs.rs:instance_to_contract_id}}
```

## Convert to `Identity`
Expand Down Expand Up @@ -202,7 +202,7 @@ Convert a string to `Bytes`:
Convert two hex strings to `B512`:

```rust,ignore
{{#include ../../../packages/fuels/tests/types_contracts.rs:b512_example}}
{{#include ../../../e2e/tests/types_contracts.rs:b512_example}}
```

## Convert to `EvmAddress`
Expand Down
4 changes: 2 additions & 2 deletions docs/src/types/custom_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CounterConfig {
After using the `abigen!` macro, `CounterConfig` will be accessible in your Rust file! Here's an example:

```rust,ignore
{{#include ../../../packages/fuels/tests/types_contracts.rs:struct_generation}}
{{#include ../../../e2e/tests/types_contracts.rs:struct_generation}}
```

You can freely use your custom types (structs or enums) within this scope. That also means passing custom types to functions and receiving custom types from function calls.
Expand Down Expand Up @@ -57,7 +57,7 @@ impl MyContract for Contract {
Your Rust code would look like this:

```rust,ignore
{{#include ../../../packages/fuels/tests/types_contracts.rs:generic}}
{{#include ../../../e2e/tests/types_contracts.rs:generic}}
```

### Unused generic type parameters
Expand Down
2 changes: 1 addition & 1 deletion docs/src/types/evm_address.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ In the Rust SDK, Ethereum Virtual Machine (EVM) addresses can be represented wit
Here's an example:

```rust,ignore
{{#include ../../../packages/fuels/tests/types_contracts.rs:evm_address_arg}}
{{#include ../../../e2e/tests/types_contracts.rs:evm_address_arg}}
```

> **Note:** when creating an `EvmAddress` from `Bits256`, the first 12 bytes will be cleared because an EVM address is only 20 bytes long.
2 changes: 1 addition & 1 deletion docs/src/types/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ To make working with `SizedAsciiString`s easier, you can use `try_into()` to con
If your contract's method takes and returns, for instance, a Sway's `str[23]`. When using the SDK, this method will take and return a `SizedAsciiString<23>`, and you can pass a string to it like this:

```rust,ignore
{{#include ../../../packages/fuels/tests/types_contracts.rs:contract_takes_string}}
{{#include ../../../e2e/tests/types_contracts.rs:contract_takes_string}}
```
4 changes: 2 additions & 2 deletions docs/src/types/vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
You can pass a Rust `std::vec::Vec` into your contract method transparently. The following code calls a Sway contract method which accepts a `Vec<SomeStruct<u32>>`.

```rust,ignore
{{#include ../../../packages/fuels/tests/types_contracts.rs:passing_in_vec}}
{{#include ../../../e2e/tests/types_contracts.rs:passing_in_vec}}
```

You can use a vector just like you would use any other type -- e.g. a `[Vec<u32>; 2]` or a `SomeStruct<Vec<Bits256>>` etc.
Expand All @@ -15,7 +15,7 @@ You can use a vector just like you would use any other type -- e.g. a `[Vec<u32>
Returning vectors from contract methods is supported transparently, with the caveat that you cannot have them nested inside another type. This limitation is temporary.

```rust,ignore
{{#include ../../../packages/fuels/tests/types_contracts.rs:returning_vec}}
{{#include ../../../e2e/tests/types_contracts.rs:returning_vec}}
```

> **Note: you can still interact with contracts containing methods that return vectors nested inside another type, just not interact with the methods themselves**
2 changes: 1 addition & 1 deletion docs/src/wallets/signing.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Below is a full example of how to create a transaction builder and add signers t
If you have a built transaction and want to add a signature, you can use the `sign_with` method.

```rust,ignore
{{#include ../../../packages/fuels/tests/contracts.rs:tx_sign_with}}
{{#include ../../../e2e/tests/contracts.rs:tx_sign_with}}
```
Loading

0 comments on commit ab94801

Please sign in to comment.