From 413b9349d0d5429a6b99f36b0d7c028dc568c976 Mon Sep 17 00:00:00 2001 From: Neotamandua <107320179+Neotamandua@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:24:57 +0200 Subject: [PATCH] rusk-wallet: reorder imports to align with convention --- rusk-wallet/src/bin/command.rs | 24 ++++---- rusk-wallet/src/bin/command/history.rs | 4 +- rusk-wallet/src/bin/config.rs | 3 +- rusk-wallet/src/bin/interactive.rs | 17 ++---- .../src/bin/interactive/command_menu.rs | 16 +++-- rusk-wallet/src/bin/io/args.rs | 6 +- rusk-wallet/src/bin/io/prompt.rs | 21 +++---- rusk-wallet/src/bin/main.rs | 17 +++--- rusk-wallet/src/bin/settings.rs | 8 +-- rusk-wallet/src/cache.rs | 4 +- rusk-wallet/src/clients.rs | 42 ++++++-------- rusk-wallet/src/clients/sync.rs | 3 +- rusk-wallet/src/dat.rs | 3 +- rusk-wallet/src/error.rs | 5 +- rusk-wallet/src/gql.rs | 2 +- rusk-wallet/src/lib.rs | 19 +++--- rusk-wallet/src/store.rs | 4 +- rusk-wallet/src/wallet.rs | 58 +++++++++---------- rusk-wallet/src/wallet/address.rs | 7 ++- rusk-wallet/src/wallet/transaction.rs | 23 ++++---- 20 files changed, 128 insertions(+), 158 deletions(-) diff --git a/rusk-wallet/src/bin/command.rs b/rusk-wallet/src/bin/command.rs index 3f17df8843..f5eeb448fa 100644 --- a/rusk-wallet/src/bin/command.rs +++ b/rusk-wallet/src/bin/command.rs @@ -8,27 +8,25 @@ mod history; pub use history::TransactionHistory; +use std::fmt; +use std::path::PathBuf; + use clap::Subcommand; -use execution_core::{ - stake::StakeData, transfer::data::ContractCall, BlsScalar, - CONTRACT_ID_BYTES, -}; -use rusk_wallet::{ - currency::{Dusk, Lux}, - gas::{ - Gas, DEFAULT_LIMIT_CALL, DEFAULT_LIMIT_DEPLOYMENT, - DEFAULT_LIMIT_TRANSFER, DEFAULT_PRICE, MIN_PRICE_DEPLOYMENT, - }, - Address, Error, Profile, Wallet, EPOCH, MAX_PROFILES, +use execution_core::stake::StakeData; +use execution_core::transfer::data::ContractCall; +use execution_core::{BlsScalar, CONTRACT_ID_BYTES}; +use rusk_wallet::currency::{Dusk, Lux}; +use rusk_wallet::gas::{ + Gas, DEFAULT_LIMIT_CALL, DEFAULT_LIMIT_DEPLOYMENT, DEFAULT_LIMIT_TRANSFER, + DEFAULT_PRICE, MIN_PRICE_DEPLOYMENT, }; +use rusk_wallet::{Address, Error, Profile, Wallet, EPOCH, MAX_PROFILES}; use wallet_core::BalanceInfo; use crate::io::prompt; use crate::settings::Settings; use crate::{WalletFile, WalletPath}; -use std::{fmt, path::PathBuf}; - /// Commands that can be run against the Dusk wallet #[allow(clippy::large_enum_variant)] #[derive(PartialEq, Eq, Hash, Clone, Subcommand, Debug)] diff --git a/rusk-wallet/src/bin/command/history.rs b/rusk-wallet/src/bin/command/history.rs index 87fb6e3391..4f640aa88c 100644 --- a/rusk-wallet/src/bin/command/history.rs +++ b/rusk-wallet/src/bin/command/history.rs @@ -8,10 +8,10 @@ use std::collections::hash_map::Entry; use std::collections::HashMap; use std::fmt::{self, Display}; +use execution_core::transfer::Transaction; +use execution_core::{dusk, from_dusk}; use rusk_wallet::{BlockTransaction, DecodedNote, GraphQL}; -use execution_core::{dusk, from_dusk, transfer::Transaction}; - use crate::io::{self}; use crate::settings::Settings; diff --git a/rusk-wallet/src/bin/config.rs b/rusk-wallet/src/bin/config.rs index 1fdadbec2e..2e266619ba 100644 --- a/rusk-wallet/src/bin/config.rs +++ b/rusk-wallet/src/bin/config.rs @@ -4,9 +4,10 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use serde::Deserialize; use std::collections::HashMap; use std::path::Path; + +use serde::Deserialize; use url::Url; use crate::Error; diff --git a/rusk-wallet/src/bin/interactive.rs b/rusk-wallet/src/bin/interactive.rs index fbcc7a4b1f..7e954bfd1a 100644 --- a/rusk-wallet/src/bin/interactive.rs +++ b/rusk-wallet/src/bin/interactive.rs @@ -10,18 +10,13 @@ use std::fmt::Display; use bip39::{Language, Mnemonic, MnemonicType}; use inquire::{InquireError, Select}; +use rusk_wallet::currency::Dusk; +use rusk_wallet::dat::{DatFileVersion, LATEST_VERSION}; +use rusk_wallet::{Address, Error, Profile, Wallet, WalletPath, MAX_PROFILES}; -use rusk_wallet::{ - currency::Dusk, - dat::{DatFileVersion, LATEST_VERSION}, - Address, Error, Profile, Wallet, WalletPath, MAX_PROFILES, -}; - -use crate::{ - io::{self, prompt}, - settings::Settings, - Command, GraphQL, RunResult, WalletFile, -}; +use crate::io::{self, prompt}; +use crate::settings::Settings; +use crate::{Command, GraphQL, RunResult, WalletFile}; /// Run the interactive UX loop with a loaded wallet pub(crate) async fn run_loop( diff --git a/rusk-wallet/src/bin/interactive/command_menu.rs b/rusk-wallet/src/bin/interactive/command_menu.rs index 79f6c62a37..bacc4a2a34 100644 --- a/rusk-wallet/src/bin/interactive/command_menu.rs +++ b/rusk-wallet/src/bin/interactive/command_menu.rs @@ -8,18 +8,16 @@ use std::fmt::Display; use execution_core::transfer::data::MAX_MEMO_SIZE; use inquire::{InquireError, Select}; -use rusk_wallet::{ - currency::Dusk, - gas::{ - self, DEFAULT_LIMIT_CALL, DEFAULT_LIMIT_STAKE, DEFAULT_LIMIT_TRANSFER, - DEFAULT_PRICE, GAS_PER_DEPLOY_BYTE, MIN_PRICE_DEPLOYMENT, - }, - Address, Wallet, MAX_FUNCTION_NAME_SIZE, +use rusk_wallet::currency::Dusk; +use rusk_wallet::gas::{ + self, DEFAULT_LIMIT_CALL, DEFAULT_LIMIT_STAKE, DEFAULT_LIMIT_TRANSFER, + DEFAULT_PRICE, GAS_PER_DEPLOY_BYTE, MIN_PRICE_DEPLOYMENT, }; - -use crate::{prompt, settings::Settings, Command, WalletFile}; +use rusk_wallet::{Address, Wallet, MAX_FUNCTION_NAME_SIZE}; use super::ProfileOp; +use crate::settings::Settings; +use crate::{prompt, Command, WalletFile}; /// The command-menu items #[derive(PartialEq, Eq, Hash, Clone, Debug)] diff --git a/rusk-wallet/src/bin/io/args.rs b/rusk-wallet/src/bin/io/args.rs index 829de1338d..ab9aaba143 100644 --- a/rusk-wallet/src/bin/io/args.rs +++ b/rusk-wallet/src/bin/io/args.rs @@ -4,10 +4,12 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. +use std::path::PathBuf; + +use clap::{arg, Parser}; + use crate::settings::{LogFormat, LogLevel}; use crate::Command; -use clap::{arg, Parser}; -use std::path::PathBuf; #[derive(Parser, Debug)] #[command( diff --git a/rusk-wallet/src/bin/io/prompt.rs b/rusk-wallet/src/bin/io/prompt.rs index 38fa06bb78..43a89ab87c 100644 --- a/rusk-wallet/src/bin/io/prompt.rs +++ b/rusk-wallet/src/bin/io/prompt.rs @@ -5,31 +5,26 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use std::fmt::Display; +use std::io::stdout; use std::path::PathBuf; +use std::println; use std::str::FromStr; -use std::{io::stdout, println}; - -use crossterm::{ - cursor::{Hide, Show}, - ExecutableCommand, -}; use anyhow::Result; use bip39::{ErrorKind, Language, Mnemonic}; +use crossterm::cursor::{Hide, Show}; +use crossterm::ExecutableCommand; use execution_core::stake::MINIMUM_STAKE; - use inquire::ui::RenderConfig; use inquire::validator::Validation; use inquire::{ Confirm, CustomType, InquireError, Password, PasswordDisplayMode, Select, Text, }; -use rusk_wallet::{ - currency::{Dusk, Lux}, - dat::DatFileVersion, - gas::{self, MempoolGasPrices}, - Address, Error, MAX_CONVERTIBLE, MIN_CONVERTIBLE, -}; +use rusk_wallet::currency::{Dusk, Lux}; +use rusk_wallet::dat::DatFileVersion; +use rusk_wallet::gas::{self, MempoolGasPrices}; +use rusk_wallet::{Address, Error, MAX_CONVERTIBLE, MIN_CONVERTIBLE}; use sha2::{Digest, Sha256}; pub(crate) fn ask_pwd(msg: &str) -> Result { diff --git a/rusk-wallet/src/bin/main.rs b/rusk-wallet/src/bin/main.rs index 3fc0e6c5a5..445d99d521 100644 --- a/rusk-wallet/src/bin/main.rs +++ b/rusk-wallet/src/bin/main.rs @@ -12,27 +12,26 @@ mod settings; pub(crate) use command::{Command, RunResult}; +use std::fs::{self, File}; +use std::io::Write; + use bip39::{Language, Mnemonic, MnemonicType}; use clap::Parser; use inquire::InquireError; use rocksdb::ErrorKind; +use rusk_wallet::currency::Dusk; +use rusk_wallet::dat::{self, LATEST_VERSION}; +use rusk_wallet::{ + Error, GraphQL, Profile, SecureWalletFile, Wallet, WalletPath, EPOCH, +}; use tracing::{error, info, warn, Level}; use crate::command::TransactionHistory; use crate::settings::{LogFormat, Settings}; -use rusk_wallet::{ - currency::Dusk, - dat::{self, LATEST_VERSION}, - Error, GraphQL, Profile, SecureWalletFile, Wallet, WalletPath, EPOCH, -}; - use config::Config; use io::{prompt, status, WalletArgs}; -use std::fs::{self, File}; -use std::io::Write; - #[derive(Debug, Clone)] pub(crate) struct WalletFile { path: WalletPath, diff --git a/rusk-wallet/src/bin/settings.rs b/rusk-wallet/src/bin/settings.rs index b5c7e15c15..c18b4e75d9 100644 --- a/rusk-wallet/src/bin/settings.rs +++ b/rusk-wallet/src/bin/settings.rs @@ -4,16 +4,16 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::config::Network; -use crate::io::WalletArgs; - -use rusk_wallet::{Error, RuesHttpClient}; use std::fmt; use std::path::PathBuf; +use rusk_wallet::{Error, RuesHttpClient}; use tracing::Level; use url::Url; +use crate::config::Network; +use crate::io::WalletArgs; + #[derive(clap::ValueEnum, Debug, Clone)] pub(crate) enum LogFormat { Json, diff --git a/rusk-wallet/src/cache.rs b/rusk-wallet/src/cache.rs index 0f005f03fc..813241ab1a 100644 --- a/rusk-wallet/src/cache.rs +++ b/rusk-wallet/src/cache.rs @@ -12,8 +12,8 @@ use execution_core::transfer::phoenix::NoteLeaf; use rocksdb::{DBWithThreadMode, MultiThreaded, Options}; use super::*; - -use crate::{clients::TREE_LEAF, error::Error}; +use crate::clients::TREE_LEAF; +use crate::error::Error; type DB = DBWithThreadMode; diff --git a/rusk-wallet/src/clients.rs b/rusk-wallet/src/clients.rs index 3d13e5ca83..2836efa928 100644 --- a/rusk-wallet/src/clients.rs +++ b/rusk-wallet/src/clients.rs @@ -6,38 +6,30 @@ mod sync; +use std::path::Path; +use std::sync::{Arc, Mutex}; + use dusk_bytes::Serializable; -use execution_core::{ - signatures::bls::PublicKey as BlsPublicKey, - transfer::{ - moonlight::AccountData, - phoenix::{Note, NoteLeaf, Prove}, - Transaction, - }, - Error as ExecutionCoreError, -}; +use execution_core::signatures::bls::PublicKey as BlsPublicKey; +use execution_core::transfer::moonlight::AccountData; +use execution_core::transfer::phoenix::{Note, NoteLeaf, Prove}; +use execution_core::transfer::Transaction; +use execution_core::Error as ExecutionCoreError; use flume::Receiver; use rues::RuesHttpClient; -use tokio::{ - task::JoinHandle, - time::{sleep, Duration}, -}; -use wallet_core::{ - keys::{derive_phoenix_pk, derive_phoenix_sk, derive_phoenix_vk}, - pick_notes, +use tokio::task::JoinHandle; +use tokio::time::{sleep, Duration}; +use wallet_core::keys::{ + derive_phoenix_pk, derive_phoenix_sk, derive_phoenix_vk, }; +use wallet_core::pick_notes; use zeroize::Zeroize; -use std::{ - path::Path, - sync::{Arc, Mutex}, -}; - use self::sync::sync_db; - -use super::{cache::Cache, *}; - -use crate::{store::LocalStore, Error, MAX_PROFILES}; +use super::cache::Cache; +use super::*; +use crate::store::LocalStore; +use crate::{Error, MAX_PROFILES}; const TRANSFER_CONTRACT: &str = "0100000000000000000000000000000000000000000000000000000000000000"; diff --git a/rusk-wallet/src/clients/sync.rs b/rusk-wallet/src/clients/sync.rs index d5a44e5a1b..8ebc38fae5 100644 --- a/rusk-wallet/src/clients/sync.rs +++ b/rusk-wallet/src/clients/sync.rs @@ -7,11 +7,10 @@ use futures::StreamExt; use rues::CONTRACTS_TARGET; +use super::*; use crate::clients::{Cache, TRANSFER_CONTRACT}; use crate::Error; -use super::*; - pub(crate) async fn sync_db( client: &RuesHttpClient, cache: &Cache, diff --git a/rusk-wallet/src/dat.rs b/rusk-wallet/src/dat.rs index fe61bbe79b..c0a243e46d 100644 --- a/rusk-wallet/src/dat.rs +++ b/rusk-wallet/src/dat.rs @@ -12,8 +12,7 @@ use std::io::Read; use wallet_core::Seed; use crate::crypto::decrypt; -use crate::Error; -use crate::WalletPath; +use crate::{Error, WalletPath}; /// Binary prefix for old Dusk wallet files pub const OLD_MAGIC: u32 = 0x1d0c15; diff --git a/rusk-wallet/src/error.rs b/rusk-wallet/src/error.rs index 802c4e763d..8b39a919e3 100644 --- a/rusk-wallet/src/error.rs +++ b/rusk-wallet/src/error.rs @@ -4,11 +4,12 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use inquire::InquireError; -use rand::Error as RngError; use std::io; use std::str::Utf8Error; +use inquire::InquireError; +use rand::Error as RngError; + use crate::gql::GraphQLError; /// Errors returned by this library diff --git a/rusk-wallet/src/gql.rs b/rusk-wallet/src/gql.rs index b6fe91e86d..868c92f783 100644 --- a/rusk-wallet/src/gql.rs +++ b/rusk-wallet/src/gql.rs @@ -9,10 +9,10 @@ //! graphql schema use execution_core::transfer::Transaction; +use serde::Deserialize; use tokio::time::{sleep, Duration}; use crate::{Error, RuesHttpClient}; -use serde::Deserialize; /// GraphQL is a helper struct that aggregates all queries done /// to the Dusk GraphQL database. diff --git a/rusk-wallet/src/lib.rs b/rusk-wallet/src/lib.rs index 26d2fcb7e4..c024563acb 100644 --- a/rusk-wallet/src/lib.rs +++ b/rusk-wallet/src/lib.rs @@ -27,24 +27,19 @@ pub mod currency; pub mod dat; pub mod gas; -pub use rues::RuesHttpClient; - pub use error::Error; +pub use gql::{BlockTransaction, GraphQL}; +pub use rues::RuesHttpClient; pub use wallet::{ Address, DecodedNote, Profile, SecureWalletFile, Wallet, WalletPath, }; -pub use gql::{BlockTransaction, GraphQL}; - -use execution_core::{ - dusk, from_dusk, - stake::StakeData, - transfer::phoenix::{ - ArchivedNoteLeaf, Note, NoteOpening, PublicKey as PhoenixPublicKey, - SecretKey as PhoenixSecretKey, ViewKey as PhoenixViewKey, - }, - BlsScalar, +use execution_core::stake::StakeData; +use execution_core::transfer::phoenix::{ + ArchivedNoteLeaf, Note, NoteOpening, PublicKey as PhoenixPublicKey, + SecretKey as PhoenixSecretKey, ViewKey as PhoenixViewKey, }; +use execution_core::{dusk, from_dusk, BlsScalar}; use currency::Dusk; diff --git a/rusk-wallet/src/store.rs b/rusk-wallet/src/store.rs index cda61ba17b..e846cb9151 100644 --- a/rusk-wallet/src/store.rs +++ b/rusk-wallet/src/store.rs @@ -4,10 +4,10 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::clients::State; - use wallet_core::Seed; +use crate::clients::State; + /// Provides a valid wallet seed to dusk_wallet_core #[derive(Clone)] pub(crate) struct LocalStore { diff --git a/rusk-wallet/src/wallet.rs b/rusk-wallet/src/wallet.rs index 46b036173d..ee2999bcc5 100644 --- a/rusk-wallet/src/wallet.rs +++ b/rusk-wallet/src/wallet.rs @@ -17,40 +17,34 @@ use std::path::{Path, PathBuf}; use bip39::{Language, Mnemonic, Seed}; use dusk_bytes::Serializable; +use execution_core::signatures::bls::{ + PublicKey as BlsPublicKey, SecretKey as BlsSecretKey, +}; +use execution_core::stake::StakeData; +use execution_core::transfer::phoenix::{ + Note, NoteLeaf, PublicKey as PhoenixPublicKey, + SecretKey as PhoenixSecretKey, ViewKey as PhoenixViewKey, +}; +use execution_core::{BlsScalar, CONTRACT_ID_BYTES}; use serde::Serialize; +use wallet_core::prelude::keys::{ + derive_bls_pk, derive_bls_sk, derive_phoenix_pk, derive_phoenix_sk, + derive_phoenix_vk, +}; +use wallet_core::{phoenix_balance, BalanceInfo}; use zeroize::Zeroize; -use execution_core::{ - signatures::bls::{PublicKey as BlsPublicKey, SecretKey as BlsSecretKey}, - stake::StakeData, - transfer::phoenix::{ - Note, NoteLeaf, PublicKey as PhoenixPublicKey, - SecretKey as PhoenixSecretKey, ViewKey as PhoenixViewKey, - }, - BlsScalar, CONTRACT_ID_BYTES, +use crate::clients::State; +use crate::crypto::encrypt; +use crate::currency::Dusk; +use crate::dat::{ + self, version_bytes, DatFileVersion, FILE_TYPE, LATEST_VERSION, MAGIC, + RESERVED, }; -use wallet_core::{ - phoenix_balance, - prelude::keys::{ - derive_bls_pk, derive_bls_sk, derive_phoenix_pk, derive_phoenix_sk, - derive_phoenix_vk, - }, - BalanceInfo, -}; - use crate::gas::MempoolGasPrices; -use crate::{ - clients::State, - crypto::encrypt, - currency::Dusk, - dat::{ - self, version_bytes, DatFileVersion, FILE_TYPE, LATEST_VERSION, MAGIC, - RESERVED, - }, - rues::RuesHttpClient, - store::LocalStore, - Error, -}; +use crate::rues::RuesHttpClient; +use crate::store::LocalStore; +use crate::Error; /// The interface to the Dusk Network /// @@ -652,7 +646,8 @@ struct BlsKeyPair { } mod base64 { - use base64::{engine::general_purpose::STANDARD as BASE64, Engine}; + use base64::engine::general_purpose::STANDARD as BASE64; + use base64::Engine; use serde::{Serialize, Serializer}; pub fn serialize(v: &[u8], s: S) -> Result { @@ -664,9 +659,10 @@ mod base64 { #[cfg(test)] mod tests { - use super::*; use tempfile::tempdir; + use super::*; + const TEST_ADDR: &str = "2w7fRQW23Jn9Bgm1GQW9eC2bD9U883dAwqP7HAr2F8g1syzPQaPYrxSyyVZ81yDS5C1rv9L8KjdPBsvYawSx3QCW"; #[derive(Debug, Clone)] diff --git a/rusk-wallet/src/wallet/address.rs b/rusk-wallet/src/wallet/address.rs index 1e55903ca1..6724807576 100644 --- a/rusk-wallet/src/wallet/address.rs +++ b/rusk-wallet/src/wallet/address.rs @@ -4,14 +4,15 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. +use std::fmt; use std::hash::Hasher; -use std::{fmt, str::FromStr}; +use std::str::FromStr; + +use dusk_bytes::{DeserializableSlice, Serializable}; use super::*; use crate::Error; -use dusk_bytes::{DeserializableSlice, Serializable}; - /// Address to perform a transaction with. #[derive(Clone, Eq)] #[allow(missing_docs)] diff --git a/rusk-wallet/src/wallet/transaction.rs b/rusk-wallet/src/wallet/transaction.rs index 3f76db610e..1484fb9ab6 100644 --- a/rusk-wallet/src/wallet/transaction.rs +++ b/rusk-wallet/src/wallet/transaction.rs @@ -6,26 +6,25 @@ use std::fmt::Debug; +use execution_core::signatures::bls::PublicKey as BlsPublicKey; +use execution_core::transfer::data::TransactionData; +use execution_core::transfer::phoenix::PublicKey as PhoenixPublicKey; +use execution_core::transfer::Transaction; use rand::rngs::StdRng; use rand::SeedableRng; -use zeroize::Zeroize; - -use execution_core::{ - signatures::bls::PublicKey as BlsPublicKey, - transfer::{ - data::TransactionData, phoenix::PublicKey as PhoenixPublicKey, - Transaction, - }, -}; use wallet_core::transaction::{ moonlight, moonlight_deployment, moonlight_stake, moonlight_stake_reward, moonlight_to_phoenix, moonlight_unstake, phoenix, phoenix_deployment, phoenix_stake, phoenix_stake_reward, phoenix_to_moonlight, phoenix_unstake, }; +use zeroize::Zeroize; -use crate::{clients::Prover, currency::Dusk, gas::Gas, Error}; - -use super::{file::SecureWalletFile, Wallet}; +use super::file::SecureWalletFile; +use super::Wallet; +use crate::clients::Prover; +use crate::currency::Dusk; +use crate::gas::Gas; +use crate::Error; impl Wallet { /// Transfers funds between shielded addresses.