mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-23 14:06:56 +01:00
chore: fmt
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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, "e.unit, &CurrencyUnit::Msat)
|
||||
.expect("Quote unit is checked above that it can convert to msat");
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
@@ -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(|| {
|
||||
@@ -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(|| {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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,
|
||||
@@ -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?;
|
||||
@@ -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?;
|
||||
@@ -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()?;
|
||||
@@ -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
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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>,
|
||||
|
||||
@@ -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();
|
||||
@@ -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
|
||||
@@ -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))
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
tab_spaces = 4
|
||||
max_width = 100
|
||||
max_width = 80
|
||||
newline_style = "Auto"
|
||||
reorder_imports = true
|
||||
reorder_modules = true
|
||||
|
||||
Reference in New Issue
Block a user