diff --git a/Cargo.toml b/Cargo.toml index 5360aeb629..ed7021c5da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ async-trait = { version = "0.1.74", default-features = false } bech32 = "0.9.1" bytes = { version = "1.5.0", default-features = false } chrono = "0.4.31" -cynic = { version = "2.2", default-features = false } +cynic = { version = "3.1.0", default-features = false } elliptic-curve = { version = "0.13.8", default-features = false } eth-keystore = "0.5.0" flate2 = { version = "1.0", default-features = false } @@ -113,3 +113,12 @@ fuels-macros = { version = "0.66.10", path = "./packages/fuels-macros", default- fuels-programs = { version = "0.66.10", path = "./packages/fuels-programs", default-features = false } fuels-test-helpers = { version = "0.66.10", path = "./packages/fuels-test-helpers", default-features = false } versions-replacer = { version = "0.66.10", path = "./scripts/versions-replacer", default-features = false } + +[patch.crates-io] +fuel-core = { git = "https://github.com/FuelLabs/fuel-core", branch = "hal3e/unknown-variants", package = "fuel-core"} +fuel-core-chain-config = { git = "https://github.com/FuelLabs/fuel-core", branch = "hal3e/unknown-variants", package = "fuel-core-chain-config"} +fuel-core-client = { git = "https://github.com/FuelLabs/fuel-core", branch = "hal3e/unknown-variants", package = "fuel-core-client"} # TODO: remove this @hal3e +fuel-core-poa = { git = "https://github.com/FuelLabs/fuel-core", branch = "hal3e/unknown-variants", package = "fuel-core-poa"} +fuel-core-services = { git = "https://github.com/FuelLabs/fuel-core", branch = "hal3e/unknown-variants", package = "fuel-core-services"} +fuel-core-types = { git = "https://github.com/FuelLabs/fuel-core", branch = "hal3e/unknown-variants", package = "fuel-core-types"} +fuel-core-wasm-executor = { git = "https://github.com/FuelLabs/fuel-core", branch = "hal3e/unknown-variants", package = "fuel-core-wasm-executor"} diff --git a/e2e/tests/predicates.rs b/e2e/tests/predicates.rs index 58642149b8..0f1faed0ca 100644 --- a/e2e/tests/predicates.rs +++ b/e2e/tests/predicates.rs @@ -428,8 +428,7 @@ async fn predicate_transfer_to_base_layer() -> Result<()> { let proof = predicate .try_provider()? .get_message_proof(&tx_id, &msg_nonce, None, Some(2)) - .await? - .expect("failed to retrieve message proof"); + .await?; assert_eq!(proof.amount, amount); assert_eq!(proof.recipient, base_layer_address); diff --git a/examples/wallets/src/lib.rs b/examples/wallets/src/lib.rs index dff23836b1..f52f5064de 100644 --- a/examples/wallets/src/lib.rs +++ b/examples/wallets/src/lib.rs @@ -376,8 +376,7 @@ mod tests { let proof = wallet .try_provider()? .get_message_proof(&tx_id, &msg_id, None, Some(2)) - .await? - .expect("failed to retrieve message proof"); + .await?; // Verify the amount and recipient assert_eq!(proof.amount, amount); diff --git a/packages/fuels-accounts/src/accounts_utils.rs b/packages/fuels-accounts/src/accounts_utils.rs index a89458ffe3..056cbb4ef3 100644 --- a/packages/fuels-accounts/src/accounts_utils.rs +++ b/packages/fuels-accounts/src/accounts_utils.rs @@ -54,11 +54,11 @@ pub fn available_base_assets_and_amount( amount, asset_id, .. }) if asset_id == base_asset_id => { sum += amount; - Some(resource.id()) + resource.id() } CoinType::Message(message) => { sum += message.amount; - Some(resource.id()) + resource.id() } _ => None, }, diff --git a/packages/fuels-accounts/src/impersonated_account.rs b/packages/fuels-accounts/src/impersonated_account.rs index 10f3759dfd..96c48956f5 100644 --- a/packages/fuels-accounts/src/impersonated_account.rs +++ b/packages/fuels-accounts/src/impersonated_account.rs @@ -2,13 +2,15 @@ use std::fmt::Debug; use async_trait::async_trait; use fuel_crypto::{Message, Signature}; -use fuels_core::traits::Signer; -use fuels_core::types::transaction_builders::TransactionBuilder; -use fuels_core::types::{bech32::Bech32Address, errors::Result}; -use fuels_core::types::{coin_type_id::CoinTypeId, input::Input, AssetId}; +use fuels_core::{ + traits::Signer, + types::{ + bech32::Bech32Address, coin_type_id::CoinTypeId, errors::Result, input::Input, + transaction_builders::TransactionBuilder, AssetId, + }, +}; -use crate::accounts_utils::try_provider_error; -use crate::{provider::Provider, Account, ViewOnlyAccount}; +use crate::{accounts_utils::try_provider_error, provider::Provider, Account, ViewOnlyAccount}; /// A `ImpersonatedAccount` simulates ownership of assets held by an account with a given address. /// `ImpersonatedAccount` will only succeed in unlocking assets if the the network is setup with diff --git a/packages/fuels-accounts/src/provider.rs b/packages/fuels-accounts/src/provider.rs index 862b3414fd..7dc48a4ad5 100644 --- a/packages/fuels-accounts/src/provider.rs +++ b/packages/fuels-accounts/src/provider.rs @@ -382,8 +382,8 @@ impl Provider { .await? .into_iter() .flatten() - .map(CoinType::try_from) - .collect::>>()?; + .map(CoinType::from) + .collect(); Ok(res) } @@ -696,19 +696,17 @@ impl Provider { nonce: &Nonce, commit_block_id: Option<&Bytes32>, commit_block_height: Option, - ) -> Result> { - let proof = self - .client + ) -> Result { + self.client .message_proof( tx_id, nonce, commit_block_id.map(Into::into), commit_block_height.map(Into::into), ) - .await? - .map(Into::into); - - Ok(proof) + .await + .map(Into::into) + .map_err(Into::into) } pub async fn is_user_account(&self, address: impl Into) -> Result { diff --git a/packages/fuels-accounts/src/provider/retryable_client.rs b/packages/fuels-accounts/src/provider/retryable_client.rs index 06952e5323..624df3f429 100644 --- a/packages/fuels-accounts/src/provider/retryable_client.rs +++ b/packages/fuels-accounts/src/provider/retryable_client.rs @@ -300,7 +300,7 @@ impl RetryableClient { nonce: &Nonce, commit_block_id: Option<&BlockId>, commit_block_height: Option, - ) -> RequestResult> { + ) -> RequestResult { self.wrap(|| { self.client .message_proof(transaction_id, nonce, commit_block_id, commit_block_height) @@ -350,7 +350,7 @@ mod custom_queries { use fuel_core_client::client::schema::blob::BlobIdFragment; use fuel_core_client::client::schema::schema; use fuel_core_client::client::schema::{ - contract::{ContractByIdArgs, ContractIdFragment}, + contract::{ContractByIdArgsFields, ContractIdFragment}, tx::TransactionIdFragment, BlobId, ContractId, TransactionId, }; diff --git a/packages/fuels-accounts/src/schema/schema.sdl b/packages/fuels-accounts/src/schema/schema.sdl index b9048362ca..54db4ec099 100644 --- a/packages/fuels-accounts/src/schema/schema.sdl +++ b/packages/fuels-accounts/src/schema/schema.sdl @@ -980,7 +980,7 @@ type Query { """ owner: Address, first: Int, after: String, last: Int, before: String ): MessageConnection! - messageProof(transactionId: TransactionId!, nonce: Nonce!, commitBlockId: BlockId, commitBlockHeight: U32): MessageProof + messageProof(transactionId: TransactionId!, nonce: Nonce!, commitBlockId: BlockId, commitBlockHeight: U32): MessageProof! messageStatus(nonce: Nonce!): MessageStatus! relayedTransactionStatus( """ diff --git a/packages/fuels-core/src/types/transaction_builders.rs b/packages/fuels-core/src/types/transaction_builders.rs index 6d0fa09bed..3166b378c1 100644 --- a/packages/fuels-core/src/types/transaction_builders.rs +++ b/packages/fuels-core/src/types/transaction_builders.rs @@ -299,7 +299,7 @@ macro_rules! impl_tx_builder_trait { .inputs() .iter() .filter_map(|input| match input { - Input::ResourceSigned { resource } => Some(resource.owner()), + Input::ResourceSigned { resource } => resource.owner(), _ => None, }) .unique() @@ -1305,7 +1305,7 @@ fn resolve_fuel_inputs( resource, code, data, - } => Ok(resolve_predicate_resource(resource, code, data)), + } => resolve_predicate_resource(resource, code, data), Input::Contract { utxo_id, balance_root, @@ -1357,13 +1357,25 @@ fn resolve_signed_resource( create_coin_message_input(message, num_witnesses + *witness_idx_offset as u16) }) } + CoinType::Unknown => Err(error_transaction!( + Builder, + "can not resolve `CoinType::Unknown`" + )), } } -fn resolve_predicate_resource(resource: CoinType, code: Vec, data: Vec) -> FuelInput { +fn resolve_predicate_resource( + resource: CoinType, + code: Vec, + data: Vec, +) -> Result { match resource { - CoinType::Coin(coin) => create_coin_predicate(coin.asset_id, coin, code, data), - CoinType::Message(message) => create_coin_message_predicate(message, code, data), + CoinType::Coin(coin) => Ok(create_coin_predicate(coin.asset_id, coin, code, data)), + CoinType::Message(message) => Ok(create_coin_message_predicate(message, code, data)), + CoinType::Unknown => Err(error_transaction!( + Builder, + "can not resolve `CoinType::Unknown`" + )), } } diff --git a/packages/fuels-core/src/types/wrappers/coin_type.rs b/packages/fuels-core/src/types/wrappers/coin_type.rs index 486a644904..3b612ff36e 100644 --- a/packages/fuels-core/src/types/wrappers/coin_type.rs +++ b/packages/fuels-core/src/types/wrappers/coin_type.rs @@ -3,37 +3,32 @@ use fuel_core_client::client::types::CoinType as ClientCoinType; use crate::types::{ - bech32::Bech32Address, - coin::Coin, - coin_type_id::CoinTypeId, - errors::{error, Error}, - message::Message, - AssetId, + bech32::Bech32Address, coin::Coin, coin_type_id::CoinTypeId, message::Message, AssetId, }; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum CoinType { Coin(Coin), Message(Message), + Unknown, } -impl TryFrom for CoinType { - type Error = Error; - - fn try_from(client_resource: ClientCoinType) -> Result { +impl From for CoinType { + fn from(client_resource: ClientCoinType) -> Self { match client_resource { - ClientCoinType::Coin(coin) => Ok(CoinType::Coin(coin.into())), - ClientCoinType::MessageCoin(message) => Ok(CoinType::Message(message.into())), - ClientCoinType::Unknown => Err(error!(Other, "unknown `ClientCoinType`")), + ClientCoinType::Coin(coin) => CoinType::Coin(coin.into()), + ClientCoinType::MessageCoin(message) => CoinType::Message(message.into()), + ClientCoinType::Unknown => CoinType::Unknown, } } } impl CoinType { - pub fn id(&self) -> CoinTypeId { + pub fn id(&self) -> Option { match self { - CoinType::Coin(coin) => CoinTypeId::UtxoId(coin.utxo_id), - CoinType::Message(message) => CoinTypeId::Nonce(message.nonce), + CoinType::Coin(coin) => Some(CoinTypeId::UtxoId(coin.utxo_id)), + CoinType::Message(message) => Some(CoinTypeId::Nonce(message.nonce)), + CoinType::Unknown => None, } } @@ -41,6 +36,7 @@ impl CoinType { match self { CoinType::Coin(coin) => coin.amount, CoinType::Message(message) => message.amount, + CoinType::Unknown => 0, } } @@ -48,13 +44,15 @@ impl CoinType { match self { CoinType::Coin(coin) => Some(coin.asset_id), CoinType::Message(_) => None, + CoinType::Unknown => None, } } - pub fn owner(&self) -> &Bech32Address { + pub fn owner(&self) -> Option<&Bech32Address> { match self { - CoinType::Coin(coin) => &coin.owner, - CoinType::Message(message) => &message.recipient, + CoinType::Coin(coin) => Some(&coin.owner), + CoinType::Message(message) => Some(&message.recipient), + CoinType::Unknown => None, } } } diff --git a/packages/fuels-core/src/types/wrappers/transaction.rs b/packages/fuels-core/src/types/wrappers/transaction.rs index a4590982f8..82f19b4228 100644 --- a/packages/fuels-core/src/types/wrappers/transaction.rs +++ b/packages/fuels-core/src/types/wrappers/transaction.rs @@ -187,6 +187,7 @@ pub enum TransactionType { Upload(UploadTransaction), Upgrade(UpgradeTransaction), Blob(BlobTransaction), + Unknown, } #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] @@ -284,15 +285,17 @@ pub trait Transaction: ) -> Result; } -impl From for FuelTransaction { - fn from(value: TransactionType) -> Self { +impl TryFrom for FuelTransaction { + type Error = Error; + fn try_from(value: TransactionType) -> Result { match value { - TransactionType::Script(tx) => tx.into(), - TransactionType::Create(tx) => tx.into(), - TransactionType::Mint(tx) => tx.into(), - TransactionType::Upload(tx) => tx.into(), - TransactionType::Upgrade(tx) => tx.into(), - TransactionType::Blob(tx) => tx.into(), + TransactionType::Script(tx) => Ok(tx.into()), + TransactionType::Create(tx) => Ok(tx.into()), + TransactionType::Mint(tx) => Ok(tx.into()), + TransactionType::Upload(tx) => Ok(tx.into()), + TransactionType::Upgrade(tx) => Ok(tx.into()), + TransactionType::Blob(tx) => Ok(tx.into()), + TransactionType::Unknown => Err(error_transaction!(Other, "`Unknown` transaction")), } } } diff --git a/packages/fuels-core/src/types/wrappers/transaction_response.rs b/packages/fuels-core/src/types/wrappers/transaction_response.rs index c0711a4a36..d2051771c0 100644 --- a/packages/fuels-core/src/types/wrappers/transaction_response.rs +++ b/packages/fuels-core/src/types/wrappers/transaction_response.rs @@ -3,14 +3,12 @@ use chrono::{DateTime, Utc}; use fuel_core_client::client::types::{ TransactionResponse as ClientTransactionResponse, TransactionStatus as ClientTransactionStatus, + TransactionType as ClientTxType, }; use fuel_tx::Transaction; use fuel_types::BlockHeight; -use crate::types::{ - transaction::{CreateTransaction, ScriptTransaction, TransactionType}, - tx_status::TxStatus, -}; +use crate::types::{transaction::TransactionType, tx_status::TxStatus}; #[derive(Debug, Clone)] pub struct TransactionResponse { @@ -39,12 +37,13 @@ impl From for TransactionResponse { }; let transaction = match client_response.transaction { - Transaction::Script(tx) => TransactionType::Script(ScriptTransaction::from(tx)), - Transaction::Create(tx) => TransactionType::Create(CreateTransaction::from(tx)), - Transaction::Mint(tx) => TransactionType::Mint(tx.into()), - Transaction::Upgrade(tx) => TransactionType::Upgrade(tx.into()), - Transaction::Upload(tx) => TransactionType::Upload(tx.into()), - Transaction::Blob(tx) => TransactionType::Blob(tx.into()), + ClientTxType::Known(Transaction::Script(tx)) => TransactionType::Script(tx.into()), + ClientTxType::Known(Transaction::Create(tx)) => TransactionType::Create(tx.into()), + ClientTxType::Known(Transaction::Mint(tx)) => TransactionType::Mint(tx.into()), + ClientTxType::Known(Transaction::Upgrade(tx)) => TransactionType::Upgrade(tx.into()), + ClientTxType::Known(Transaction::Upload(tx)) => TransactionType::Upload(tx.into()), + ClientTxType::Known(Transaction::Blob(tx)) => TransactionType::Blob(tx.into()), + ClientTxType::Unknown => TransactionType::Unknown, }; Self { diff --git a/packages/fuels-test-helpers/src/accounts.rs b/packages/fuels-test-helpers/src/accounts.rs index 8da8ea922d..f3ce3695a8 100644 --- a/packages/fuels-test-helpers/src/accounts.rs +++ b/packages/fuels-test-helpers/src/accounts.rs @@ -168,6 +168,7 @@ mod tests { assert_eq!(&coin.owner, wallet.address()) } CoinType::Message(_) => panic!("resources contained messages"), + CoinType::Unknown => panic!("resources contained unknown coins"), } } } diff --git a/packages/fuels-test-helpers/src/service.rs b/packages/fuels-test-helpers/src/service.rs index d37621fa4d..a848a869e3 100644 --- a/packages/fuels-test-helpers/src/service.rs +++ b/packages/fuels-test-helpers/src/service.rs @@ -86,6 +86,8 @@ impl FuelService { database_type: node_config.database_type.into(), #[cfg(feature = "rocksdb")] state_rewind_policy: Default::default(), + #[cfg(feature = "rocksdb")] + max_fds: 512, }; ServiceConfig { graphql_config: GraphQLConfig {