From 6dd023a71c8d781ea54db6227ede9452ba558ad9 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Fri, 15 Nov 2024 18:04:19 +0000 Subject: [PATCH] chore: cargo fmt --- crates/cdk-axum/src/lib.rs | 5 +--- crates/cdk-axum/src/router_handlers.rs | 6 ++-- crates/cdk-axum/src/ws/handler.rs | 3 +- crates/cdk-axum/src/ws/mod.rs | 6 ++-- crates/cdk-axum/src/ws/subscribe.rs | 13 ++++----- crates/cdk-axum/src/ws/unsubscribe.rs | 4 ++- .../src/sub_commands/create_request.rs | 12 ++++---- .../src/sub_commands/list_mint_proofs.rs | 8 ++---- .../cdk-cli/src/sub_commands/pay_request.rs | 12 ++++---- .../src/bin/fake_wallet.rs | 3 +- .../src/init_fake_wallet.rs | 18 +++++------- .../cdk-integration-tests/src/init_regtest.rs | 27 ++++++++++-------- .../tests/fake_wallet.rs | 19 ++++++------- crates/cdk-integration-tests/tests/mint.rs | 7 +++-- crates/cdk-integration-tests/tests/regtest.rs | 26 ++++++++--------- crates/cdk-mintd/src/main.rs | 8 ++---- crates/cdk-mintd/src/setup.rs | 18 ++++++------ crates/cdk/src/error.rs | 4 ++- crates/cdk/src/mint/builder.rs | 21 +++++++------- crates/cdk/src/mint/check_spendable.rs | 3 +- crates/cdk/src/mint/info.rs | 3 +- crates/cdk/src/mint/keysets.rs | 3 +- crates/cdk/src/mint/melt.rs | 20 ++++++------- crates/cdk/src/mint/mint_nut04.rs | 6 ++-- crates/cdk/src/mint/mod.rs | 3 +- crates/cdk/src/mint/swap.rs | 5 ++-- crates/cdk/src/nuts/nut17/mod.rs | 25 ++++++++--------- crates/cdk/src/nuts/nut17/on_subscription.rs | 11 ++++---- crates/cdk/src/nuts/nut18.rs | 14 ++++------ crates/cdk/src/pub_sub/index.rs | 9 +++--- crates/cdk/src/pub_sub/mod.rs | 28 ++++++++----------- crates/cdk/src/types.rs | 9 ++---- crates/cdk/src/wallet/balance.rs | 3 +- crates/cdk/src/wallet/keysets.rs | 7 ++--- crates/cdk/src/wallet/melt.rs | 17 ++++++----- crates/cdk/src/wallet/mint.rs | 18 ++++++------ crates/cdk/src/wallet/mod.rs | 3 +- crates/cdk/src/wallet/proofs.rs | 11 ++++---- crates/cdk/src/wallet/receive.rs | 21 +++++++------- crates/cdk/src/wallet/send.rs | 11 +++----- crates/cdk/src/wallet/swap.rs | 15 +++------- 41 files changed, 213 insertions(+), 252 deletions(-) diff --git a/crates/cdk-axum/src/lib.rs b/crates/cdk-axum/src/lib.rs index a431f0d6..6c0c2423 100644 --- a/crates/cdk-axum/src/lib.rs +++ b/crates/cdk-axum/src/lib.rs @@ -26,12 +26,10 @@ mod swagger_imports { pub use cdk::nuts::nut01::{Keys, KeysResponse, PublicKey, SecretKey}; pub use cdk::nuts::nut02::{Id, KeySet, KeySetInfo, KeySetVersion, KeysetResponse}; pub use cdk::nuts::nut03::{SwapRequest, SwapResponse}; - pub use cdk::nuts::nut04; pub use cdk::nuts::nut04::{ MintBolt11Request, MintBolt11Response, MintMethodSettings, MintQuoteBolt11Request, MintQuoteBolt11Response, }; - pub use cdk::nuts::nut05; pub use cdk::nuts::nut05::{ MeltBolt11Request, MeltMethodSettings, MeltQuoteBolt11Request, MeltQuoteBolt11Response, }; @@ -41,9 +39,8 @@ mod swagger_imports { pub use cdk::nuts::nut11::P2PKWitness; pub use cdk::nuts::nut12::{BlindSignatureDleq, ProofDleq}; pub use cdk::nuts::nut14::HTLCWitness; - pub use cdk::nuts::nut15; pub use cdk::nuts::nut15::{Mpp, MppMethodSettings}; - pub use cdk::nuts::{MeltQuoteState, MintQuoteState}; + pub use cdk::nuts::{nut04, nut05, nut15, MeltQuoteState, MintQuoteState}; } #[cfg(feature = "swagger")] diff --git a/crates/cdk-axum/src/router_handlers.rs b/crates/cdk-axum/src/router_handlers.rs index d3947d40..29300be8 100644 --- a/crates/cdk-axum/src/router_handlers.rs +++ b/crates/cdk-axum/src/router_handlers.rs @@ -1,5 +1,6 @@ use anyhow::Result; -use axum::extract::{ws::WebSocketUpgrade, Json, Path, State}; +use axum::extract::ws::WebSocketUpgrade; +use axum::extract::{Json, Path, State}; use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; use cdk::error::ErrorResponse; @@ -13,7 +14,8 @@ use cdk::util::unix_time; use cdk::Error; use paste::paste; -use crate::{ws::main_websocket, MintState}; +use crate::ws::main_websocket; +use crate::MintState; macro_rules! post_cache_wrapper { ($handler:ident, $request_type:ty, $response_type:ty) => { diff --git a/crates/cdk-axum/src/ws/handler.rs b/crates/cdk-axum/src/ws/handler.rs index ea1ba3ae..b2298551 100644 --- a/crates/cdk-axum/src/ws/handler.rs +++ b/crates/cdk-axum/src/ws/handler.rs @@ -1,6 +1,7 @@ -use super::{WsContext, WsError, JSON_RPC_VERSION}; use serde::Serialize; +use super::{WsContext, WsError, JSON_RPC_VERSION}; + impl From for WsErrorResponse { fn from(val: WsError) -> Self { let (id, message) = match val { diff --git a/crates/cdk-axum/src/ws/mod.rs b/crates/cdk-axum/src/ws/mod.rs index 2af2156e..4b71368e 100644 --- a/crates/cdk-axum/src/ws/mod.rs +++ b/crates/cdk-axum/src/ws/mod.rs @@ -1,13 +1,15 @@ -use crate::MintState; +use std::collections::HashMap; + use axum::extract::ws::{Message, WebSocket}; use cdk::nuts::nut17::{NotificationPayload, SubId}; use futures::StreamExt; use handler::{WsHandle, WsNotification}; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; use subscribe::Notification; use tokio::sync::mpsc; +use crate::MintState; + mod error; mod handler; mod subscribe; diff --git a/crates/cdk-axum/src/ws/subscribe.rs b/crates/cdk-axum/src/ws/subscribe.rs index 0a7de158..06505eb7 100644 --- a/crates/cdk-axum/src/ws/subscribe.rs +++ b/crates/cdk-axum/src/ws/subscribe.rs @@ -1,11 +1,8 @@ -use super::{ - handler::{WsHandle, WsNotification}, - WsContext, WsError, JSON_RPC_VERSION, -}; -use cdk::{ - nuts::nut17::{NotificationPayload, Params}, - pub_sub::SubId, -}; +use cdk::nuts::nut17::{NotificationPayload, Params}; +use cdk::pub_sub::SubId; + +use super::handler::{WsHandle, WsNotification}; +use super::{WsContext, WsError, JSON_RPC_VERSION}; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Method(Params); diff --git a/crates/cdk-axum/src/ws/unsubscribe.rs b/crates/cdk-axum/src/ws/unsubscribe.rs index 421abbae..8a8d3660 100644 --- a/crates/cdk-axum/src/ws/unsubscribe.rs +++ b/crates/cdk-axum/src/ws/unsubscribe.rs @@ -1,6 +1,8 @@ -use super::{handler::WsHandle, WsContext, WsError}; use cdk::pub_sub::SubId; +use super::handler::WsHandle; +use super::{WsContext, WsError}; + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Method { #[serde(rename = "subId")] diff --git a/crates/cdk-cli/src/sub_commands/create_request.rs b/crates/cdk-cli/src/sub_commands/create_request.rs index de362be5..a973d794 100644 --- a/crates/cdk-cli/src/sub_commands/create_request.rs +++ b/crates/cdk-cli/src/sub_commands/create_request.rs @@ -1,13 +1,11 @@ use anyhow::Result; -use cdk::{ - nuts::{ - nut18::TransportType, CurrencyUnit, PaymentRequest, PaymentRequestPayload, Token, Transport, - }, - wallet::MultiMintWallet, -}; +use cdk::nuts::nut18::TransportType; +use cdk::nuts::{CurrencyUnit, PaymentRequest, PaymentRequestPayload, Token, Transport}; +use cdk::wallet::MultiMintWallet; use clap::Args; +use nostr_sdk::nips::nip19::Nip19Profile; use nostr_sdk::prelude::*; -use nostr_sdk::{nips::nip19::Nip19Profile, Client as NostrClient, Filter, Keys, ToBech32}; +use nostr_sdk::{Client as NostrClient, Filter, Keys, ToBech32}; #[derive(Args)] pub struct CreateRequestSubCommand { diff --git a/crates/cdk-cli/src/sub_commands/list_mint_proofs.rs b/crates/cdk-cli/src/sub_commands/list_mint_proofs.rs index f4e8a4d6..754c301e 100644 --- a/crates/cdk-cli/src/sub_commands/list_mint_proofs.rs +++ b/crates/cdk-cli/src/sub_commands/list_mint_proofs.rs @@ -1,11 +1,9 @@ use std::collections::BTreeMap; use anyhow::Result; -use cdk::{ - mint_url::MintUrl, - nuts::{CurrencyUnit, Proof}, - wallet::multi_mint_wallet::MultiMintWallet, -}; +use cdk::mint_url::MintUrl; +use cdk::nuts::{CurrencyUnit, Proof}; +use cdk::wallet::multi_mint_wallet::MultiMintWallet; pub async fn proofs(multi_mint_wallet: &MultiMintWallet) -> Result<()> { list_proofs(multi_mint_wallet).await?; diff --git a/crates/cdk-cli/src/sub_commands/pay_request.rs b/crates/cdk-cli/src/sub_commands/pay_request.rs index 308df1d0..a003072c 100644 --- a/crates/cdk-cli/src/sub_commands/pay_request.rs +++ b/crates/cdk-cli/src/sub_commands/pay_request.rs @@ -1,13 +1,13 @@ use std::io::{self, Write}; use anyhow::{anyhow, Result}; -use cdk::{ - amount::SplitTarget, - nuts::{nut18::TransportType, PaymentRequest, PaymentRequestPayload}, - wallet::{MultiMintWallet, SendKind}, -}; +use cdk::amount::SplitTarget; +use cdk::nuts::nut18::TransportType; +use cdk::nuts::{PaymentRequest, PaymentRequestPayload}; +use cdk::wallet::{MultiMintWallet, SendKind}; use clap::Args; -use nostr_sdk::{nips::nip19::Nip19Profile, Client as NostrClient, EventBuilder, FromBech32, Keys}; +use nostr_sdk::nips::nip19::Nip19Profile; +use nostr_sdk::{Client as NostrClient, EventBuilder, FromBech32, Keys}; use reqwest::Client; #[derive(Args)] diff --git a/crates/cdk-integration-tests/src/bin/fake_wallet.rs b/crates/cdk-integration-tests/src/bin/fake_wallet.rs index 162dc7ee..9d83e96c 100644 --- a/crates/cdk-integration-tests/src/bin/fake_wallet.rs +++ b/crates/cdk-integration-tests/src/bin/fake_wallet.rs @@ -2,7 +2,8 @@ use std::env; use anyhow::Result; use cdk::cdk_database::mint_memory::MintMemoryDatabase; -use cdk_integration_tests::{init_fake_wallet::start_fake_mint, init_regtest::get_temp_dir}; +use cdk_integration_tests::init_fake_wallet::start_fake_mint; +use cdk_integration_tests::init_regtest::get_temp_dir; use cdk_redb::MintRedbDatabase; use cdk_sqlite::MintSqliteDatabase; diff --git a/crates/cdk-integration-tests/src/init_fake_wallet.rs b/crates/cdk-integration-tests/src/init_fake_wallet.rs index 8fbe7784..d3216b82 100644 --- a/crates/cdk-integration-tests/src/init_fake_wallet.rs +++ b/crates/cdk-integration-tests/src/init_fake_wallet.rs @@ -1,17 +1,13 @@ -use std::{ - collections::{HashMap, HashSet}, - sync::Arc, -}; +use std::collections::{HashMap, HashSet}; +use std::sync::Arc; use anyhow::Result; use axum::Router; -use cdk::{ - cdk_database::{self, MintDatabase}, - cdk_lightning::MintLightning, - mint::FeeReserve, - nuts::CurrencyUnit, - types::LnKey, -}; +use cdk::cdk_database::{self, MintDatabase}; +use cdk::cdk_lightning::MintLightning; +use cdk::mint::FeeReserve; +use cdk::nuts::CurrencyUnit; +use cdk::types::LnKey; use cdk_fake_wallet::FakeWallet; use tokio::sync::Notify; use tower_http::cors::CorsLayer; diff --git a/crates/cdk-integration-tests/src/init_regtest.rs b/crates/cdk-integration-tests/src/init_regtest.rs index 92d147b5..525f8e4e 100644 --- a/crates/cdk-integration-tests/src/init_regtest.rs +++ b/crates/cdk-integration-tests/src/init_regtest.rs @@ -1,20 +1,23 @@ -use std::{collections::HashMap, env, path::PathBuf, sync::Arc}; +use std::collections::HashMap; +use std::env; +use std::path::PathBuf; +use std::sync::Arc; use anyhow::Result; use axum::Router; use bip39::Mnemonic; -use cdk::{ - cdk_database::{self, MintDatabase}, - cdk_lightning::MintLightning, - mint::{FeeReserve, Mint}, - nuts::{CurrencyUnit, MintInfo}, - types::{LnKey, QuoteTTL}, -}; +use cdk::cdk_database::{self, MintDatabase}; +use cdk::cdk_lightning::MintLightning; +use cdk::mint::{FeeReserve, Mint}; +use cdk::nuts::{CurrencyUnit, MintInfo}; +use cdk::types::{LnKey, QuoteTTL}; use cdk_cln::Cln as CdkCln; -use ln_regtest_rs::{ - bitcoin_client::BitcoinClient, bitcoind::Bitcoind, cln::Clnd, cln_client::ClnClient, lnd::Lnd, - lnd_client::LndClient, -}; +use ln_regtest_rs::bitcoin_client::BitcoinClient; +use ln_regtest_rs::bitcoind::Bitcoind; +use ln_regtest_rs::cln::Clnd; +use ln_regtest_rs::cln_client::ClnClient; +use ln_regtest_rs::lnd::Lnd; +use ln_regtest_rs::lnd_client::LndClient; use tokio::sync::Notify; use tower_http::cors::CorsLayer; use tracing_subscriber::EnvFilter; diff --git a/crates/cdk-integration-tests/tests/fake_wallet.rs b/crates/cdk-integration-tests/tests/fake_wallet.rs index 884e63d1..cf0ea1be 100644 --- a/crates/cdk-integration-tests/tests/fake_wallet.rs +++ b/crates/cdk-integration-tests/tests/fake_wallet.rs @@ -1,18 +1,15 @@ -use std::{sync::Arc, time::Duration}; +use std::sync::Arc; +use std::time::Duration; use anyhow::Result; use bip39::Mnemonic; -use cdk::{ - amount::SplitTarget, - cdk_database::WalletMemoryDatabase, - nuts::{ - CurrencyUnit, MeltBolt11Request, MeltQuoteState, MintQuoteState, PreMintSecrets, State, - }, - wallet::{ - client::{HttpClient, HttpClientMethods}, - Wallet, - }, +use cdk::amount::SplitTarget; +use cdk::cdk_database::WalletMemoryDatabase; +use cdk::nuts::{ + CurrencyUnit, MeltBolt11Request, MeltQuoteState, MintQuoteState, PreMintSecrets, State, }; +use cdk::wallet::client::{HttpClient, HttpClientMethods}; +use cdk::wallet::Wallet; use cdk_fake_wallet::{create_fake_invoice, FakeInvoiceDescription}; use cdk_integration_tests::attempt_to_swap_pending; use tokio::time::sleep; diff --git a/crates/cdk-integration-tests/tests/mint.rs b/crates/cdk-integration-tests/tests/mint.rs index b75f0378..3c9f1258 100644 --- a/crates/cdk-integration-tests/tests/mint.rs +++ b/crates/cdk-integration-tests/tests/mint.rs @@ -1,5 +1,9 @@ //! Mint tests +use std::collections::HashMap; +use std::sync::Arc; +use std::time::Duration; + use anyhow::{bail, Result}; use bip39::Mnemonic; use cdk::amount::{Amount, SplitTarget}; @@ -15,9 +19,6 @@ use cdk::nuts::{ use cdk::types::QuoteTTL; use cdk::util::unix_time; use cdk::Mint; -use std::collections::HashMap; -use std::sync::Arc; -use std::time::Duration; use tokio::sync::OnceCell; use tokio::time::sleep; diff --git a/crates/cdk-integration-tests/tests/regtest.rs b/crates/cdk-integration-tests/tests/regtest.rs index 24bbe89b..107fa49e 100644 --- a/crates/cdk-integration-tests/tests/regtest.rs +++ b/crates/cdk-integration-tests/tests/regtest.rs @@ -1,19 +1,18 @@ -use std::{fmt::Debug, str::FromStr, sync::Arc, time::Duration}; +use std::fmt::Debug; +use std::str::FromStr; +use std::sync::Arc; +use std::time::Duration; use anyhow::{bail, Result}; use bip39::Mnemonic; -use cdk::{ - amount::{Amount, SplitTarget}, - cdk_database::WalletMemoryDatabase, - nuts::{ - CurrencyUnit, MeltQuoteState, MintBolt11Request, MintQuoteState, NotificationPayload, - PreMintSecrets, State, - }, - wallet::{ - client::{HttpClient, HttpClientMethods}, - Wallet, - }, +use cdk::amount::{Amount, SplitTarget}; +use cdk::cdk_database::WalletMemoryDatabase; +use cdk::nuts::{ + CurrencyUnit, MeltQuoteState, MintBolt11Request, MintQuoteState, NotificationPayload, + PreMintSecrets, State, }; +use cdk::wallet::client::{HttpClient, HttpClientMethods}; +use cdk::wallet::Wallet; use cdk_integration_tests::init_regtest::{ get_mint_url, get_mint_ws_url, init_cln_client, init_lnd_client, }; @@ -22,7 +21,8 @@ use lightning_invoice::Bolt11Invoice; use ln_regtest_rs::InvoiceStatus; use serde_json::json; use tokio::time::{sleep, timeout}; -use tokio_tungstenite::{connect_async, tungstenite::protocol::Message}; +use tokio_tungstenite::connect_async; +use tokio_tungstenite::tungstenite::protocol::Message; async fn get_notification> + Unpin, E: Debug>( reader: &mut T, diff --git a/crates/cdk-mintd/src/main.rs b/crates/cdk-mintd/src/main.rs index 7472bdfb..554c4ff8 100644 --- a/crates/cdk-mintd/src/main.rs +++ b/crates/cdk-mintd/src/main.rs @@ -14,10 +14,11 @@ use bip39::Mnemonic; use cdk::cdk_database::{self, MintDatabase}; use cdk::cdk_lightning; use cdk::cdk_lightning::MintLightning; -use cdk::mint::{MeltQuote, Mint}; -use cdk::mint::{MintBuilder, MintMeltLimits}; +use cdk::mint::{MeltQuote, Mint, MintBuilder, MintMeltLimits}; use cdk::nuts::{ContactInfo, CurrencyUnit, MeltQuoteState, MintVersion, PaymentMethod}; use cdk::types::LnKey; +use cdk_mintd::cli::CLIArgs; +use cdk_mintd::config::{self, DatabaseEngine, LnBackend}; use cdk_mintd::setup::LnBackendSetup; use cdk_redb::MintRedbDatabase; use cdk_sqlite::MintSqliteDatabase; @@ -28,9 +29,6 @@ use tracing_subscriber::EnvFilter; #[cfg(feature = "swagger")] use utoipa::OpenApi; -use cdk_mintd::cli::CLIArgs; -use cdk_mintd::config::{self, DatabaseEngine, LnBackend}; - const CARGO_PKG_VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION"); const DEFAULT_QUOTE_TTL_SECS: u64 = 1800; const DEFAULT_CACHE_TTL_SECS: u64 = 1800; diff --git a/crates/cdk-mintd/src/setup.rs b/crates/cdk-mintd/src/setup.rs index 63674288..9a2cc820 100644 --- a/crates/cdk-mintd/src/setup.rs +++ b/crates/cdk-mintd/src/setup.rs @@ -1,20 +1,18 @@ -use std::{ - collections::{HashMap, HashSet}, - sync::Arc, -}; +use std::collections::{HashMap, HashSet}; +use std::sync::Arc; use anyhow::{anyhow, bail}; use axum::{async_trait, Router}; +use cdk::cdk_lightning::MintLightning; +use cdk::mint::FeeReserve; +use cdk::mint_url::MintUrl; +use cdk::nuts::CurrencyUnit; use rand::Rng; - -use cdk::{cdk_lightning::MintLightning, mint::FeeReserve, mint_url::MintUrl, nuts::CurrencyUnit}; use tokio::sync::Mutex; use url::Url; -use crate::{ - config::{self, Settings}, - expand_path, -}; +use crate::config::{self, Settings}; +use crate::expand_path; #[async_trait] pub trait LnBackendSetup { diff --git a/crates/cdk/src/error.rs b/crates/cdk/src/error.rs index 1695a58c..5ddfac64 100644 --- a/crates/cdk/src/error.rs +++ b/crates/cdk/src/error.rs @@ -6,9 +6,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde_json::Value; use thiserror::Error; +use crate::nuts::Id; +use crate::util::hex; #[cfg(feature = "wallet")] use crate::wallet::multi_mint_wallet::WalletKey; -use crate::{nuts::Id, util::hex, Amount}; +use crate::Amount; /// CDK Error #[derive(Debug, Error)] diff --git a/crates/cdk/src/mint/builder.rs b/crates/cdk/src/mint/builder.rs index 07b6840e..a71c259c 100644 --- a/crates/cdk/src/mint/builder.rs +++ b/crates/cdk/src/mint/builder.rs @@ -1,20 +1,19 @@ //! Mint Builder -use std::{collections::HashMap, sync::Arc}; +use std::collections::HashMap; +use std::sync::Arc; use anyhow::anyhow; -use crate::{ - amount::Amount, - cdk_database::{self, MintDatabase}, - cdk_lightning::{self, MintLightning}, - mint::Mint, - nuts::{ - ContactInfo, CurrencyUnit, MeltMethodSettings, MintInfo, MintMethodSettings, MintVersion, - MppMethodSettings, PaymentMethod, - }, - types::{LnKey, QuoteTTL}, +use crate::amount::Amount; +use crate::cdk_database::{self, MintDatabase}; +use crate::cdk_lightning::{self, MintLightning}; +use crate::mint::Mint; +use crate::nuts::{ + ContactInfo, CurrencyUnit, MeltMethodSettings, MintInfo, MintMethodSettings, MintVersion, + MppMethodSettings, PaymentMethod, }; +use crate::types::{LnKey, QuoteTTL}; /// Cashu Mint #[derive(Default)] diff --git a/crates/cdk/src/mint/check_spendable.rs b/crates/cdk/src/mint/check_spendable.rs index 103bed2d..04c009d9 100644 --- a/crates/cdk/src/mint/check_spendable.rs +++ b/crates/cdk/src/mint/check_spendable.rs @@ -2,9 +2,8 @@ use std::collections::HashSet; use tracing::instrument; -use crate::Error; - use super::{CheckStateRequest, CheckStateResponse, Mint, ProofState, PublicKey, State}; +use crate::Error; impl Mint { /// Check state diff --git a/crates/cdk/src/mint/info.rs b/crates/cdk/src/mint/info.rs index 0b800963..ba9455f5 100644 --- a/crates/cdk/src/mint/info.rs +++ b/crates/cdk/src/mint/info.rs @@ -1,8 +1,7 @@ use tracing::instrument; -use crate::mint_url::MintUrl; - use super::{Mint, MintInfo}; +use crate::mint_url::MintUrl; impl Mint { /// Set Mint Url diff --git a/crates/cdk/src/mint/keysets.rs b/crates/cdk/src/mint/keysets.rs index 66445608..9ca8c7ec 100644 --- a/crates/cdk/src/mint/keysets.rs +++ b/crates/cdk/src/mint/keysets.rs @@ -3,12 +3,11 @@ use std::collections::{HashMap, HashSet}; use bitcoin::bip32::DerivationPath; use tracing::instrument; -use crate::Error; - use super::{ create_new_keyset, derivation_path_from_unit, CurrencyUnit, Id, KeySet, KeySetInfo, KeysResponse, KeysetResponse, Mint, MintKeySet, MintKeySetInfo, }; +use crate::Error; impl Mint { /// Retrieve the public keys of the active keyset for distribution to wallet diff --git a/crates/cdk/src/mint/melt.rs b/crates/cdk/src/mint/melt.rs index 1613fc3c..8ac01d69 100644 --- a/crates/cdk/src/mint/melt.rs +++ b/crates/cdk/src/mint/melt.rs @@ -5,21 +5,19 @@ use anyhow::bail; use lightning_invoice::Bolt11Invoice; use tracing::instrument; -use crate::cdk_lightning; -use crate::cdk_lightning::MintLightning; -use crate::cdk_lightning::PayInvoiceResponse; -use crate::nuts::nut00::ProofsMethods; -use crate::nuts::nut11::enforce_sig_flag; -use crate::nuts::nut11::EnforceSigFlag; -use crate::{ - amount::to_unit, mint::SigFlag, nuts::Id, nuts::MeltQuoteState, types::LnKey, util::unix_time, - Amount, Error, -}; - use super::{ CurrencyUnit, MeltBolt11Request, MeltQuote, MeltQuoteBolt11Request, MeltQuoteBolt11Response, Mint, PaymentMethod, PublicKey, State, }; +use crate::amount::to_unit; +use crate::cdk_lightning::{MintLightning, PayInvoiceResponse}; +use crate::mint::SigFlag; +use crate::nuts::nut00::ProofsMethods; +use crate::nuts::nut11::{enforce_sig_flag, EnforceSigFlag}; +use crate::nuts::{Id, MeltQuoteState}; +use crate::types::LnKey; +use crate::util::unix_time; +use crate::{cdk_lightning, Amount, Error}; impl Mint { fn check_melt_request_acceptable( diff --git a/crates/cdk/src/mint/mint_nut04.rs b/crates/cdk/src/mint/mint_nut04.rs index fb0b6d4d..5631fd04 100644 --- a/crates/cdk/src/mint/mint_nut04.rs +++ b/crates/cdk/src/mint/mint_nut04.rs @@ -1,11 +1,13 @@ use tracing::instrument; -use crate::{nuts::MintQuoteState, types::LnKey, util::unix_time, Amount, Error}; - use super::{ nut04, CurrencyUnit, Mint, MintQuote, MintQuoteBolt11Request, MintQuoteBolt11Response, NotificationPayload, PaymentMethod, PublicKey, }; +use crate::nuts::MintQuoteState; +use crate::types::LnKey; +use crate::util::unix_time; +use crate::{Amount, Error}; impl Mint { /// Checks that minting is enabled, request is supported unit and within range diff --git a/crates/cdk/src/mint/mod.rs b/crates/cdk/src/mint/mod.rs index 893ecedd..360ff266 100644 --- a/crates/cdk/src/mint/mod.rs +++ b/crates/cdk/src/mint/mod.rs @@ -608,9 +608,8 @@ mod tests { use bitcoin::Network; use secp256k1::Secp256k1; - use crate::types::LnKey; - use super::*; + use crate::types::LnKey; #[test] fn mint_mod_generate_keyset_from_seed() { diff --git a/crates/cdk/src/mint/swap.rs b/crates/cdk/src/mint/swap.rs index 88ccd0d1..6dcf31fa 100644 --- a/crates/cdk/src/mint/swap.rs +++ b/crates/cdk/src/mint/swap.rs @@ -2,11 +2,10 @@ use std::collections::HashSet; use tracing::instrument; -use crate::nuts::nut00::ProofsMethods; -use crate::Error; - use super::nut11::{enforce_sig_flag, EnforceSigFlag}; use super::{Id, Mint, PublicKey, SigFlag, State, SwapRequest, SwapResponse}; +use crate::nuts::nut00::ProofsMethods; +use crate::Error; impl Mint { /// Process Swap diff --git a/crates/cdk/src/nuts/nut17/mod.rs b/crates/cdk/src/nuts/nut17/mod.rs index 7d2a3c4a..3ddd1f82 100644 --- a/crates/cdk/src/nuts/nut17/mod.rs +++ b/crates/cdk/src/nuts/nut17/mod.rs @@ -1,23 +1,21 @@ //! Specific Subscription for the cdk crate -use std::{ops::Deref, sync::Arc}; +use std::ops::Deref; +use std::sync::Arc; use serde::{Deserialize, Serialize}; mod on_subscription; +pub use on_subscription::OnSubscription; + use crate::cdk_database::{self, MintDatabase}; -use crate::nuts::{BlindSignature, CurrencyUnit, PaymentMethod}; -use crate::{ - nuts::{ - MeltQuoteBolt11Response, MeltQuoteState, MintQuoteBolt11Response, MintQuoteState, - ProofState, - }, - pub_sub::{self, Index, Indexable, SubscriptionGlobalId}, +use crate::nuts::{ + BlindSignature, CurrencyUnit, MeltQuoteBolt11Response, MeltQuoteState, MintQuoteBolt11Response, + MintQuoteState, PaymentMethod, ProofState, }; - pub use crate::pub_sub::SubId; -pub use on_subscription::OnSubscription; +use crate::pub_sub::{self, Index, Indexable, SubscriptionGlobalId}; /// Subscription Parameter according to the standard #[derive(Debug, Clone, Serialize, Deserialize)] @@ -214,12 +212,13 @@ impl PubSubManager { #[cfg(test)] mod test { - use crate::nuts::{PublicKey, State}; - - use super::*; use std::time::Duration; + use tokio::time::sleep; + use super::*; + use crate::nuts::{PublicKey, State}; + #[tokio::test] async fn active_and_drop() { let manager = PubSubManager::default(); diff --git a/crates/cdk/src/nuts/nut17/on_subscription.rs b/crates/cdk/src/nuts/nut17/on_subscription.rs index 9aaf8c18..ed3c634d 100644 --- a/crates/cdk/src/nuts/nut17/on_subscription.rs +++ b/crates/cdk/src/nuts/nut17/on_subscription.rs @@ -1,14 +1,13 @@ //! On Subscription //! //! This module contains the code that is triggered when a new subscription is created. -use std::{collections::HashMap, sync::Arc}; +use std::collections::HashMap; +use std::sync::Arc; use super::{Kind, NotificationPayload}; -use crate::{ - cdk_database::{self, MintDatabase}, - nuts::{MeltQuoteBolt11Response, MintQuoteBolt11Response, ProofState, PublicKey}, - pub_sub::OnNewSubscription, -}; +use crate::cdk_database::{self, MintDatabase}; +use crate::nuts::{MeltQuoteBolt11Response, MintQuoteBolt11Response, ProofState, PublicKey}; +use crate::pub_sub::OnNewSubscription; #[derive(Default)] /// Subscription Init diff --git a/crates/cdk/src/nuts/nut18.rs b/crates/cdk/src/nuts/nut18.rs index cb19735e..170af17d 100644 --- a/crates/cdk/src/nuts/nut18.rs +++ b/crates/cdk/src/nuts/nut18.rs @@ -2,19 +2,17 @@ //! //! -use std::{fmt, str::FromStr}; +use std::fmt; +use std::str::FromStr; -use bitcoin::base64::{ - alphabet, - engine::{general_purpose, GeneralPurpose}, - Engine, -}; +use bitcoin::base64::engine::{general_purpose, GeneralPurpose}; +use bitcoin::base64::{alphabet, Engine}; use serde::{Deserialize, Serialize}; use thiserror::Error; -use crate::{mint_url::MintUrl, Amount}; - use super::{CurrencyUnit, Proofs}; +use crate::mint_url::MintUrl; +use crate::Amount; const PAYMENT_REQUEST_PREFIX: &str = "creqA"; diff --git a/crates/cdk/src/pub_sub/index.rs b/crates/cdk/src/pub_sub/index.rs index b19f4a38..56b4e61b 100644 --- a/crates/cdk/src/pub_sub/index.rs +++ b/crates/cdk/src/pub_sub/index.rs @@ -1,9 +1,8 @@ +use std::fmt::Debug; +use std::ops::Deref; +use std::sync::atomic::{AtomicUsize, Ordering}; + use super::SubId; -use std::{ - fmt::Debug, - ops::Deref, - sync::atomic::{AtomicUsize, Ordering}, -}; /// Indexable trait pub trait Indexable { diff --git a/crates/cdk/src/pub_sub/mod.rs b/crates/cdk/src/pub_sub/mod.rs index c511c803..a8269290 100644 --- a/crates/cdk/src/pub_sub/mod.rs +++ b/crates/cdk/src/pub_sub/mod.rs @@ -8,22 +8,17 @@ //! generic type that must be converted to a vector of indexes. //! //! Events are also generic that should implement the `Indexable` trait. +use std::cmp::Ordering; +use std::collections::{BTreeMap, HashSet}; +use std::fmt::Debug; +use std::ops::{Deref, DerefMut}; +use std::str::FromStr; +use std::sync::atomic::{self, AtomicUsize}; +use std::sync::Arc; + use serde::{Deserialize, Serialize}; -use std::{ - cmp::Ordering, - collections::{BTreeMap, HashSet}, - fmt::Debug, - ops::{Deref, DerefMut}, - str::FromStr, - sync::{ - atomic::{self, AtomicUsize}, - Arc, - }, -}; -use tokio::{ - sync::{mpsc, RwLock}, - task::JoinHandle, -}; +use tokio::sync::{mpsc, RwLock}; +use tokio::task::JoinHandle; mod index; @@ -345,9 +340,10 @@ impl Deref for SubId { #[cfg(test)] mod test { - use super::*; use tokio::sync::mpsc; + use super::*; + #[test] fn test_active_subscription_drop() { let (tx, rx) = mpsc::channel::<(SubId, ())>(10); diff --git a/crates/cdk/src/types.rs b/crates/cdk/src/types.rs index e3d91eca..23ab9e89 100644 --- a/crates/cdk/src/types.rs +++ b/crates/cdk/src/types.rs @@ -176,13 +176,10 @@ impl QuoteTTL { mod tests { use std::str::FromStr; - use crate::{ - nuts::{Id, Proof, PublicKey}, - secret::Secret, - Amount, - }; - use super::Melted; + use crate::nuts::{Id, Proof, PublicKey}; + use crate::secret::Secret; + use crate::Amount; #[test] fn test_melted() { diff --git a/crates/cdk/src/wallet/balance.rs b/crates/cdk/src/wallet/balance.rs index 46c814ac..5b45ac48 100644 --- a/crates/cdk/src/wallet/balance.rs +++ b/crates/cdk/src/wallet/balance.rs @@ -3,7 +3,8 @@ use std::collections::HashMap; use tracing::instrument; use crate::nuts::nut00::ProofsMethods; -use crate::{nuts::CurrencyUnit, Amount, Error, Wallet}; +use crate::nuts::CurrencyUnit; +use crate::{Amount, Error, Wallet}; impl Wallet { /// Total unspent balance of wallet diff --git a/crates/cdk/src/wallet/keysets.rs b/crates/cdk/src/wallet/keysets.rs index 546c17a5..03cfa51b 100644 --- a/crates/cdk/src/wallet/keysets.rs +++ b/crates/cdk/src/wallet/keysets.rs @@ -1,10 +1,7 @@ use tracing::instrument; -use crate::nuts::Id; -use crate::nuts::KeySetInfo; -use crate::nuts::Keys; -use crate::Error; -use crate::Wallet; +use crate::nuts::{Id, KeySetInfo, Keys}; +use crate::{Error, Wallet}; impl Wallet { /// Get keys for mint keyset diff --git a/crates/cdk/src/wallet/melt.rs b/crates/cdk/src/wallet/melt.rs index 4948ecd3..e8a0a0b5 100644 --- a/crates/cdk/src/wallet/melt.rs +++ b/crates/cdk/src/wallet/melt.rs @@ -3,17 +3,16 @@ use std::str::FromStr; use lightning_invoice::Bolt11Invoice; use tracing::instrument; +use super::MeltQuote; +use crate::dhke::construct_proofs; use crate::nuts::nut00::ProofsMethods; -use crate::nuts::{MeltBolt11Request, MeltQuoteBolt11Request, Mpp}; -use crate::{ - dhke::construct_proofs, - nuts::{CurrencyUnit, MeltQuoteBolt11Response, PreMintSecrets, Proofs, State}, - types::{Melted, ProofInfo}, - util::unix_time, - Amount, Error, Wallet, +use crate::nuts::{ + CurrencyUnit, MeltBolt11Request, MeltQuoteBolt11Request, MeltQuoteBolt11Response, Mpp, + PreMintSecrets, Proofs, State, }; - -use super::MeltQuote; +use crate::types::{Melted, ProofInfo}; +use crate::util::unix_time; +use crate::{Amount, Error, Wallet}; impl Wallet { /// Melt Quote diff --git a/crates/cdk/src/wallet/mint.rs b/crates/cdk/src/wallet/mint.rs index 743044f0..77b9bb70 100644 --- a/crates/cdk/src/wallet/mint.rs +++ b/crates/cdk/src/wallet/mint.rs @@ -1,17 +1,17 @@ use tracing::instrument; use super::MintQuote; +use crate::amount::SplitTarget; +use crate::dhke::construct_proofs; use crate::nuts::nut00::ProofsMethods; -use crate::nuts::{MintBolt11Request, MintQuoteBolt11Request}; -use crate::{ - amount::SplitTarget, - dhke::construct_proofs, - nuts::{nut12, MintQuoteBolt11Response, PreMintSecrets, SpendingConditions, State}, - types::ProofInfo, - util::unix_time, - wallet::MintQuoteState, - Amount, Error, Wallet, +use crate::nuts::{ + nut12, MintBolt11Request, MintQuoteBolt11Request, MintQuoteBolt11Response, PreMintSecrets, + SpendingConditions, State, }; +use crate::types::ProofInfo; +use crate::util::unix_time; +use crate::wallet::MintQuoteState; +use crate::{Amount, Error, Wallet}; impl Wallet { /// Mint Quote diff --git a/crates/cdk/src/wallet/mod.rs b/crates/cdk/src/wallet/mod.rs index 7b8de868..bff6d4bf 100644 --- a/crates/cdk/src/wallet/mod.rs +++ b/crates/cdk/src/wallet/mod.rs @@ -36,10 +36,11 @@ mod swap; pub mod types; pub mod util; -use crate::nuts::nut00::ProofsMethods; pub use multi_mint_wallet::MultiMintWallet; pub use types::{MeltQuote, MintQuote, SendKind}; +use crate::nuts::nut00::ProofsMethods; + /// CDK Wallet /// /// The CDK [`Wallet`] is a high level cashu wallet. diff --git a/crates/cdk/src/wallet/proofs.rs b/crates/cdk/src/wallet/proofs.rs index fd67015a..c56956ce 100644 --- a/crates/cdk/src/wallet/proofs.rs +++ b/crates/cdk/src/wallet/proofs.rs @@ -2,14 +2,13 @@ use std::collections::HashSet; use tracing::instrument; +use crate::amount::SplitTarget; use crate::nuts::nut00::ProofsMethods; -use crate::nuts::CheckStateRequest; -use crate::{ - amount::SplitTarget, - nuts::{Proof, ProofState, Proofs, PublicKey, SpendingConditions, State}, - types::ProofInfo, - Amount, Error, Wallet, +use crate::nuts::{ + CheckStateRequest, Proof, ProofState, Proofs, PublicKey, SpendingConditions, State, }; +use crate::types::ProofInfo; +use crate::{Amount, Error, Wallet}; impl Wallet { /// Get unspent proofs for mint diff --git a/crates/cdk/src/wallet/receive.rs b/crates/cdk/src/wallet/receive.rs index 2a594b1f..c98c3cc7 100644 --- a/crates/cdk/src/wallet/receive.rs +++ b/crates/cdk/src/wallet/receive.rs @@ -1,20 +1,19 @@ -use std::{collections::HashMap, str::FromStr}; +use std::collections::HashMap; +use std::str::FromStr; +use bitcoin::hashes::sha256::Hash as Sha256Hash; use bitcoin::hashes::Hash; -use bitcoin::{hashes::sha256::Hash as Sha256Hash, XOnlyPublicKey}; +use bitcoin::XOnlyPublicKey; use tracing::instrument; +use crate::amount::SplitTarget; +use crate::dhke::construct_proofs; use crate::nuts::nut00::ProofsMethods; use crate::nuts::nut10::Kind; -use crate::nuts::{Conditions, Token}; -use crate::{ - amount::SplitTarget, - dhke::construct_proofs, - nuts::{Proofs, PublicKey, SecretKey, SigFlag, State}, - types::ProofInfo, - util::hex, - Amount, Error, Wallet, SECP256K1, -}; +use crate::nuts::{Conditions, Proofs, PublicKey, SecretKey, SigFlag, State, Token}; +use crate::types::ProofInfo; +use crate::util::hex; +use crate::{Amount, Error, Wallet, SECP256K1}; impl Wallet { /// Receive proofs diff --git a/crates/cdk/src/wallet/send.rs b/crates/cdk/src/wallet/send.rs index 0c6e7b79..f5146852 100644 --- a/crates/cdk/src/wallet/send.rs +++ b/crates/cdk/src/wallet/send.rs @@ -1,13 +1,10 @@ use tracing::instrument; -use crate::nuts::nut00::ProofsMethods; -use crate::{ - amount::SplitTarget, - nuts::{Proofs, SpendingConditions, State, Token}, - Amount, Error, Wallet, -}; - use super::SendKind; +use crate::amount::SplitTarget; +use crate::nuts::nut00::ProofsMethods; +use crate::nuts::{Proofs, SpendingConditions, State, Token}; +use crate::{Amount, Error, Wallet}; impl Wallet { /// Send specific proofs diff --git a/crates/cdk/src/wallet/swap.rs b/crates/cdk/src/wallet/swap.rs index 650ceac9..784d180d 100644 --- a/crates/cdk/src/wallet/swap.rs +++ b/crates/cdk/src/wallet/swap.rs @@ -3,18 +3,11 @@ use tracing::instrument; use crate::amount::SplitTarget; use crate::dhke::construct_proofs; use crate::nuts::nut00::ProofsMethods; -use crate::nuts::nut10; -use crate::nuts::PreMintSecrets; -use crate::nuts::PreSwap; -use crate::nuts::Proofs; -use crate::nuts::PublicKey; -use crate::nuts::SpendingConditions; -use crate::nuts::State; -use crate::nuts::SwapRequest; +use crate::nuts::{ + nut10, PreMintSecrets, PreSwap, Proofs, PublicKey, SpendingConditions, State, SwapRequest, +}; use crate::types::ProofInfo; -use crate::Amount; -use crate::Error; -use crate::Wallet; +use crate::{Amount, Error, Wallet}; impl Wallet { /// Swap