Skip to content

Commit

Permalink
chore: fmt, clippy, typos
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Nov 17, 2024
1 parent c488db2 commit b056e86
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 100 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml

This file was deleted.

3 changes: 1 addition & 2 deletions crates/cdk-cln/src/bolt12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ use lightning::offers::invoice::Bolt12Invoice;
use lightning::offers::offer::Offer;
use uuid::Uuid;

use super::Cln;
use super::Error;
use super::{Cln, Error};

#[async_trait]
impl MintBolt12Lightning for Cln {
Expand Down
2 changes: 1 addition & 1 deletion crates/cdk-integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn create_backends_fake_wallet(
let ln_key = LnKey::new(CurrencyUnit::Sat, PaymentMethod::Bolt11);

let wallet = Arc::new(FakeWallet::new(
fee_reserve.clone(),
fee_reserve,
HashMap::default(),
HashSet::default(),
0,
Expand Down
8 changes: 4 additions & 4 deletions crates/cdk-integration-tests/tests/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use cdk::mint::MintQuote;
use cdk::nuts::nut00::ProofsMethods;
use cdk::nuts::nut17::Params;
use cdk::nuts::{
CurrencyUnit, Id, MintBolt11Request, MintInfo, NotificationPayload, Nuts, PreMintSecrets,
ProofState, Proofs, SecretKey, SpendingConditions, State, SwapRequest,
CurrencyUnit, Id, MintBolt11Request, MintInfo, NotificationPayload, Nuts, PaymentMethod,
PreMintSecrets, ProofState, Proofs, SecretKey, SpendingConditions, State, SwapRequest,
};
use cdk::types::QuoteTTL;
use cdk::util::unix_time;
Expand Down Expand Up @@ -76,21 +76,21 @@ async fn mint_proofs(
let quote = MintQuote::new(
mint.mint_url.clone(),
"".to_string(),
PaymentMethod::Bolt11,
CurrencyUnit::Sat,
Some(amount),
unix_time() + 36000,
request_lookup.to_string(),
Amount::ZERO,
Amount::ZERO,
true,
true,
vec![],
);

mint.localstore.add_mint_quote(quote.clone()).await?;

let wait_invoice = WaitInvoiceResponse {
request_lookup_id: request_lookup,
request_lookup_id: request_lookup.clone(),
payment_amount: amount,
unit: CurrencyUnit::Sat,
payment_id: request_lookup,
Expand Down
9 changes: 4 additions & 5 deletions crates/cdk/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use std::cmp::Ordering;
use std::fmt;
use std::str::FromStr;

use serde::{Deserialize, Deserializer, Serialize, Serializer};

use lightning::offers::offer::Offer;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use thiserror::Error;

use crate::nuts::CurrencyUnit;
Expand All @@ -25,9 +24,9 @@ pub enum Error {
/// Cannot convert units
#[error("Cannot convert units")]
CannotConvertUnits,
/// Amount undefinded
/// Amount undefined
#[error("Amount undefined")]
AmountUndefinded,
AmountUndefined,
/// Utf8 parse error
#[error(transparent)]
Utf8ParseError(#[from] std::string::FromUtf8Error),
Expand Down Expand Up @@ -310,7 +309,7 @@ where

/// Convert offer to amount in unit
pub fn amount_for_offer(offer: &Offer, unit: &CurrencyUnit) -> Result<Amount, Error> {
let offer_amount = offer.amount().ok_or(Error::AmountUndefinded)?;
let offer_amount = offer.amount().ok_or(Error::AmountUndefined)?;

let (amount, currency) = match offer_amount {
lightning::offers::offer::Amount::Bitcoin { amount_msats } => {
Expand Down
37 changes: 14 additions & 23 deletions crates/cdk/src/mint/melt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,21 @@ use anyhow::bail;
use lightning::offers::offer::Offer;
use tracing::instrument;

use crate::amount::amount_for_offer;
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::nut05::MeltRequestTrait;
use super::types::PaymentRequest;
use super::BlindSignature;
use super::CurrencyUnit;
use super::MeltQuote;
use super::MeltQuoteBolt11Request;
use super::MeltQuoteBolt11Response;
use super::MeltQuoteBolt12Request;
use super::Mint;
use super::PaymentMethod;
use super::State;
use crate::nuts::PublicKey;
use super::{
BlindSignature, CurrencyUnit, MeltQuote, MeltQuoteBolt11Request, MeltQuoteBolt11Response,
MeltQuoteBolt12Request, Mint, PaymentMethod, State,
};
use crate::amount::{amount_for_offer, 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, PublicKey};
use crate::types::LnKey;
use crate::util::unix_time;
use crate::{cdk_lightning, Amount, Error};

impl Mint {
fn check_melt_request_acceptable(
Expand Down Expand Up @@ -460,7 +451,7 @@ impl Mint {

if let Ok(Some(quote)) = self
.localstore
.get_melt_quote(&melt_request.get_quote_id())
.get_melt_quote(melt_request.get_quote_id())
.await
{
self.pubsub_manager
Expand Down
11 changes: 5 additions & 6 deletions crates/cdk/src/mint/mint_18.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use tracing::instrument;

use crate::{types::LnKey, util::unix_time, Amount, Error};

use super::{
nut19::{MintQuoteBolt12Request, MintQuoteBolt12Response},
Mint, MintQuote, PaymentMethod,
};
use super::nut19::{MintQuoteBolt12Request, MintQuoteBolt12Response};
use super::{Mint, MintQuote, PaymentMethod};
use crate::types::LnKey;
use crate::util::unix_time;
use crate::{Amount, Error};

impl Mint {
/// Create new mint bolt11 quote
Expand Down
5 changes: 1 addition & 4 deletions crates/cdk/src/mint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,7 @@ fn create_new_keyset<C: secp256k1::Signing>(
}

fn derivation_path_from_unit(unit: CurrencyUnit, index: u32) -> Option<DerivationPath> {
let unit_index = match unit.derivation_index() {
Some(index) => index,
None => return None,
};
let unit_index = unit.derivation_index()?;

Some(DerivationPath::from(vec![
ChildNumber::from_hardened_idx(0).expect("0 is a valid index"),
Expand Down
6 changes: 4 additions & 2 deletions crates/cdk/src/mint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ pub enum PaymentRequest {
}

mod offer_serde {
use super::Offer;
use serde::{self, Deserialize, Deserializer, Serializer};
use std::str::FromStr;

use serde::{self, Deserialize, Deserializer, Serializer};

use super::Offer;

pub fn serialize<S>(offer: &Offer, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand Down
2 changes: 1 addition & 1 deletion crates/cdk/src/nuts/nut06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub struct Nuts {
pub nut15: Option<nut15::Settings>,
/// NUT17 Settings
#[cfg(feature = "mint")]
pub nut17: super::nut17::SupportedSettings,
pub nut17: Option<super::nut17::SupportedSettings>,
/// NUT04 Settings
#[serde(rename = "18")]
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
3 changes: 1 addition & 2 deletions crates/cdk/src/nuts/nut17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ impl Indexable for NotificationPayload {
}
}

/// Kind
#[derive(Debug, Clone, Copy, Eq, Ord, PartialOrd, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]

/// Kind
pub enum Kind {
/// Bolt 11 Melt Quote
Bolt11MeltQuote,
Expand Down
4 changes: 2 additions & 2 deletions crates/cdk/src/nuts/nut20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
use serde::{Deserialize, Serialize};
use thiserror::Error;

use super::nut05::MeltRequestTrait;
use super::{BlindedMessage, CurrencyUnit, PaymentMethod, Proofs};
use crate::Amount;

use super::{nut05::MeltRequestTrait, BlindedMessage, CurrencyUnit, PaymentMethod, Proofs};

/// NUT18 Error
#[derive(Debug, Error)]
pub enum Error {
Expand Down
15 changes: 7 additions & 8 deletions crates/cdk/src/wallet/mint_bolt12.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use tracing::instrument;

use super::MintQuote;
use crate::amount::SplitTarget;
use crate::dhke::construct_proofs;
use crate::nuts::nut00::ProofsMethods;
use crate::nuts::nut19::{MintQuoteBolt12Request, MintQuoteBolt12Response};
use crate::nuts::{MintBolt11Request, PaymentMethod};
use crate::{
amount::SplitTarget,
dhke::construct_proofs,
nuts::{nut12, PreMintSecrets, SpendingConditions, State},
types::ProofInfo,
util::unix_time,
Amount, Error, Wallet,
use crate::nuts::{
nut12, MintBolt11Request, PaymentMethod, PreMintSecrets, SpendingConditions, State,
};
use crate::types::ProofInfo;
use crate::util::unix_time;
use crate::{Amount, Error, Wallet};

impl Wallet {
/// Mint Bolt12
Expand Down
46 changes: 9 additions & 37 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "CDK Flake";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";

rust-overlay = {
url = "github:oxalica/rust-overlay";
Expand Down Expand Up @@ -53,7 +53,7 @@
targets = [ "wasm32-unknown-unknown" ]; # wasm
};

# Nighly for creating lock files
# Nightly for creating lock files
nightly_toolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
extensions = [ "rustfmt" "clippy" "rust-analyzer" ];
});
Expand Down

0 comments on commit b056e86

Please sign in to comment.