diff --git a/crates/iota-graphql-client/Cargo.toml b/crates/iota-graphql-client/Cargo.toml index efc7c97ac..511c5b57f 100644 --- a/crates/iota-graphql-client/Cargo.toml +++ b/crates/iota-graphql-client/Cargo.toml @@ -9,12 +9,12 @@ repository = "https://github.com/iotaledger/iota-rust-sdk/" description = "GraphQL RPC Client for the IOTA Blockchain" [dependencies] -anyhow = "1.0.71" base64ct = { version = "1.6.0", features = ["alloc", "std"] } bcs = "0.1.4" chrono = "0.4.26" cynic = "3.7.3" derive_more = { version = "2.0", features = ["from"] } +eyre = "0.6" futures = "0.3.29" iota-types = { package = "iota-sdk-types", path = "../iota-sdk-types", features = ["serde"] } reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "json"] } diff --git a/crates/iota-graphql-client/README.md b/crates/iota-graphql-client/README.md index 56552d387..26936340c 100644 --- a/crates/iota-graphql-client/README.md +++ b/crates/iota-graphql-client/README.md @@ -23,7 +23,7 @@ Instantiate a client with [`Client::new(server: &str)`] or use one of the predef ```rust, no_run use iota_graphql_client::Client; -use anyhow::Result; +use eyre::Result; #[tokio::main] async fn main() -> Result<()> { @@ -47,7 +47,7 @@ The client provides an API to request gas from the faucet. The `request_and_wait use iota_graphql_client::faucet::FaucetClient; use iota_types::Address; -use anyhow::Result; +use eyre::Result; use std::str::FromStr; #[tokio::main] @@ -77,7 +77,7 @@ Note that this `FaucetClient` is explicitly designed to work with two endpoints: use iota_graphql_client::faucet::FaucetClient; use iota_types::Address; -use anyhow::Result; +use eyre::Result; use std::str::FromStr; #[tokio::main] @@ -157,7 +157,7 @@ pub struct BigInt(pub String); The complete example is shown below: ```rust, ignore -use anyhow::Result; +use eyre::Result; use cynic::QueryBuilder; use iota_graphql_client::{ diff --git a/crates/iota-graphql-client/examples/custom_query.rs b/crates/iota-graphql-client/examples/custom_query.rs index a9a786a43..a9fab31ea 100644 --- a/crates/iota-graphql-client/examples/custom_query.rs +++ b/crates/iota-graphql-client/examples/custom_query.rs @@ -2,8 +2,8 @@ // Modifications Copyright (c) 2025 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use anyhow::Result; use cynic::QueryBuilder; +use eyre::Result; use iota_graphql_client::{ Client, query_types::{BigInt, schema}, diff --git a/crates/iota-graphql-client/examples/dynamic_fields.rs b/crates/iota-graphql-client/examples/dynamic_fields.rs index 62fe6094f..afc7f70fa 100644 --- a/crates/iota-graphql-client/examples/dynamic_fields.rs +++ b/crates/iota-graphql-client/examples/dynamic_fields.rs @@ -1,7 +1,7 @@ // Copyright (c) 2025 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use anyhow::Result; +use eyre::Result; use iota_graphql_client::Client; #[tokio::main] diff --git a/crates/iota-graphql-client/examples/generic_move_function.rs b/crates/iota-graphql-client/examples/generic_move_function.rs index cac68b12f..8cfd6ebd1 100644 --- a/crates/iota-graphql-client/examples/generic_move_function.rs +++ b/crates/iota-graphql-client/examples/generic_move_function.rs @@ -3,7 +3,7 @@ use core::str::FromStr; -use anyhow::{Context, Result}; +use eyre::{OptionExt, Result}; use iota_graphql_client::Client; use iota_transaction_builder::{Function, TransactionBuilder, unresolved::Input}; use iota_types::{Address, Identifier, TypeTag}; @@ -20,7 +20,7 @@ async fn main() -> Result<()> { None, ) .await? - .context("missing gas coin")?; + .ok_or_eyre("missing gas coin")?; let mut builder = TransactionBuilder::new(); @@ -55,7 +55,7 @@ async fn main() -> Result<()> { client .reference_gas_price(None) .await? - .context("missing gas price")?, + .ok_or_eyre("missing gas price")?, ); builder.add_gas_objects([Input::from(&gas_coin).with_owned_kind()]); @@ -63,7 +63,7 @@ async fn main() -> Result<()> { let res = client.dry_run_tx(&txn, false).await?; if let Some(err) = res.error { - anyhow::bail!("Failed to call generic Move function: {err}"); + eyre::bail!("Failed to call generic Move function: {err}"); } println!("Successfully called generic Move function!"); diff --git a/crates/iota-graphql-client/examples/get_object.rs b/crates/iota-graphql-client/examples/get_object.rs index 79062e06c..cdbc7c861 100644 --- a/crates/iota-graphql-client/examples/get_object.rs +++ b/crates/iota-graphql-client/examples/get_object.rs @@ -3,7 +3,7 @@ use std::str::FromStr; -use anyhow::{Context, Result}; +use eyre::{OptionExt, Result}; use iota_graphql_client::Client; use iota_types::ObjectId; @@ -17,7 +17,7 @@ async fn main() -> Result<()> { let obj = client .object(object_id, None) .await? - .context("missing object")?; + .ok_or_eyre("missing object")?; println!("Object ID: {}", obj.object_id()); println!("Version: {}", obj.version()); diff --git a/crates/iota-graphql-client/examples/move_functions.rs b/crates/iota-graphql-client/examples/move_functions.rs index 0b46e6ff8..cec4525af 100644 --- a/crates/iota-graphql-client/examples/move_functions.rs +++ b/crates/iota-graphql-client/examples/move_functions.rs @@ -3,7 +3,7 @@ use std::str::FromStr; -use anyhow::Result; +use eyre::Result; use iota_graphql_client::Client; use iota_types::Address; @@ -14,7 +14,7 @@ async fn main() -> Result<()> { let package_address = Address::from_str("0x3ec4826f1d6e0d9f00680b2e9a7a41f03788ee610b3d11c24f41ab0ae71da39f")?; let Some(package) = client.package(package_address, None).await? else { - anyhow::bail!("no package found") + eyre::bail!("no package found") }; for (module_id, _) in package.modules { @@ -30,7 +30,7 @@ async fn main() -> Result<()> { ) .await? else { - anyhow::bail!("module `{module_id}` not found") + eyre::bail!("module `{module_id}` not found") }; if let Some(funs) = module.functions { println!("Module: {module_id}"); diff --git a/crates/iota-graphql-client/examples/owned_objects.rs b/crates/iota-graphql-client/examples/owned_objects.rs index 8e7725202..1c865cba8 100644 --- a/crates/iota-graphql-client/examples/owned_objects.rs +++ b/crates/iota-graphql-client/examples/owned_objects.rs @@ -1,7 +1,7 @@ // Copyright (c) 2025 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use anyhow::Result; +use eyre::Result; use iota_graphql_client::{Client, pagination::PaginationFilter, query_types::ObjectFilter}; use iota_types::Address; diff --git a/crates/iota-graphql-client/examples/pagination.rs b/crates/iota-graphql-client/examples/pagination.rs index be544532c..ac5037b56 100644 --- a/crates/iota-graphql-client/examples/pagination.rs +++ b/crates/iota-graphql-client/examples/pagination.rs @@ -1,7 +1,7 @@ // Copyright (c) 2025 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use anyhow::Result; +use eyre::Result; use iota_graphql_client::{Client, pagination::PaginationFilter, query_types::ObjectFilter}; use iota_types::Address; diff --git a/crates/iota-graphql-client/examples/prepare_send_iota.rs b/crates/iota-graphql-client/examples/prepare_send_iota.rs index 17410bf43..431a403cd 100644 --- a/crates/iota-graphql-client/examples/prepare_send_iota.rs +++ b/crates/iota-graphql-client/examples/prepare_send_iota.rs @@ -3,8 +3,8 @@ use std::str::FromStr; -use anyhow::Result; use base64ct::Encoding; +use eyre::Result; use iota_graphql_client::Client; use iota_transaction_builder::{TransactionBuilder, unresolved::Input}; use iota_types::{Address, ObjectId}; @@ -63,7 +63,7 @@ async fn main() -> Result<()> { let res = client.dry_run_tx(&txn, false).await?; if let Some(err) = res.error { - anyhow::bail!("Failed to send IOTA: {err}"); + eyre::bail!("Failed to send IOTA: {err}"); } println!("Send IOTA dry run was successful!"); diff --git a/crates/iota-graphql-client/examples/prepare_send_iota_multi.rs b/crates/iota-graphql-client/examples/prepare_send_iota_multi.rs index 11f0a32bb..a3f40474c 100644 --- a/crates/iota-graphql-client/examples/prepare_send_iota_multi.rs +++ b/crates/iota-graphql-client/examples/prepare_send_iota_multi.rs @@ -3,8 +3,8 @@ use std::str::FromStr; -use anyhow::{Context, Result}; use base64ct::Encoding; +use eyre::{OptionExt, Result}; use iota_graphql_client::Client; use iota_transaction_builder::{TransactionBuilder, unresolved::Input}; use iota_types::{Address, Argument, ObjectId}; @@ -24,7 +24,7 @@ async fn main() -> Result<()> { None, ) .await? - .context("missing gas coin")?; + .ok_or_eyre("missing gas coin")?; // Recipients and amounts let recipients = [ @@ -61,7 +61,7 @@ async fn main() -> Result<()> { // Transfer each split coin to its corresponding recipient for (i, recipient_input) in recipient_inputs.into_iter().enumerate() { let coin_arg = Argument::get_nested_result(&split_coins_result, i as u16) - .ok_or_else(|| anyhow::anyhow!("Failed to get split coin result at index {i}"))?; + .ok_or_else(|| eyre::eyre!("Failed to get split coin result at index {i}"))?; builder.transfer_objects(vec![coin_arg], recipient_input); } @@ -71,7 +71,7 @@ async fn main() -> Result<()> { client .reference_gas_price(None) .await? - .context("missing ref gas price")?, + .ok_or_eyre("missing ref gas price")?, ); builder.add_gas_objects([Input::from(&gas_coin).with_owned_kind()]); let txn = builder.finish()?; @@ -85,7 +85,7 @@ async fn main() -> Result<()> { let res = client.dry_run_tx(&txn, false).await?; if let Some(err) = res.error { - anyhow::bail!("Failed to send IOTA: {err}"); + eyre::bail!("Failed to send IOTA: {err}"); } println!("Send IOTA dry run was successful!"); diff --git a/crates/iota-graphql-client/examples/stake.rs b/crates/iota-graphql-client/examples/stake.rs index f2ef0a484..1115e7fa4 100644 --- a/crates/iota-graphql-client/examples/stake.rs +++ b/crates/iota-graphql-client/examples/stake.rs @@ -3,7 +3,7 @@ use std::str::FromStr; -use anyhow::{Context, Result}; +use eyre::{OptionExt, Result}; use iota_graphql_client::Client; use iota_transaction_builder::{Function, TransactionBuilder, unresolved::Input}; use iota_types::{Address, Identifier, ObjectId}; @@ -21,7 +21,7 @@ async fn main() -> Result<()> { .data .into_iter() .next() - .context("no validators found")?; + .ok_or_eyre("no validators found")?; println!( "Staking to validator {}", @@ -36,7 +36,7 @@ async fn main() -> Result<()> { None, ) .await? - .context("missing object")?; + .ok_or_eyre("missing object")?; let gas_coin = client .object( ObjectId::from_str( @@ -45,7 +45,7 @@ async fn main() -> Result<()> { None, ) .await? - .context("missing gas coin")?; + .ok_or_eyre("missing gas coin")?; let mut builder = TransactionBuilder::new(); let inputs = vec![ @@ -68,14 +68,14 @@ async fn main() -> Result<()> { client .reference_gas_price(None) .await? - .context("missing ref gas price")?, + .ok_or_eyre("missing ref gas price")?, ); builder.add_gas_objects([Input::from(&gas_coin).with_owned_kind()]); let txn = builder.finish()?; let res = client.dry_run_tx(&txn, false).await?; if let Some(err) = res.error { - anyhow::bail!("Failed to stake: {err}"); + eyre::bail!("Failed to stake: {err}"); } println!("Stake dry run was successful!"); diff --git a/crates/iota-graphql-client/examples/unstake.rs b/crates/iota-graphql-client/examples/unstake.rs index 6e2480b6c..17fd91210 100644 --- a/crates/iota-graphql-client/examples/unstake.rs +++ b/crates/iota-graphql-client/examples/unstake.rs @@ -3,7 +3,7 @@ use std::str::FromStr; -use anyhow::{Context, Result}; +use eyre::{OptionExt, Result}; use iota_graphql_client::{Client, query_types::ObjectFilter}; use iota_transaction_builder::{Function, TransactionBuilder, unresolved::Input}; use iota_types::{Address, Identifier, ObjectId, StructTag}; @@ -24,7 +24,7 @@ async fn main() -> Result<()> { .data .into_iter() .next() - .context("no staked iota found")?; + .ok_or_eyre("no staked iota found")?; // Get a valid gas coin let gas_coin = client @@ -40,7 +40,7 @@ async fn main() -> Result<()> { .data .into_iter() .next() - .context("no gas coin found")?; + .ok_or_eyre("no gas coin found")?; let mut builder = TransactionBuilder::new(); let inputs = vec![ @@ -69,7 +69,7 @@ async fn main() -> Result<()> { let res = client.dry_run_tx(&txn, false).await?; if let Some(err) = res.error { - anyhow::bail!("Failed to unstake: {err}"); + eyre::bail!("Failed to unstake: {err}"); } println!("Unstake dry run was successful!"); diff --git a/crates/iota-graphql-client/src/faucet.rs b/crates/iota-graphql-client/src/faucet.rs index d4fed9c46..167d7ce57 100644 --- a/crates/iota-graphql-client/src/faucet.rs +++ b/crates/iota-graphql-client/src/faucet.rs @@ -4,7 +4,7 @@ use std::time::Duration; -use anyhow::{anyhow, bail}; +use eyre::{bail, eyre}; use iota_types::{Address, Digest, ObjectId}; use reqwest::{StatusCode, Url}; use serde::{Deserialize, Serialize}; @@ -95,13 +95,13 @@ impl FaucetClient { /// Request gas from the faucet. Note that this will return the UUID of the /// request and not wait until the token is received. Use /// `request_and_wait` to wait for the token. - pub async fn request(&self, address: Address) -> anyhow::Result> { + pub async fn request(&self, address: Address) -> eyre::Result> { self.request_impl(address).await } /// Internal implementation of a faucet request. It returns the task Uuid as /// a String. - async fn request_impl(&self, address: Address) -> anyhow::Result> { + async fn request_impl(&self, address: Address) -> eyre::Result> { let address = address.to_string(); let json_body = json![{ "FixedAmountRequest": { @@ -158,10 +158,7 @@ impl FaucetClient { /// /// Note that the faucet is heavily rate-limited, so calling repeatedly the /// faucet would likely result in a 429 code or 502 code. - pub async fn request_and_wait( - &self, - address: Address, - ) -> anyhow::Result> { + pub async fn request_and_wait(&self, address: Address) -> eyre::Result> { let request_id = self.request(address).await?; if let Some(request_id) = request_id { let poll_response = tokio::time::timeout(FAUCET_REQUEST_TIMEOUT, async { @@ -189,7 +186,7 @@ impl FaucetClient { } } else if let Some(err) = req.err() { error!("Faucet request {request_id} failed. Error: {:?}", err); - break Err(anyhow!( + break Err(eyre!( "Faucet request {request_id} failed. Error: {:?}", err )); @@ -202,7 +199,7 @@ impl FaucetClient { "Faucet request {request_id} timed out. Timeout set to {} seconds", FAUCET_REQUEST_TIMEOUT.as_secs() ); - anyhow!("Faucet request timed out") + eyre!("Faucet request timed out") })??; Ok(poll_response.transferred_gas_objects) } else { @@ -213,7 +210,7 @@ impl FaucetClient { /// Check the faucet request status. /// /// Possible statuses are defined in: [`BatchSendStatusType`] - pub async fn request_status(&self, id: String) -> anyhow::Result> { + pub async fn request_status(&self, id: String) -> eyre::Result> { let status_url = format!("{}v1/status/{}", self.faucet_url, id); info!("Checking status of faucet request: {status_url}"); let response = self.inner.get(&status_url).send().await?; @@ -227,7 +224,7 @@ impl FaucetClient { .await .map_err(|e| { error!("Failed to parse faucet response: {:?}", e); - anyhow!("Failed to parse faucet response: {:?}", e) + eyre!("Failed to parse faucet response: {:?}", e) })?; Ok(json.status) } diff --git a/crates/iota-sdk-types/src/transaction/fixtures/update-transaction-fixtures/Cargo.toml b/crates/iota-sdk-types/src/transaction/fixtures/update-transaction-fixtures/Cargo.toml index 4e44d57eb..455d87628 100644 --- a/crates/iota-sdk-types/src/transaction/fixtures/update-transaction-fixtures/Cargo.toml +++ b/crates/iota-sdk-types/src/transaction/fixtures/update-transaction-fixtures/Cargo.toml @@ -6,8 +6,8 @@ version = "0.1.0" edition = "2021" [dependencies] -anyhow = "1.0.71" bcs = "0.1.4" +eyre = "0.6" fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "5f2c63266a065996d53f98156f0412782b468597" } futures = "0.3.28" iota-json-rpc-types = { path = "../../../../../../../iota/crates/iota-json-rpc-types" } diff --git a/crates/iota-sdk-types/src/transaction/fixtures/update-transaction-fixtures/src/main.rs b/crates/iota-sdk-types/src/transaction/fixtures/update-transaction-fixtures/src/main.rs index 3bde25b2b..381d5791e 100644 --- a/crates/iota-sdk-types/src/transaction/fixtures/update-transaction-fixtures/src/main.rs +++ b/crates/iota-sdk-types/src/transaction/fixtures/update-transaction-fixtures/src/main.rs @@ -22,7 +22,7 @@ use test_cluster::TestClusterBuilder; const BASE_PATH: &str = "../"; #[tokio::main] -async fn main() -> anyhow::Result<()> { +async fn main() -> eyre::Result<()> { let test_cluster = TestClusterBuilder::new().build().await; let client = test_cluster.wallet.get_client().await?; @@ -130,7 +130,7 @@ async fn main() -> anyhow::Result<()> { // Write the tx data bytes base64 encoded to a file with the BASE_PATH before // the provided name -fn write_bs64_tx_to_file(tx_data_bytes: &[u8], name: &str) -> anyhow::Result<()> { +fn write_bs64_tx_to_file(tx_data_bytes: &[u8], name: &str) -> eyre::Result<()> { let mut f = OpenOptions::new() .create(true) .write(true) @@ -141,7 +141,7 @@ fn write_bs64_tx_to_file(tx_data_bytes: &[u8], name: &str) -> anyhow::Result<()> Ok(()) } -fn raw_tx_bytes_to_transaction_data_bytes(raw_tx_bytes: &[u8]) -> anyhow::Result> { +fn raw_tx_bytes_to_transaction_data_bytes(raw_tx_bytes: &[u8]) -> eyre::Result> { let sender_signed_data: SenderSignedData = bcs::from_bytes(raw_tx_bytes)?; let tx_data = sender_signed_data.transaction_data(); let tx_data_bytes = bcs::to_bytes(tx_data)?; diff --git a/crates/iota-transaction-builder/Cargo.toml b/crates/iota-transaction-builder/Cargo.toml index 663d024d8..0a46ec051 100644 --- a/crates/iota-transaction-builder/Cargo.toml +++ b/crates/iota-transaction-builder/Cargo.toml @@ -23,7 +23,7 @@ thiserror = "2.0" schemars = { version = "0.8.21", optional = true } [dev-dependencies] -anyhow = "1.0" +eyre = "0.6" iota-crypto = { package = "iota-crypto", path = "../iota-crypto", features = ["ed25519"] } iota-graphql-client = { package = "iota-graphql-client", path = "../iota-graphql-client" } iota-types = { package = "iota-sdk-types", path = "../iota-sdk-types", features = ["rand"] } diff --git a/crates/iota-transaction-builder/src/lib.rs b/crates/iota-transaction-builder/src/lib.rs index 691b56df6..df4daf248 100644 --- a/crates/iota-transaction-builder/src/lib.rs +++ b/crates/iota-transaction-builder/src/lib.rs @@ -478,8 +478,8 @@ fn try_from_unresolved_input_arg(value: unresolved::Input) -> Result