Skip to content

Commit

Permalink
Merge branch 'master' into oleksii/connect_to_deployed_contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Br1ght0ne authored Oct 14, 2024
2 parents d0dec24 + 92dd2cc commit 53952a1
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
CARGO_TERM_COLOR: always
DASEL_VERSION: https://github.com/TomWright/dasel/releases/download/v2.3.6/dasel_linux_amd64
RUSTFLAGS: "-D warnings"
FUEL_CORE_VERSION: 0.38.0
FUEL_CORE_VERSION: 0.39.0
FUEL_CORE_PATCH_BRANCH: ""
FUEL_CORE_PATCH_REVISION: ""
RUST_VERSION: 1.79.0
Expand Down
31 changes: 16 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ readme = "README.md"
license = "Apache-2.0"
repository = "https://github.com/FuelLabs/fuels-rs"
rust-version = "1.79.0"
version = "0.66.7"
version = "0.66.8"

[workspace.dependencies]
Inflector = "0.11.4"
Expand All @@ -48,6 +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 }
elliptic-curve = { version = "0.13.8", default-features = false }
eth-keystore = "0.5.0"
flate2 = { version = "1.0", default-features = false }
Expand Down Expand Up @@ -85,14 +86,14 @@ octocrab = { version = "0.39", default-features = false }
dotenv = { version = "0.15", default-features = false }

# Dependencies from the `fuel-core` repository:
fuel-core = { version = "0.38.0", default-features = false, features = [
fuel-core = { version = "0.39.0", default-features = false, features = [
"wasm-executor",
] }
fuel-core-chain-config = { version = "0.38.0", default-features = false }
fuel-core-client = { version = "0.38.0", default-features = false }
fuel-core-poa = { version = "0.38.0", default-features = false }
fuel-core-services = { version = "0.38.0", default-features = false }
fuel-core-types = { version = "0.38.0", default-features = false }
fuel-core-chain-config = { version = "0.39.0", default-features = false }
fuel-core-client = { version = "0.39.0", default-features = false }
fuel-core-poa = { version = "0.39.0", default-features = false }
fuel-core-services = { version = "0.39.0", default-features = false }
fuel-core-types = { version = "0.39.0", default-features = false }

# Dependencies from the `fuel-vm` repository:
fuel-asm = { version = "0.58.0" }
Expand All @@ -104,11 +105,11 @@ fuel-types = { version = "0.58.0" }
fuel-vm = { version = "0.58.0" }

# Workspace projects
fuels = { version = "0.66.7", path = "./packages/fuels", default-features = false }
fuels-accounts = { version = "0.66.7", path = "./packages/fuels-accounts", default-features = false }
fuels-code-gen = { version = "0.66.7", path = "./packages/fuels-code-gen", default-features = false }
fuels-core = { version = "0.66.7", path = "./packages/fuels-core", default-features = false }
fuels-macros = { version = "0.66.7", path = "./packages/fuels-macros", default-features = false }
fuels-programs = { version = "0.66.7", path = "./packages/fuels-programs", default-features = false }
fuels-test-helpers = { version = "0.66.7", path = "./packages/fuels-test-helpers", default-features = false }
versions-replacer = { version = "0.66.7", path = "./scripts/versions-replacer", default-features = false }
fuels = { version = "0.66.8", path = "./packages/fuels", default-features = false }
fuels-accounts = { version = "0.66.8", path = "./packages/fuels-accounts", default-features = false }
fuels-code-gen = { version = "0.66.8", path = "./packages/fuels-code-gen", default-features = false }
fuels-core = { version = "0.66.8", path = "./packages/fuels-core", default-features = false }
fuels-macros = { version = "0.66.8", path = "./packages/fuels-macros", default-features = false }
fuels-programs = { version = "0.66.8", path = "./packages/fuels-programs", default-features = false }
fuels-test-helpers = { version = "0.66.8", path = "./packages/fuels-test-helpers", default-features = false }
versions-replacer = { version = "0.66.8", path = "./scripts/versions-replacer", 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.66.7", features = ["fuel-core-lib"] }
fuels = { version = "0.66.8", 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.66.7", features = ["rocksdb"] }
fuels = { version = "0.66.8", features = ["rocksdb"] }
```
67 changes: 67 additions & 0 deletions e2e/tests/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,3 +1214,70 @@ async fn contract_call_with_impersonation() -> Result<()> {

Ok(())
}

#[tokio::test]
async fn is_account_query_test() -> Result<()> {
{
let wallet = launch_provider_and_get_wallet().await?;
let provider = wallet.provider().unwrap().clone();

let blob = Blob::new(vec![1; 100]);
let blob_id = blob.id();

let is_account = provider.is_user_account(blob_id).await?;
assert!(is_account);

let mut tb = BlobTransactionBuilder::default().with_blob(blob);
wallet.adjust_for_fee(&mut tb, 0).await?;
wallet.add_witnesses(&mut tb)?;
let tx = tb.build(provider.clone()).await?;

provider
.send_transaction_and_await_commit(tx)
.await?
.check(None)?;

let is_account = provider.is_user_account(blob_id).await?;
assert!(!is_account);
}
{
let wallet = launch_provider_and_get_wallet().await?;
let provider = wallet.provider().unwrap().clone();

let contract = Contract::load_from(
"sway/contracts/contract_test/out/release/contract_test.bin",
LoadConfiguration::default(),
)?;
let contract_id = contract.contract_id();

let is_account = provider.is_user_account(*contract_id).await?;
assert!(is_account);

contract.deploy(&wallet, TxPolicies::default()).await?;

let is_account = provider.is_user_account(*contract_id).await?;
assert!(!is_account);
}
{
let wallet = launch_provider_and_get_wallet().await?;
let provider = wallet.provider().unwrap().clone();

let mut tb = ScriptTransactionBuilder::default();
wallet.adjust_for_fee(&mut tb, 0).await?;
wallet.add_witnesses(&mut tb)?;
let tx = tb.build(provider.clone()).await?;

let tx_id = tx.id(provider.chain_id());
let is_account = provider.is_user_account(tx_id).await?;
assert!(is_account);

provider
.send_transaction_and_await_commit(tx)
.await?
.check(None)?;
let is_account = provider.is_user_account(tx_id).await?;
assert!(!is_account);
}

Ok(())
}
6 changes: 6 additions & 0 deletions packages/fuels-accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description = "Fuel Rust SDK accounts."
[dependencies]
async-trait = { workspace = true, default-features = false }
chrono = { workspace = true }
cynic = { workspace = true, optional = true }
elliptic-curve = { workspace = true, default-features = false }
eth-keystore = { workspace = true, optional = true }
fuel-core-client = { workspace = true, optional = true }
Expand All @@ -33,6 +34,10 @@ fuel-tx = { workspace = true, features = ["test-helpers", "random"] }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["test-util"] }

[build-dependencies]
cynic = { workspace = true, features = ["default"], optional = true }
fuel-core-client = { workspace = true, optional = true }

[features]
default = ["std"]
coin-cache = ["tokio?/time"]
Expand All @@ -41,4 +46,5 @@ std = [
"dep:tokio",
"fuel-core-client/default",
"dep:eth-keystore",
"dep:cynic",
]
15 changes: 15 additions & 0 deletions packages/fuels-accounts/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn main() {
#[cfg(feature = "std")]
{
use std::fs;

fs::create_dir_all("target").expect("Unable to create target directory");
fs::write(
"target/fuel-core-client-schema.sdl",
fuel_core_client::SCHEMA_SDL,
)
.expect("Unable to write schema file");

println!("cargo:rerun-if-changed=build.rs");
}
}
4 changes: 4 additions & 0 deletions packages/fuels-accounts/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,10 @@ impl Provider {
Ok(proof)
}

pub async fn is_user_account(&self, address: impl Into<Bytes32>) -> Result<bool> {
self.client.is_user_account(*address.into()).await
}

pub fn with_retry_config(mut self, retry_config: RetryConfig) -> Self {
self.client.set_retry_config(retry_config);

Expand Down
52 changes: 52 additions & 0 deletions packages/fuels-accounts/src/provider/retryable_client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{future::Future, io};

use custom_queries::{IsUserAccountQuery, IsUserAccountVariables};
use cynic::QueryBuilder;
use fuel_core_client::client::{
pagination::{PaginatedResult, PaginationRequest},
types::{
Expand Down Expand Up @@ -311,4 +313,54 @@ impl RetryableClient {
.map(|contract| contract.is_some())
}
// DELEGATION END

pub async fn is_user_account(&self, address: [u8; 32]) -> Result<bool> {
let blob_id = BlobId::from(address);
let contract_id = ContractId::from(address);
let transaction_id = TransactionId::from(address);

let query = IsUserAccountQuery::build(IsUserAccountVariables {
blob_id: blob_id.into(),
contract_id: contract_id.into(),
transaction_id: transaction_id.into(),
});

let response = self.client.query(query).await?;

let is_resource = response.blob.is_some()
|| response.contract.is_some()
|| response.transaction.is_some();

Ok(!is_resource)
}
}

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::ContractIdFragment, tx::TransactionIdFragment, BlobId, ContractId, TransactionId,
};

#[derive(cynic::QueryVariables, Debug)]
pub struct IsUserAccountVariables {
pub blob_id: BlobId,
pub contract_id: ContractId,
pub transaction_id: TransactionId,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(
graphql_type = "Query",
variables = "IsUserAccountVariables",
schema_path = "./target/fuel-core-client-schema.sdl"
)]
pub struct IsUserAccountQuery {
#[arguments(id: $blob_id)]
pub blob: Option<BlobIdFragment>,
#[arguments(id: $contract_id)]
pub contract: Option<ContractIdFragment>,
#[arguments(id: $transaction_id)]
pub transaction: Option<TransactionIdFragment>,
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub const SUPPORTED_FUEL_CORE_VERSION: semver::Version = semver::Version::new(0, 38, 0);
pub const SUPPORTED_FUEL_CORE_VERSION: semver::Version = semver::Version::new(0, 39, 0);
1 change: 1 addition & 0 deletions packages/fuels-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ itertools = { workspace = true }
postcard = { version = "1", default-features = true, features = ["alloc"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, default-features = true }
sha2 = { workspace = true }
thiserror = { workspace = true, default-features = false }
uint = { workspace = true, default-features = false }

Expand Down
1 change: 1 addition & 0 deletions packages/fuels-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod transaction_builders;
pub mod tx_status;
mod wrappers;
pub use dry_runner::*;
pub mod checksum_address;

pub type ByteArray = [u8; 8];
pub type Selector = Vec<u8>;
Expand Down
Loading

0 comments on commit 53952a1

Please sign in to comment.