Skip to content

Commit

Permalink
Merge branch 'master' into oleksii/dynamic-supported-core-version
Browse files Browse the repository at this point in the history
  • Loading branch information
segfault-magnet authored Feb 1, 2024
2 parents c3810f0 + 1221632 commit e641a5c
Show file tree
Hide file tree
Showing 73 changed files with 1,478 additions and 489 deletions.
40 changes: 35 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ env:
FUEL_CORE_VERSION: 0.22.0
FUEL_CORE_PATCH_BRANCH:
RUST_VERSION: 1.74.0
FORC_VERSION: 0.48.0
FORC_VERSION: 0.49.1
FORC_PATCH_BRANCH: ""
FORC_PATCH_REVISION: ""

Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
# TODO: To be removed once https://github.com/FuelLabs/fuels-rs/issues/881 is unblocked.
- name: Build Sway test projects w type paths
run: forc build --terse --json-abi-with-callpaths
run: forc build --terse --error-on-warnings --json-abi-with-callpaths
working-directory: packages/fuels

- uses: actions/upload-artifact@v2
Expand All @@ -97,6 +97,25 @@ jobs:
!packages/fuels/tests/**/Forc.lock
!packages/fuels/tests/.gitignore
# TODO: To be removed once experimental encoding is the default
- name: Build Sway test projects w experimental logs
run: forc build --terse --error-on-warnings --json-abi-with-callpaths --experimental-new-encoding
working-directory: packages/fuels

- uses: actions/upload-artifact@v2
with:
retention-days: 2
name: sway-examples-w-experimental-logs
# cache only the sway build artifacts, skip all src files
path: |
packages/fuels/tests
!packages/fuels/tests/*.rs
!packages/fuels/tests/**/*.rs
!packages/fuels/tests/**/*.sw
!packages/fuels/tests/**/Forc.toml
!packages/fuels/tests/**/Forc.lock
!packages/fuels/tests/.gitignore
get-workspace-members:
runs-on: ubuntu-latest
outputs:
Expand Down Expand Up @@ -137,7 +156,7 @@ jobs:
toolchain: ${{ env.RUST_VERSION }}

- name: Publish crate check
uses: katyo/publish-crates@v2
uses: xgreenx/publish-crates@v1
with:
dry-run: true
check-repo: false
Expand Down Expand Up @@ -182,6 +201,11 @@ jobs:
args:
- command: check_doc_unresolved_links
args:
# TODO: To be removed once experimental encoding is the default
- command: test_experimental_logs
args:
download_sway_artifacts: sway-examples-w-experimental-logs
install_fuel_core: true
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand Down Expand Up @@ -218,8 +242,9 @@ jobs:
name: ${{ matrix.download_sway_artifacts }}
path: packages/fuels/tests/

# TODO: `test_experimental_logs` to be removed once experimental encoding is the default.
- name: Install nextest
if: ${{ matrix.cargo_command == 'nextest' }}
if: ${{ matrix.cargo_command == 'nextest' || matrix.command == 'test_experimental_logs' }}
uses: taiki-e/install-action@nextest

- name: Install cargo-machete
Expand Down Expand Up @@ -257,6 +282,11 @@ jobs:
run: |
! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to"
# TODO: To be removed once experimental encoding is the default.
- name: Test experimental logs
if: ${{ matrix.command == 'test_experimental_logs' }}
run: RUSTFLAGS='--cfg experimental' cargo nextest run --test logs

publish:
needs:
- cargo-verifications
Expand All @@ -279,7 +309,7 @@ jobs:
mv ./dasel /usr/local/bin/dasel
./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} Cargo.toml
- name: Publish crate
uses: katyo/publish-crates@v2
uses: xgreenx/publish-crates@v1
with:
publish-delay: 30000
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ readme = "README.md"
license = "Apache-2.0"
repository = "https://github.com/FuelLabs/fuels-rs"
rust-version = "1.74.0"
version = "0.54.0"
version = "0.55.0"

[workspace.dependencies]
Inflector = "0.11.4"
Expand Down Expand Up @@ -89,10 +89,10 @@ fuel-types = { version = "0.43.1" }
fuel-vm = { version = "0.43.1" }

# Workspace projects
fuels = { version = "0.54.0", path = "./packages/fuels" }
fuels-accounts = { version = "0.54.0", path = "./packages/fuels-accounts", default-features = false }
fuels-code-gen = { version = "0.54.0", path = "./packages/fuels-code-gen", default-features = false }
fuels-core = { version = "0.54.0", path = "./packages/fuels-core", default-features = false }
fuels-macros = { version = "0.54.0", path = "./packages/fuels-macros", default-features = false }
fuels-programs = { version = "0.54.0", path = "./packages/fuels-programs", default-features = false }
fuels-test-helpers = { version = "0.54.0", path = "./packages/fuels-test-helpers", default-features = false }
fuels = { version = "0.55.0", path = "./packages/fuels" }
fuels-accounts = { version = "0.55.0", path = "./packages/fuels-accounts", default-features = false }
fuels-code-gen = { version = "0.55.0", path = "./packages/fuels-code-gen", default-features = false }
fuels-core = { version = "0.55.0", path = "./packages/fuels-core", default-features = false }
fuels-macros = { version = "0.55.0", path = "./packages/fuels-macros", default-features = false }
fuels-programs = { version = "0.55.0", path = "./packages/fuels-programs", default-features = false }
fuels-test-helpers = { version = "0.55.0", path = "./packages/fuels-test-helpers", default-features = false }
4 changes: 2 additions & 2 deletions docs/src/connecting/short-lived.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ let wallet = launch_provider_and_get_wallet().await?;
The `fuel-core-lib` feature allows us to run a `fuel-core` node without installing the `fuel-core` binary on the local machine. Using the `fuel-core-lib` feature flag entails downloading all the dependencies needed to run the fuel-core node.

```rust,ignore
fuels = { version = "0.54.0", features = ["fuel-core-lib"] }
fuels = { version = "0.55.0", features = ["fuel-core-lib"] }
```

### RocksDB

The `rocksdb` is an additional feature that, when combined with `fuel-core-lib`, provides persistent storage capabilities while using `fuel-core` as a library.

```rust,ignore
fuels = { version = "0.54.0", features = ["rocksdb"] }
fuels = { version = "0.55.0", features = ["rocksdb"] }
```
18 changes: 15 additions & 3 deletions docs/src/custom-transactions/transaction-builders.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,22 @@ We combine all of the inputs and outputs and set them on the builder:
{{#include ../../../examples/cookbook/src/lib.rs:custom_tx_io}}
```

As we have used coins that require a signature, we sign the transaction builder with:
As we have used coins that require a signature, we have to add the signer to the transaction builder with:

```rust,ignore
{{#include ../../../examples/cookbook/src/lib.rs:custom_tx_sign}}
{{#include ../../../examples/cookbook/src/lib.rs:custom_tx_add_signer}}
```

> **Note** The signature is not created until the transaction is finalized with `build(&provider)`
We need to do one more thing before we stop thinking about transaction inputs. Executing the transaction also incurs a fee that is paid with the base asset. Our base asset inputs need to be large enough so that the total amount covers the transaction fee and any other operations we are doing. The Account trait lets us use `adjust_for_fee()` for adjusting the transaction inputs if needed to cover the fee. The second argument to `adjust_for_fee()` is the total amount of the base asset that we expect our transaction to spend regardless of fees. In our case, this is the **ask_amount** we are transferring to the predicate.
We need to do one more thing before we stop thinking about transaction inputs. Executing the transaction also incurs a fee that is paid with the base asset. Our base asset inputs need to be large enough so that the total amount covers the transaction fee and any other operations we are doing. The `Account` trait lets us use `adjust_for_fee()` for adjusting the transaction inputs if needed to cover the fee. The second argument to `adjust_for_fee()` is the total amount of the base asset that we expect our transaction to spend regardless of fees. In our case, this is the **ask_amount** we are transferring to the predicate.

```rust,ignore
{{#include ../../../examples/cookbook/src/lib.rs:custom_tx_adjust}}
```

> **Note** It is recommended to add signers before calling `adjust_for_fee()` as the estimation will include the size of the witnesses.
We can also define transaction policies. For example, we can limit the gas price by doing the following:

```rust,ignore
Expand All @@ -83,3 +85,13 @@ Finally, we verify the transaction succeeded and that the cold storage indeed ho
```rust,ignore
{{#include ../../../examples/cookbook/src/lib.rs:custom_tx_verify}}
```

## Building a transaction without signatures

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}}
```

> **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.
2 changes: 1 addition & 1 deletion docs/src/types/address.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `Address`

Like `Bytes32`, `Address` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuel-types}}/fuel_types/struct.Address.html)).
Like `Bytes32`, `Address` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/latest/fuel_types/struct.Address.html)).

These are the main ways of creating an `Address`:

Expand Down
2 changes: 1 addition & 1 deletion docs/src/types/bytes32.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ These are the main ways of creating a `Bytes32`:
{{#include ../../../examples/types/src/lib.rs:bytes32_format}}
```

For a full list of implemented methods and traits, see the [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuel-types}}/fuel_types/struct.Bytes32.html).
For a full list of implemented methods and traits, see the [fuel-types documentation](https://docs.rs/fuel-types/latest/fuel_types/struct.Bytes32.html).

> **Note:** In Fuel, there's a special type called `b256`, which is similar to `Bytes32`; also used to represent hashes, and it holds a 256-bit value. In Rust, through the SDK, this is represented as `Bits256(value)` where `value` is a `[u8; 32]`. If your contract method takes a `b256` as input, all you need to do is pass a `Bits256([u8; 32])` when calling it from the SDK.
20 changes: 14 additions & 6 deletions docs/src/wallets/signing.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
# Signing

Once you've instantiated your wallet in an unlocked state using one of the previously discussed methods, you can sign a message with `wallet.sign_message`. Below is a full example of how to sign and recover a message.
Once you've instantiated your wallet in an unlocked state using one of the previously discussed methods, you can sign a message with `wallet.sign`. Below is a full example of how to sign and recover a message.

```rust,ignore
{{#include ../../../packages/fuels-accounts/src/account.rs:sign_message}}
```

## Signing a transaction
## Adding `Signers` to a transaction builder

Every signed resource in the inputs needs to have a witness index that points to a valid witness. Changing the witness index inside an input will change the transaction ID. This means that we need to set all witness indexes before finally signing the transaction. Previously, the user had to make sure that the witness indexes and the order of the witnesses are correct. To automate this process, the SDK will keep track of the signatures in the transaction builder and resolve the final transaction automatically. This is done by storing the secret keys of all signers until the final transaction is built.
Every signed resource in the inputs needs to have a witness index that points to a valid witness. Changing the witness index inside an input will change the transaction ID. This means that we need to set all witness indexes before finally signing the transaction. Previously, the user had to make sure that the witness indexes and the order of the witnesses are correct. To automate this process, the SDK will keep track of the signers in the transaction builder and resolve the final transaction automatically. This is done by storing signers until the final transaction is built.

To sign a _transaction builder_ use the `wallet.sign_transaction`. Below is a full example of how to create a transaction and sign it.
Below is a full example of how to create a transaction builder and add signers to it.

> Note: When you sign a transaction builder the secret key is stored inside it and will not be resolved until you call `build()`!
> Note: When you add a `Signer` to a transaction builder, the signer is stored inside it and the transaction will not be resolved until you call `build()`!
```rust,ignore
{{#include ../../../packages/fuels-accounts/src/account.rs:sign_tx}}
{{#include ../../../packages/fuels-accounts/src/account.rs:sign_tb}}
```

## Signing a built transaction

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}}
```
2 changes: 1 addition & 1 deletion examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ mod tests {
// customize the builder...

wallet.adjust_for_fee(&mut tb, 0).await?;
wallet.sign_transaction(&mut tb);
tb.add_signer(wallet.clone())?;

let tx = tb.build(provider).await?;

Expand Down
13 changes: 6 additions & 7 deletions examples/cookbook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ mod tests {
use std::str::FromStr;

use fuels::{
accounts::{
predicate::Predicate, wallet::WalletUnlocked, Account, Signer, ViewOnlyAccount,
},
accounts::{predicate::Predicate, wallet::WalletUnlocked, Account, ViewOnlyAccount},
core::constants::BASE_ASSET_ID,
prelude::Result,
test_helpers::{setup_single_asset_coins, setup_test_provider},
Expand Down Expand Up @@ -191,7 +189,8 @@ mod tests {
// ANCHOR: transfer_multiple_transaction
let mut tb =
ScriptTransactionBuilder::prepare_transfer(inputs, outputs, TxPolicies::default());
wallet_1.sign_transaction(&mut tb);
tb.add_signer(wallet_1.clone())?;

let tx = tb.build(&provider).await?;

provider.send_transaction_and_await_commit(tx).await?;
Expand Down Expand Up @@ -296,9 +295,9 @@ mod tests {
let mut tb = tb.with_inputs(inputs).with_outputs(outputs);
// ANCHOR_END: custom_tx_io

// ANCHOR: custom_tx_sign
hot_wallet.sign_transaction(&mut tb);
// ANCHOR_END: custom_tx_sign
// ANCHOR: custom_tx_add_signer
tb.add_signer(hot_wallet.clone())?;
// ANCHOR_END: custom_tx_add_signer

// ANCHOR: custom_tx_adjust
hot_wallet.adjust_for_fee(&mut tb, 100).await?;
Expand Down
23 changes: 5 additions & 18 deletions examples/predicates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
mod tests {
use fuels::{
accounts::{predicate::Predicate, Account},
crypto::{Message, SecretKey},
prelude::*,
types::B512,
};

#[tokio::test]
async fn predicate_example() -> Result<()> {
use fuels::accounts::fuel_crypto::SecretKey;

// ANCHOR: predicate_wallets
let secret_key1: SecretKey =
"0x862512a2363db2b3a375c0d4bbbd27172180d89f23f2e259bac850ab02619301"
Expand Down Expand Up @@ -53,22 +52,10 @@ mod tests {
});
// ANCHOR_END: predicate_coins

let data_to_sign = [0; 32];
let signature1: B512 = wallet
.sign_message(data_to_sign)
.await?
.as_ref()
.try_into()?;
let signature2: B512 = wallet2
.sign_message(data_to_sign)
.await?
.as_ref()
.try_into()?;
let signature3: B512 = wallet3
.sign_message(data_to_sign)
.await?
.as_ref()
.try_into()?;
let data_to_sign = Message::new([0; 32]);
let signature1: B512 = wallet.sign(data_to_sign).await?.as_ref().try_into()?;
let signature2: B512 = wallet2.sign(data_to_sign).await?.as_ref().try_into()?;
let signature3: B512 = wallet3.sign(data_to_sign).await?.as_ref().try_into()?;

let signatures = [signature1, signature2, signature3];

Expand Down
2 changes: 1 addition & 1 deletion examples/providers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod tests {
// ANCHOR: connect_to_testnet
use std::str::FromStr;

use fuels::{accounts::fuel_crypto::SecretKey, prelude::*};
use fuels::{crypto::SecretKey, prelude::*};

// Create a provider pointing to the testnet.
// This example will not work as the testnet does not support the new version of fuel-core
Expand Down
2 changes: 1 addition & 1 deletion examples/wallets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod tests {
// ANCHOR: create_wallet_from_secret_key
use std::str::FromStr;

use fuels::{accounts::fuel_crypto::SecretKey, prelude::*};
use fuels::{crypto::SecretKey, prelude::*};

// Use the test helper to setup a test provider.
let provider = setup_test_provider(vec![], vec![], None, None).await?;
Expand Down
Loading

0 comments on commit e641a5c

Please sign in to comment.