Skip to content

Commit

Permalink
deps: upgrade fuel-core and fuel-vm crates versions (#997)
Browse files Browse the repository at this point in the history
This PR is here to adapt the SDK to :
- `[email protected]` 
- `[email protected]`

---------

Co-authored-by: green <[email protected]>
Co-authored-by: Hannes Karppila <[email protected]>
Co-authored-by: Ahmed Sagdati <[email protected]>
Co-authored-by: Halil Beglerović <[email protected]>
  • Loading branch information
5 people authored Jul 17, 2023
1 parent e3ddd07 commit 6c7e7a0
Show file tree
Hide file tree
Showing 31 changed files with 264 additions and 249 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ env:
CARGO_TERM_COLOR: always
DASEL_VERSION: https://github.com/TomWright/dasel/releases/download/v1.24.3/dasel_linux_amd64
RUSTFLAGS: "-D warnings"
FUEL_CORE_VERSION: 0.18.1
RUST_VERSION: 1.68.0
FORC_VERSION: 0.40.0
FUEL_CORE_VERSION: 0.19.1
RUST_VERSION: 1.70.0
FORC_VERSION: 0.40.1
FORC_PATCH_BRANCH: ""
FORC_PATCH_REVISION: ""

Expand Down
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ homepage = "https://fuel.network/"
readme = "README.md"
license = "Apache-2.0"
repository = "https://github.com/FuelLabs/fuels-rs"
rust-version = "1.68.0"
rust-version = "1.70.0"
version = "0.43.0"

[workspace.dependencies]
Expand All @@ -45,17 +45,17 @@ chrono = "0.4.24"
elliptic-curve = { version = "0.13.4", default-features = false }
eth-keystore = "0.5.0"
fuel-abi-types = "0.3.0"
fuel-asm = "0.31.1"
fuel-core = { version = "0.18.2", default-features = false }
fuel-core-chain-config = { version = "0.18.2", default-features = false }
fuel-core-client = { version = "0.18.2", default-features = false }
fuel-core-types = { version = "0.18.2", default-features = false }
fuel-crypto = "0.31.1"
fuel-merkle = "0.31.1"
fuel-storage = "0.31.1"
fuel-tx = "0.31.1"
fuel-types = { version = "0.31.1", default-features = false }
fuel-vm = "0.31.2"
fuel-core = { version = "0.19.1", default-features = false }
fuel-core-chain-config = { version = "0.19.1", default-features = false }
fuel-core-client = { version = "0.19.1", default-features = false }
fuel-core-types = { version = "0.19.1", default-features = false }
fuel-asm = "0.34.0"
fuel-crypto = "0.34.0"
fuel-merkle = "0.34.0"
fuel-storage = "0.34.0"
fuel-tx = "0.34.0"
fuel-types = { version = "0.34.0", default-features = false }
fuel-vm = "0.34.0"
fuels = { version = "0.43.0", path = "./packages/fuels" }
fuels-accounts = { version = "0.43.0", path = "./packages/fuels-accounts", default-features = false }
fuels-code-gen = { version = "0.43.0", path = "./packages/fuels-code-gen", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ mod tests {
.await?;
// ANCHOR_END: contract_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 625);
assert_eq!(transaction_cost.gas_used, 498);

Ok(())
}
Expand Down Expand Up @@ -628,7 +628,7 @@ mod tests {
.await?;
// ANCHOR_END: multi_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 1021);
assert_eq!(transaction_cost.gas_used, 783);

Ok(())
}
Expand Down
6 changes: 2 additions & 4 deletions examples/wallets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ mod tests {
.await?;
assert_eq!(contract_balances.len(), 1);

let random_asset_id_key = format!("{random_asset_id:#x}");
let random_asset_balance = contract_balances.get(&random_asset_id_key).unwrap();
let random_asset_balance = contract_balances.get(&random_asset_id.to_string()).unwrap();
assert_eq!(*random_asset_balance, 300);
// ANCHOR_END: wallet_contract_transfer

Expand Down Expand Up @@ -328,8 +327,7 @@ mod tests {
// ANCHOR_END: get_balances

// ANCHOR: get_balance_hashmap
let asset_id_key = format!("{asset_id:#x}");
let asset_balance = balances.get(&asset_id_key).unwrap();
let asset_balance = balances.get(&asset_id.to_string()).unwrap();
// ANCHOR_END: get_balance_hashmap

assert_eq!(*asset_balance, DEFAULT_COIN_AMOUNT * DEFAULT_NUM_COINS);
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-accounts/src/accounts_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn calculate_base_amount_with_fee(
.fee_checked_from_tx(consensus_params)
.expect("Error calculating TransactionFee");

let mut new_base_amount = transaction_fee.total() + previous_base_amount;
let mut new_base_amount = transaction_fee.max_fee() + previous_base_amount;

// If the tx doesn't consume any UTXOs, attempting to repeat it will lead to an
// error due to non unique tx ids (e.g. repeated contract call with configured gas cost of 0).
Expand Down
23 changes: 12 additions & 11 deletions packages/fuels-accounts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{collections::HashMap, fmt::Display};

use async_trait::async_trait;
use fuel_core_client::client::{PaginatedResult, PaginationRequest};
use fuel_core_client::client::pagination::{PaginatedResult, PaginationRequest};
#[doc(no_inline)]
pub use fuel_crypto;
use fuel_crypto::Signature;
use fuel_tx::{Output, Receipt, TxPointer, UtxoId};
use fuel_types::{AssetId, Bytes32, ContractId};
use fuel_tx::{Output, Receipt, TxId, TxPointer, UtxoId};
use fuel_types::{AssetId, Bytes32, ContractId, MessageId};
use fuels_core::{
constants::BASE_ASSET_ID,
types::{
Expand Down Expand Up @@ -189,7 +189,7 @@ pub trait Account: ViewOnlyAccount {
amount: u64,
asset_id: AssetId,
tx_parameters: TxParameters,
) -> Result<(String, Vec<Receipt>)> {
) -> Result<(TxId, Vec<Receipt>)> {
let inputs = self
.get_asset_inputs_for_amount(asset_id, amount, None)
.await?;
Expand All @@ -214,7 +214,7 @@ pub trait Account: ViewOnlyAccount {

let receipts = self.try_provider()?.send_transaction(&tx).await?;

Ok((tx.id(&consensus_parameters).to_string(), receipts))
Ok((tx.id(consensus_parameters.chain_id.into()), receipts))
}

/// Unconditionally transfers `balance` of type `asset_id` to
Expand Down Expand Up @@ -276,7 +276,7 @@ pub trait Account: ViewOnlyAccount {

let tx = self.add_fee_resources(tb, base_amount, None).await?;

let tx_id = tx.id(&params);
let tx_id = tx.id(params.chain_id.into());
let receipts = self.try_provider()?.send_transaction(&tx).await?;

Ok((tx_id.to_string(), receipts))
Expand All @@ -290,8 +290,9 @@ pub trait Account: ViewOnlyAccount {
to: &Bech32Address,
amount: u64,
tx_parameters: TxParameters,
) -> std::result::Result<(String, String, Vec<Receipt>), Error> {
) -> std::result::Result<(TxId, MessageId, Vec<Receipt>), Error> {
let params = self.try_provider()?.consensus_parameters();
let chain_id = params.chain_id;
let inputs = self
.get_asset_inputs_for_amount(BASE_ASSET_ID, amount, None)
.await?;
Expand All @@ -305,13 +306,13 @@ pub trait Account: ViewOnlyAccount {

let tx = self.add_fee_resources(tb, amount, None).await?;

let tx_id = tx.id(&params).to_string();
let tx_id = tx.id(chain_id.into());
let receipts = self.try_provider()?.send_transaction(&tx).await?;

let message_id = extract_message_id(&receipts)
.expect("MessageId could not be retrieved from tx receipts.");

Ok((tx_id, message_id.to_string(), receipts))
Ok((tx_id, message_id, receipts))
}
}

Expand Down Expand Up @@ -401,10 +402,10 @@ mod tests {
let test_provider = Provider::new(FuelClient::new("test")?, consensus_parameters);
wallet.set_provider(test_provider);
let signature = wallet.sign_transaction(&mut tx)?;
let message = Message::from_bytes(*tx.id(&consensus_parameters));
let message = Message::from_bytes(*tx.id(consensus_parameters.chain_id.into()));

// Check if signature is what we expect it to be
assert_eq!(signature, Signature::from_str("c09c82ff0671431cd3dfba9a0ffaaef9474ab0e336fcb3b833dc84108066ed1187c06739d47548b6faa3ee1e83739bb77a4ceb1872f31d1ef26b6cfa45b5a8c0")?);
assert_eq!(signature, Signature::from_str("13ce336c5f239a748f20f39323e3df3237ccfe104b04f128be66f26a49abd09d3b4b19c7f07efbb708c442371feb5fc6545f2b614e1f9f336702cca3e62d0cc8")?);

// Recover address that signed the transaction
let recovered_address = signature.recover(&message)?;
Expand Down
23 changes: 11 additions & 12 deletions packages/fuels-accounts/src/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ impl Predicate {
}

pub fn set_provider(&mut self, provider: Provider) -> &mut Self {
self.address = Self::calculate_address(&self.code, &provider.consensus_parameters());
self.address =
Self::calculate_address(&self.code, provider.consensus_parameters().chain_id.into());
self.provider = Some(provider);
self
}

pub fn calculate_address(code: &[u8], params: &ConsensusParameters) -> Bech32Address {
fuel_tx::Input::predicate_owner(code, params).into()
pub fn calculate_address(code: &[u8], chain_id: u64) -> Bech32Address {
fuel_tx::Input::predicate_owner(code, &chain_id.into()).into()
}

fn consensus_parameters(&self) -> ConsensusParameters {
Expand All @@ -61,7 +62,7 @@ impl Predicate {
/// Uses default `ConsensusParameters`
pub fn from_code(code: Vec<u8>) -> Self {
Self {
address: Self::calculate_address(&code, &ConsensusParameters::default()),
address: Self::calculate_address(&code, ConsensusParameters::default().chain_id.into()),
code,
data: Default::default(),
provider: None,
Expand All @@ -80,7 +81,7 @@ impl Predicate {
}

pub fn with_code(self, code: Vec<u8>) -> Self {
let address = Self::calculate_address(&code, &self.consensus_parameters());
let address = Self::calculate_address(&code, self.consensus_parameters().chain_id.into());
Self {
code,
address,
Expand All @@ -89,7 +90,8 @@ impl Predicate {
}

pub fn with_provider(self, provider: Provider) -> Self {
let address = Self::calculate_address(&self.code, &provider.consensus_parameters());
let address =
Self::calculate_address(&self.code, provider.consensus_parameters().chain_id.into());
Self {
address,
provider: Some(provider),
Expand All @@ -100,7 +102,8 @@ impl Predicate {
pub fn with_configurables(mut self, configurables: impl Into<Configurables>) -> Self {
let configurables: Configurables = configurables.into();
configurables.update_constants_in(&mut self.code);
let address = Self::calculate_address(&self.code, &self.consensus_parameters());
let address =
Self::calculate_address(&self.code, self.consensus_parameters().chain_id.into());
self.address = address;
self
}
Expand Down Expand Up @@ -147,11 +150,7 @@ impl Account for Predicate {
previous_base_amount: u64,
_witness_index: Option<u8>,
) -> Result<Tb::TxType> {
let consensus_parameters = self
.try_provider()?
.chain_info()
.await?
.consensus_parameters;
let consensus_parameters = self.try_provider()?.consensus_parameters();

tb = tb.set_consensus_parameters(consensus_parameters);

Expand Down
Loading

0 comments on commit 6c7e7a0

Please sign in to comment.