Skip to content

Commit

Permalink
chore: run the code formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
vnprc committed Aug 30, 2024
1 parent e9742eb commit d20636f
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 48 deletions.
3 changes: 2 additions & 1 deletion crates/cdk-axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ struct MintState {
quote_ttl: u64,
}

/// Key used in hashmap of ln backends to identify what unit and payment method it is for
/// Key used in hashmap of ln backends to identify what unit and payment method
/// it is for
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct LnKey {
/// Unit of Payment backend
Expand Down
17 changes: 10 additions & 7 deletions crates/cdk-axum/src/router_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ pub async fn post_melt_bolt11(
};

// Check to see if there is a corresponding mint quote for a melt.
// In this case the mint can settle the payment internally and no ln payment is needed
// In this case the mint can settle the payment internally and no ln payment is
// needed
let mint_quote = match state
.mint
.localstore
Expand Down Expand Up @@ -273,12 +274,14 @@ pub async fn post_melt_bolt11(

let mut partial_amount = None;

// If the quote unit is SAT or MSAT we can check that the expected fees are provided.
// We also check if the quote is less then the invoice amount in the case that it is a mmp
// However, if the quote id not of a bitcoin unit we cannot do these checks as the mint
// is unaware of a conversion rate. In this case it is assumed that the quote is correct
// and the mint should pay the full invoice amount if inputs > then quote.amount are included.
// This is checked in the verify_melt method.
// If the quote unit is SAT or MSAT we can check that the expected fees are
// provided. We also check if the quote is less then the invoice
// amount in the case that it is a mmp However, if the quote id not
// of a bitcoin unit we cannot do these checks as the mint
// is unaware of a conversion rate. In this case it is assumed that the quote is
// correct and the mint should pay the full invoice amount if inputs
// > then quote.amount are included. This is checked in the
// verify_melt method.
if quote.unit == CurrencyUnit::Msat || quote.unit == CurrencyUnit::Sat {
let quote_msats = to_unit(quote.amount, &quote.unit, &CurrencyUnit::Msat)
.expect("Quote unit is checked above that it can convert to msat");
Expand Down
3 changes: 2 additions & 1 deletion crates/cdk-phoenixd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ impl MintLightning for Phoenixd {

impl Phoenixd {
/// Check the status of an outgooing invoice
// TODO: This should likely bee added to the trait. Both CLN and PhD use a form of it
// TODO: This should likely bee added to the trait. Both CLN and PhD use a form
// of it
async fn check_outgoing_invoice(
&self,
payment_hash: &str,
Expand Down
6 changes: 3 additions & 3 deletions crates/cdk/benches/dhke_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use criterion::{criterion_group, criterion_main, Criterion};

fn bench_dhke(c: &mut Criterion) {
// *************************************************************
// * PREPARE DATA FOR BENCHMARKS *
// * PREPARE DATA FOR BENCHMARKS *
// *************************************************************
let message =
hex::decode("d341ee4871f1f889041e63cf0d3823c713eea6aff01e80f1719f08f9e5be98f6").unwrap();
Expand All @@ -29,7 +29,7 @@ fn bench_dhke(c: &mut Criterion) {
dhke::blind_message("test_message".as_bytes(), Some(bob_sec.clone())).unwrap();

// *************************************************************
// * RUN INDIVIDUAL STEPS *
// * RUN INDIVIDUAL STEPS *
// *************************************************************
c.bench_function("hash_to_curve", |b| {
b.iter(|| {
Expand All @@ -56,7 +56,7 @@ fn bench_dhke(c: &mut Criterion) {
});

// *************************************************************
// * RUN END TO END BDHKE *
// * RUN END TO END BDHKE *
// *************************************************************
c.bench_function("End-to-End BDHKE", |b| {
b.iter(|| {
Expand Down
9 changes: 6 additions & 3 deletions crates/cdk/src/cdk_database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,20 @@ pub trait WalletDatabase: Debug {
/// Remove [`Keys`] from storage
async fn remove_keys(&self, id: &Id) -> Result<(), Self::Err>;

/// Update the proofs in storage by adding new proofs or removing proofs by their Y value.
/// Update the proofs in storage by adding new proofs or removing proofs by
/// their Y value.
async fn update_proofs(
&self,
added: Vec<ProofInfo>,
removed_ys: Vec<PublicKey>,
) -> Result<(), Self::Err>;
/// Set proofs as pending in storage. Proofs are identified by their Y value.
/// Set proofs as pending in storage. Proofs are identified by their Y
/// value.
async fn set_pending_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Self::Err>;
/// Reserve proofs in storage. Proofs are identified by their Y value.
async fn reserve_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Self::Err>;
/// Set proofs as unspent in storage. Proofs are identified by their Y value.
/// Set proofs as unspent in storage. Proofs are identified by their Y
/// value.
async fn set_unspent_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Self::Err>;
/// Get proofs from storage
async fn get_proofs(
Expand Down
3 changes: 2 additions & 1 deletion crates/cdk/src/dhke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use crate::SECP256K1;

const DOMAIN_SEPARATOR: &[u8; 28] = b"Secp256k1_HashToCurve_Cashu_";

/// Deterministically maps a message to a public key point on the secp256k1 curve, utilizing a domain separator to ensure uniqueness.
/// Deterministically maps a message to a public key point on the secp256k1
/// curve, utilizing a domain separator to ensure uniqueness.
///
/// For definationn in NUT see [NUT-00](https://github.com/cashubtc/nuts/blob/main/00.md)
pub fn hash_to_curve(message: &[u8]) -> Result<PublicKey, Error> {
Expand Down
24 changes: 15 additions & 9 deletions crates/cdk/src/mint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ impl Mint {

let paid = quote.state == MintQuoteState::Paid;

// Since the pending state is not part of the NUT it should not be part of the response.
// In practice the wallet should not be checking the state of a quote while waiting for the mint response.
// Since the pending state is not part of the NUT it should not be part of the
// response. In practice the wallet should not be checking the state of
// a quote while waiting for the mint response.
let state = match quote.state {
MintQuoteState::Pending => MintQuoteState::Paid,
s => s,
Expand Down Expand Up @@ -459,7 +460,8 @@ impl Mint {
Ok(())
}

/// Retrieve the public keys of the active keyset for distribution to wallet clients
/// Retrieve the public keys of the active keyset for distribution to wallet
/// clients
#[instrument(skip(self))]
pub async fn keyset_pubkeys(&self, keyset_id: &Id) -> Result<KeysResponse, Error> {
self.ensure_keyset_loaded(keyset_id).await?;
Expand All @@ -470,7 +472,8 @@ impl Mint {
})
}

/// Retrieve the public keys of the active keyset for distribution to wallet clients
/// Retrieve the public keys of the active keyset for distribution to wallet
/// clients
#[instrument(skip_all)]
pub async fn pubkeys(&self) -> Result<KeysResponse, Error> {
let keyset_infos = self.localstore.get_keyset_infos().await?;
Expand Down Expand Up @@ -859,8 +862,9 @@ impl Mint {
// Checks and verifes known secret kinds.
// If it is an unknown secret kind it will be treated as a normal secret.
// Spending conditions will **not** be check. It is up to the wallet to ensure
// only supported secret kinds are used as there is no way for the mint to enforce
// only signing supported secrets as they are blinded at that point.
// only supported secret kinds are used as there is no way for the mint to
// enforce only signing supported secrets as they are blinded at
// that point.
match secret.kind {
Kind::P2PK => {
proof.verify_p2pk()?;
Expand Down Expand Up @@ -1058,8 +1062,9 @@ impl Mint {
}

/// Process unpaid melt request
/// In the event that a melt request fails and the lighthing payment is not made
/// The [`Proofs`] should be returned to an unspent state and the quote should be unpaid
/// In the event that a melt request fails and the lighthing payment is not
/// made The [`Proofs`] should be returned to an unspent state and the
/// quote should be unpaid
#[instrument(skip_all)]
pub async fn process_unpaid_melt(&self, melt_request: &MeltBolt11Request) -> Result<(), Error> {
let input_ys = melt_request
Expand All @@ -1080,7 +1085,8 @@ impl Mint {
}

/// Process melt request marking [`Proofs`] as spent
/// The melt request must be verifyed using [`Self::verify_melt_request`] before calling [`Self::process_melt_request`]
/// The melt request must be verifyed using [`Self::verify_melt_request`]
/// before calling [`Self::process_melt_request`]
#[instrument(skip_all)]
pub async fn process_melt_request(
&self,
Expand Down
3 changes: 2 additions & 1 deletion crates/cdk/src/nuts/nut04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ pub enum QuoteState {
/// Quote has been paid and wallet can mint
Paid,
/// Minting is in progress
/// **Note:** This state is to be used internally but is not part of the nut.
/// **Note:** This state is to be used internally but is not part of the
/// nut.
Pending,
/// ecash issued for quote
Issued,
Expand Down
6 changes: 4 additions & 2 deletions crates/cdk/src/nuts/nut11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ where
pub enum SigFlag {
#[default]
/// Requires valid signatures on all inputs.
/// It is the default signature flag and will be applied even if the `sigflag` tag is absent.
/// It is the default signature flag and will be applied even if the
/// `sigflag` tag is absent.
SigInputs,
/// Requires valid signatures on all inputs and on all outputs.
SigAll,
Expand All @@ -615,7 +616,8 @@ impl FromStr for SigFlag {
}

#[cfg(feature = "mint")]
/// Get the signature flag that should be enforced for a set of proofs and the public keys that signatures are valid for
/// Get the signature flag that should be enforced for a set of proofs and the
/// public keys that signatures are valid for
pub(crate) fn enforce_sig_flag(proofs: Proofs) -> EnforceSigFlag {
let mut sig_flag = SigFlag::SigInputs;
let mut pubkeys = HashSet::new();
Expand Down
3 changes: 2 additions & 1 deletion crates/cdk/src/nuts/nut13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ impl PreMintSecrets {
Ok(pre_mint_secrets)
}

/// Generate blinded messages from predetermined secrets and blindings factor
/// Generate blinded messages from predetermined secrets and blindings
/// factor
pub fn restore_batch(
keyset_id: Id,
xpriv: ExtendedPrivKey,
Expand Down
3 changes: 2 additions & 1 deletion crates/cdk/src/wallet/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ impl HttpClient {

#[cfg(not(target_arch = "wasm32"))]
/// Create new [`HttpClient`] with a proxy for specific TLDs.
/// Specifying `None` for `host_matcher` will use the proxy for all requests.
/// Specifying `None` for `host_matcher` will use the proxy for all
/// requests.
pub fn with_proxy(
proxy: Url,
host_matcher: Option<&str>,
Expand Down
37 changes: 23 additions & 14 deletions crates/cdk/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ impl Wallet {
Ok(balances)
}

/// Update Mint information and related entries in the event a mint changes its URL
/// Update Mint information and related entries in the event a mint changes
/// its URL
#[instrument(skip(self))]
pub async fn update_mint_url(&mut self, new_mint_url: MintUrl) -> Result<(), Error> {
self.mint_url = new_mint_url.clone();
Expand Down Expand Up @@ -327,7 +328,8 @@ impl Wallet {

/// Get active keyset for mint
///
/// Quieries mint for current keysets then gets [`Keys`] for any unknown keysets
/// Quieries mint for current keysets then gets [`Keys`] for any unknown
/// keysets
#[instrument(skip(self))]
pub async fn get_active_mint_keyset(&self) -> Result<KeySetInfo, Error> {
let keysets = self
Expand Down Expand Up @@ -441,9 +443,10 @@ impl Wallet {
.check_proofs_spent(proofs.clone().into_iter().map(|p| p.proof).collect())
.await?;

// Both `State::Pending` and `State::Unspent` should be included in the pending table.
// This is because a proof that has been crated to send will be stored in the pending table
// in order to avoid accidentally double spending but to allow it to be explicitly reclaimed
// Both `State::Pending` and `State::Unspent` should be included in the pending
// table. This is because a proof that has been crated to send will be
// stored in the pending table in order to avoid accidentally double
// spending but to allow it to be explicitly reclaimed
let pending_states: HashSet<PublicKey> = states
.into_iter()
.filter(|s| s.state.ne(&State::Spent))
Expand Down Expand Up @@ -561,27 +564,33 @@ impl Wallet {
Ok(total_amount)
}

/// Generates blinded secrets to send to the mint for signing. This function is
/// appropriate if the caller is providing their own network transport. Otherwise
/// use `mint`, which makes a network request to the mint.
/// Generates blinded secrets to send to the mint for signing. This function
/// is appropriate if the caller is providing their own network
/// transport. Otherwise use `mint`, which makes a network request to
/// the mint.
///
/// # Parameters
///
/// - `&self`: A reference to the current instance
/// - `active_keyset_id`: The ID of the active keyset
/// - `quote_info_amount`: The amount to be minted
/// - `amount_split_target`: Strategy for splitting amount into discrete tokens
/// - `spending_conditions`: Optional spending conditions to apply to the minted tokens
/// - `count`: How many tokens were previously generated from this keyset + 1
/// - `amount_split_target`: Strategy for splitting amount into discrete
/// tokens
/// - `spending_conditions`: Optional spending conditions to apply to the
/// minted tokens
/// - `count`: How many tokens were previously generated from this keyset +
/// 1
/// - `xpriv`: The extended private key used for generating secrets
///
/// # Returns
///
/// A `Result` containing `PreMintSecrets` if successful, or an `Error` otherwise.
/// A `Result` containing `PreMintSecrets` if successful, or an `Error`
/// otherwise.
///
/// # Errors
///
/// This function will return an error if the creation of `PreMintSecrets` fails.
/// This function will return an error if the creation of `PreMintSecrets`
/// fails.
///
/// ```
pub fn generate_premint_secrets(
Expand All @@ -591,7 +600,7 @@ impl Wallet {
amount_split_target: &SplitTarget,
spending_conditions: Option<&SpendingConditions>,
count: u32,
xpriv: ExtendedPrivKey
xpriv: ExtendedPrivKey,
) -> Result<PreMintSecrets, Error> {
// Move the match logic into this function.
match spending_conditions {
Expand Down
3 changes: 2 additions & 1 deletion crates/cdk/src/wallet/multi_mint_wallet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! MultiMint Wallet
//!
//! Wrapper around core [`Wallet`] that enables the use of multiple mint unit pairs
//! Wrapper around core [`Wallet`] that enables the use of multiple mint unit
//! pairs

use std::collections::{BTreeMap, HashMap};
use std::fmt;
Expand Down
3 changes: 2 additions & 1 deletion crates/cdk/src/wallet/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ pub enum SendKind {
OnlineExact,
/// Prefer offline send if difference is less then tolerance
OnlineTolerance(Amount),
/// Wallet cannot do an online swap and selectedp proof must be exactly send amount
/// Wallet cannot do an online swap and selectedp proof must be exactly send
/// amount
OfflineExact,
/// Wallet must remain offline but can over pay if below tolerance
OfflineTolerance(Amount),
Expand Down
6 changes: 4 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@
pname = "flexbox-multibuild";
src = rustSrc;
}).overrideArgs commonArgs;
in rec {
in
rec {
workspaceDeps = craneLib.buildWorkspaceDepsOnly { };
workspaceBuild =
craneLib.buildWorkspace { cargoArtifacts = workspaceDeps; };
});
in {
in
{
devShells = flakeboxLib.mkShells {
toolchain = toolchainNative;
packages = [ ];
Expand Down

0 comments on commit d20636f

Please sign in to comment.