From 73f4054db76c73fd1d090e1b38bdbf0b2707cc50 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Wed, 20 Sep 2023 13:39:53 -0400 Subject: [PATCH 1/3] Remove excess features --- Cargo.lock | 1 + bindings/core/Cargo.toml | 3 ++ bindings/core/src/method/wallet.rs | 2 +- sdk/Cargo.toml | 39 ++++++++++++------------ sdk/examples/wallet/participation.rs | 3 +- sdk/src/client/node_manager/node.rs | 3 +- sdk/src/lib.rs | 2 -- sdk/src/utils/mod.rs | 2 +- sdk/src/wallet/core/operations/client.rs | 3 +- sdk/tests/wallet/backup_restore.rs | 2 +- sdk/tests/wallet/core.rs | 2 +- 11 files changed, 32 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 222b8ef00b..f2a24f102b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1603,6 +1603,7 @@ dependencies = [ "serde_json", "thiserror", "tokio", + "url", "zeroize", ] diff --git a/bindings/core/Cargo.toml b/bindings/core/Cargo.toml index 622989e74d..0c754e909d 100644 --- a/bindings/core/Cargo.toml +++ b/bindings/core/Cargo.toml @@ -30,6 +30,9 @@ serde = { version = "1.0.188", default-features = false } serde_json = { version = "1.0.107", default-features = false } thiserror = { version = "1.0.48", default-features = false } tokio = { version = "1.32.0", default-features = false } +url = { version = "2.4.1", default-features = false, features = [ + "serde", +] } zeroize = { version = "1.6.0", default-features = false } [features] diff --git a/bindings/core/src/method/wallet.rs b/bindings/core/src/method/wallet.rs index bd3ec1bfae..9c48819fd4 100644 --- a/bindings/core/src/method/wallet.rs +++ b/bindings/core/src/method/wallet.rs @@ -17,9 +17,9 @@ use iota_sdk::{ }, ClientOptions, }, - Url, }; use serde::{Deserialize, Serialize}; +use url::Url; use crate::method::account::AccountMethod; #[cfg(feature = "stronghold")] diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 26dd8098ad..e846f321de 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -138,20 +138,19 @@ tokio = { version = "1.32.0", default-features = false, features = [ [features] default = ["client", "wallet", "tls"] -irc_27 = ["url", "serde"] -irc_30 = ["url", "serde"] -ledger_nano = ["iota-ledger-nano"] -mqtt = ["std", "regex", "rumqttc", "dep:once_cell"] +irc_27 = ["serde", "dep:url"] +irc_30 = ["serde", "dep:url"] +ledger_nano = ["dep:iota-ledger-nano"] +mqtt = ["std", "tls", "dep:regex", "dep:rumqttc", "dep:once_cell"] participation = ["storage"] -rand = ["dep:rand"] -rocksdb = ["dep:rocksdb", "storage"] +rocksdb = ["storage", "dep:rocksdb"] serde = [ - "serde_repr", "hashbrown/serde", "packable/serde", "primitive-types/serde_no_std", "iota-crypto/serde", "zeroize?/serde", + "dep:serde_repr", ] std = [ "packable/std", @@ -167,34 +166,34 @@ std = [ ] storage = ["iota-crypto/chacha", "dep:time", "dep:anymap", "dep:once_cell"] stronghold = [ - "iota_stronghold", "iota-crypto/chacha", + "dep:iota_stronghold", "dep:time", "dep:anymap", "dep:once_cell", ] tls = ["reqwest?/rustls-tls", "rumqttc?/use-rustls"] events = [] -private_key_secret_manager = ["bs58"] +private_key_secret_manager = ["dep:bs58"] client = [ - "async-trait", - "futures", - "instant", + "std", + "serde", "iota-crypto/bip39", "iota-crypto/bip39-en", "iota-crypto/bip44", "iota-crypto/keccak", "iota-crypto/random", "iota-crypto/slip10", - "log", - "reqwest", - "serde", - "std", - "thiserror", - "tokio", - "url", - "zeroize", + "dep:async-trait", + "dep:futures", + "dep:instant", + "dep:log", + "dep:reqwest", + "dep:thiserror", + "dep:tokio", + "dep:url", + "dep:zeroize", ] wallet = ["client"] diff --git a/sdk/examples/wallet/participation.rs b/sdk/examples/wallet/participation.rs index 9e63fbad8e..bfa7129fe3 100644 --- a/sdk/examples/wallet/participation.rs +++ b/sdk/examples/wallet/participation.rs @@ -19,8 +19,9 @@ use iota_sdk::{ client::node_manager::node::Node, wallet::{account::types::participation::ParticipationEventRegistrationOptions, Result}, - Url, Wallet, + Wallet, }; +use url::Url; // The node that runs the participation plugin const PARTICPATION_NODE_URL: &str = "https://api.testnet.shimmer.network"; diff --git a/sdk/src/client/node_manager/node.rs b/sdk/src/client/node_manager/node.rs index ecba7332bf..6dc1122106 100644 --- a/sdk/src/client/node_manager/node.rs +++ b/sdk/src/client/node_manager/node.rs @@ -4,8 +4,7 @@ use std::hash::Hash; use serde::{Deserialize, Serialize}; - -use crate::Url; +use url::Url; /// Node authentication object. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)] diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index dc54411f41..9c05c833f1 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -27,8 +27,6 @@ pub mod utils; pub use crypto; pub use packable; pub use primitive_types::U256; -#[cfg(feature = "url")] -pub use url::Url; #[cfg(feature = "wallet")] pub type Wallet = self::wallet::Wallet; diff --git a/sdk/src/utils/mod.rs b/sdk/src/utils/mod.rs index b7fdcba30d..b62ea47f38 100644 --- a/sdk/src/utils/mod.rs +++ b/sdk/src/utils/mod.rs @@ -4,7 +4,7 @@ #[cfg(feature = "serde")] pub mod serde; -#[cfg(feature = "instant")] +#[cfg(feature = "client")] pub fn unix_timestamp_now() -> core::time::Duration { instant::SystemTime::now() .duration_since(instant::SystemTime::UNIX_EPOCH) diff --git a/sdk/src/wallet/core/operations/client.rs b/sdk/src/wallet/core/operations/client.rs index 12f2bf3acf..f879042db9 100644 --- a/sdk/src/wallet/core/operations/client.rs +++ b/sdk/src/wallet/core/operations/client.rs @@ -3,6 +3,8 @@ use std::collections::{HashMap, HashSet}; +use url::Url; + use super::storage::SaveLoadWallet; use crate::{ client::{ @@ -14,7 +16,6 @@ use crate::{ Client, ClientBuilder, }, wallet::{Wallet, WalletBuilder}, - Url, }; impl Wallet { diff --git a/sdk/tests/wallet/backup_restore.rs b/sdk/tests/wallet/backup_restore.rs index ae981c1196..9f9d29e8e6 100644 --- a/sdk/tests/wallet/backup_restore.rs +++ b/sdk/tests/wallet/backup_restore.rs @@ -11,8 +11,8 @@ use iota_sdk::{ secret::{mnemonic::MnemonicSecretManager, stronghold::StrongholdSecretManager, SecretManager}, }, wallet::{ClientOptions, Result, Wallet}, - Url, }; +use url::Url; use crate::wallet::common::{setup, tear_down, NODE_LOCAL, NODE_OTHER}; diff --git a/sdk/tests/wallet/core.rs b/sdk/tests/wallet/core.rs index 7976603615..6067df3c39 100644 --- a/sdk/tests/wallet/core.rs +++ b/sdk/tests/wallet/core.rs @@ -7,7 +7,6 @@ use iota_sdk::{ client::constants::SHIMMER_COIN_TYPE, client::node_manager::node::{Node, NodeDto}, wallet::Error, - Url, }; use iota_sdk::{ client::{ @@ -17,6 +16,7 @@ use iota_sdk::{ types::block::address::Bech32Address, wallet::{ClientOptions, Result, Wallet}, }; +use url::Url; #[cfg(feature = "storage")] use crate::wallet::common::NODE_OTHER; From cd9fbd30fe3668f164153bbe11a19a178a93a2a5 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Wed, 20 Sep 2023 14:02:48 -0400 Subject: [PATCH 2/3] move utils --- sdk/src/client/api/high_level.rs | 3 +-- sdk/src/client/utils.rs | 6 ++++++ sdk/src/utils/mod.rs | 7 ------- sdk/src/wallet/account/operations/syncing/mod.rs | 4 ++-- sdk/src/wallet/account/operations/syncing/transactions.rs | 3 +-- sdk/src/wallet/account/operations/transaction/mod.rs | 2 +- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/sdk/src/client/api/high_level.rs b/sdk/src/client/api/high_level.rs index e3f124dd76..c224ebe80b 100644 --- a/sdk/src/client/api/high_level.rs +++ b/sdk/src/client/api/high_level.rs @@ -11,7 +11,7 @@ use crate::{ constants::FIVE_MINUTES_IN_SECONDS, error::{Error, Result}, node_api::indexer::query_parameters::QueryParameter, - Client, + unix_timestamp_now, Client, }, types::block::{ address::Bech32Address, @@ -22,7 +22,6 @@ use crate::{ slot::SlotIndex, BlockId, }, - utils::unix_timestamp_now, }; impl Client { diff --git a/sdk/src/client/utils.rs b/sdk/src/client/utils.rs index 3e231accb0..448bec6899 100644 --- a/sdk/src/client/utils.rs +++ b/sdk/src/client/utils.rs @@ -197,3 +197,9 @@ impl Password { self.0.as_bytes() } } + +pub fn unix_timestamp_now() -> core::time::Duration { + instant::SystemTime::now() + .duration_since(instant::SystemTime::UNIX_EPOCH) + .expect("time went backwards") +} diff --git a/sdk/src/utils/mod.rs b/sdk/src/utils/mod.rs index b62ea47f38..fd6170b030 100644 --- a/sdk/src/utils/mod.rs +++ b/sdk/src/utils/mod.rs @@ -3,10 +3,3 @@ #[cfg(feature = "serde")] pub mod serde; - -#[cfg(feature = "client")] -pub fn unix_timestamp_now() -> core::time::Duration { - instant::SystemTime::now() - .duration_since(instant::SystemTime::UNIX_EPOCH) - .expect("time went backwards") -} diff --git a/sdk/src/wallet/account/operations/syncing/mod.rs b/sdk/src/wallet/account/operations/syncing/mod.rs index 2eae6020eb..250a3beb45 100644 --- a/sdk/src/wallet/account/operations/syncing/mod.rs +++ b/sdk/src/wallet/account/operations/syncing/mod.rs @@ -58,7 +58,7 @@ where let syc_start_time = instant::Instant::now(); // Prevent syncing the account multiple times simultaneously - let time_now = crate::utils::unix_timestamp_now().as_millis(); + let time_now = crate::client::unix_timestamp_now().as_millis(); let mut last_synced = self.last_synced.lock().await; log::debug!("[SYNC] last time synced before {}ms", time_now - *last_synced); if !options.force_syncing && time_now - *last_synced < MIN_SYNC_INTERVAL { @@ -86,7 +86,7 @@ where let balance = self.balance().await?; // Update last_synced mutex - let time_now = crate::utils::unix_timestamp_now().as_millis(); + let time_now = crate::client::unix_timestamp_now().as_millis(); *last_synced = time_now; log::debug!("[SYNC] finished syncing in {:.2?}", syc_start_time.elapsed()); Ok(balance) diff --git a/sdk/src/wallet/account/operations/syncing/transactions.rs b/sdk/src/wallet/account/operations/syncing/transactions.rs index 0ed2b6170b..71e64e6d84 100644 --- a/sdk/src/wallet/account/operations/syncing/transactions.rs +++ b/sdk/src/wallet/account/operations/syncing/transactions.rs @@ -2,12 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 use crate::{ - client::secret::SecretManage, + client::{secret::SecretManage, unix_timestamp_now}, types::{ api::core::response::TransactionState, block::{input::Input, output::OutputId, BlockId}, }, - utils::unix_timestamp_now, wallet::account::{ types::{InclusionState, Transaction}, Account, AccountDetails, diff --git a/sdk/src/wallet/account/operations/transaction/mod.rs b/sdk/src/wallet/account/operations/transaction/mod.rs index f8a507b0e6..c3003ef4f8 100644 --- a/sdk/src/wallet/account/operations/transaction/mod.rs +++ b/sdk/src/wallet/account/operations/transaction/mod.rs @@ -174,7 +174,7 @@ where payload: signed_transaction_data.transaction_payload, block_id, network_id, - timestamp: crate::utils::unix_timestamp_now().as_millis(), + timestamp: crate::client::unix_timestamp_now().as_millis(), inclusion_state: InclusionState::Pending, incoming: false, note: options.and_then(|o| o.note), From d2217152e144bec4e408bfb926af47d5ed7e9f92 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Wed, 20 Sep 2023 14:11:07 -0400 Subject: [PATCH 3/3] wasm --- sdk/src/client/core.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/client/core.rs b/sdk/src/client/core.rs index b38a5a2a1b..fba62c7096 100644 --- a/sdk/src/client/core.rs +++ b/sdk/src/client/core.rs @@ -107,7 +107,7 @@ impl ClientInner { // request the node info every time, so we don't create invalid transactions/blocks. #[cfg(target_family = "wasm")] { - let current_time = crate::utils::unix_timestamp_now().as_secs() as u32; + let current_time = crate::client::unix_timestamp_now().as_secs() as u32; if let Some(last_sync) = *self.last_sync.lock().await { if current_time < last_sync { return Ok(self.network_info.read().await.clone());