Skip to content

Commit

Permalink
refactor: instrument log on mint fns
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jul 10, 2024
1 parent 31cb85b commit cafa8e3
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions crates/cdk/src/mint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,31 @@ impl Mint {
}

/// Set Mint Url
#[instrument(skip_all)]
pub fn set_mint_url(&mut self, mint_url: UncheckedUrl) {
self.mint_url = mint_url;
}

/// Get Mint Url
#[instrument(skip_all)]
pub fn get_mint_url(&self) -> &UncheckedUrl {
&self.mint_url
}

/// Set Mint Info
#[instrument(skip_all)]
pub fn set_mint_info(&mut self, mint_info: MintInfo) {
self.mint_info = mint_info;
}

/// Get Mint Info
#[instrument(skip_all)]
pub fn mint_info(&self) -> &MintInfo {
&self.mint_info
}

/// New mint quote
#[instrument(skip_all)]
pub async fn new_mint_quote(
&self,
mint_url: UncheckedUrl,
Expand All @@ -147,6 +152,7 @@ impl Mint {
}

/// Check mint quote
#[instrument(skip(self))]
pub async fn check_mint_quote(&self, quote_id: &str) -> Result<MintQuoteBolt11Response, Error> {
let quote = self
.localstore
Expand All @@ -173,18 +179,21 @@ impl Mint {
}

/// Update mint quote
#[instrument(skip_all)]
pub async fn update_mint_quote(&self, quote: MintQuote) -> Result<(), Error> {
self.localstore.add_mint_quote(quote).await?;
Ok(())
}

/// Get mint quotes
#[instrument(skip_all)]
pub async fn mint_quotes(&self) -> Result<Vec<MintQuote>, Error> {
let quotes = self.localstore.get_mint_quotes().await?;
Ok(quotes)
}

/// Get pending mint quotes
#[instrument(skip_all)]
pub async fn get_pending_mint_quotes(&self) -> Result<Vec<MintQuote>, Error> {
let mint_quotes = self.localstore.get_mint_quotes().await?;

Expand All @@ -195,13 +204,15 @@ impl Mint {
}

/// Remove mint quote
#[instrument(skip_all)]
pub async fn remove_mint_quote(&self, quote_id: &str) -> Result<(), Error> {
self.localstore.remove_mint_quote(quote_id).await?;

Ok(())
}

/// New melt quote
#[instrument(skip_all)]
pub async fn new_melt_quote(
&self,
request: String,
Expand All @@ -226,6 +237,7 @@ impl Mint {
}

/// Fee required for proof set
#[instrument(skip_all)]
pub async fn get_proofs_fee(&self, proofs: &Proofs) -> Result<Amount, Error> {
let mut sum_fee = 0;

Expand All @@ -243,6 +255,7 @@ impl Mint {
}

/// Check melt quote status
#[instrument(skip(self))]
pub async fn check_melt_quote(&self, quote_id: &str) -> Result<MeltQuoteBolt11Response, Error> {
let quote = self
.localstore
Expand All @@ -263,26 +276,29 @@ impl Mint {
}

/// Update melt quote
#[instrument(skip_all)]
pub async fn update_melt_quote(&self, quote: MeltQuote) -> Result<(), Error> {
self.localstore.add_melt_quote(quote).await?;
Ok(())
}

/// Get melt quotes
#[instrument(skip_all)]
pub async fn melt_quotes(&self) -> Result<Vec<MeltQuote>, Error> {
let quotes = self.localstore.get_melt_quotes().await?;
Ok(quotes)
}

/// Remove melt quote
#[instrument(skip(self))]
pub async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Error> {
self.localstore.remove_melt_quote(quote_id).await?;

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?;
let keysets = self.keysets.read().await;
Expand All @@ -292,8 +308,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?;
for keyset_info in keyset_infos {
Expand All @@ -306,6 +322,7 @@ impl Mint {
}

/// Return a list of all supported keysets
#[instrument(skip_all)]
pub async fn keysets(&self) -> Result<KeysetResponse, Error> {
let keysets = self.localstore.get_keyset_infos().await?;
let active_keysets: HashSet<Id> = self
Expand All @@ -330,6 +347,7 @@ impl Mint {
}

/// Get keysets
#[instrument(skip(self))]
pub async fn keyset(&self, id: &Id) -> Result<Option<KeySet>, Error> {
self.ensure_keyset_loaded(id).await?;
let keysets = self.keysets.read().await;
Expand All @@ -339,6 +357,7 @@ impl Mint {

/// Add current keyset to inactive keysets
/// Generate new keyset
#[instrument(skip(self))]
pub async fn rotate_keyset(
&self,
unit: CurrencyUnit,
Expand All @@ -365,6 +384,7 @@ impl Mint {
}

/// Process mint request
#[instrument(skip_all)]
pub async fn process_mint_request(
&self,
mint_request: nut04::MintBolt11Request,
Expand Down Expand Up @@ -430,6 +450,7 @@ impl Mint {
}

/// Blind Sign
#[instrument(skip_all)]
pub async fn blind_sign(
&self,
blinded_message: &BlindedMessage,
Expand Down Expand Up @@ -480,7 +501,7 @@ impl Mint {
}

/// Process Swap
#[instrument(skip(self, swap_request))]
#[instrument(skip_all)]
pub async fn process_swap_request(
&self,
swap_request: SwapRequest,
Expand Down Expand Up @@ -600,6 +621,7 @@ impl Mint {
}

/// Verify [`Proof`] meets conditions and is signed
#[instrument(skip_all)]
pub async fn verify_proof(&self, proof: &Proof) -> Result<(), Error> {
// Check if secret is a nut10 secret with conditions
if let Ok(secret) =
Expand Down Expand Up @@ -643,6 +665,7 @@ impl Mint {
}

/// Check state
#[instrument(skip_all)]
pub async fn check_state(
&self,
check_state: &CheckStateRequest,
Expand All @@ -668,6 +691,7 @@ impl Mint {
}

/// Verify melt request is valid
#[instrument(skip_all)]
pub async fn verify_melt_request(
&self,
melt_request: &MeltBolt11Request,
Expand Down Expand Up @@ -794,6 +818,7 @@ 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
#[instrument(skip_all)]
pub async fn process_unpaid_melt(&self, melt_request: &MeltBolt11Request) -> Result<(), Error> {
self.localstore
.remove_pending_proofs(melt_request.inputs.iter().map(|p| &p.secret).collect())
Expand All @@ -808,6 +833,7 @@ 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`]
#[instrument(skip_all)]
pub async fn process_melt_request(
&self,
melt_request: &MeltBolt11Request,
Expand Down Expand Up @@ -905,6 +931,7 @@ impl Mint {
}

/// Restore
#[instrument(skip_all)]
pub async fn restore(&self, request: RestoreRequest) -> Result<RestoreResponse, Error> {
let output_len = request.outputs.len();

Expand Down Expand Up @@ -937,6 +964,7 @@ impl Mint {
}

/// Ensure Keyset is loaded in mint
#[instrument(skip(self))]
pub async fn ensure_keyset_loaded(&self, id: &Id) -> Result<(), Error> {
let keysets = self.keysets.read().await;
if keysets.contains_key(id) {
Expand All @@ -956,6 +984,7 @@ impl Mint {
}

/// Generate [`MintKeySet`] from [`MintKeySetInfo`]
#[instrument(skip_all)]
pub fn generate_keyset(&self, keyset_info: MintKeySetInfo) -> MintKeySet {
MintKeySet::generate_from_xpriv(&self.secp_ctx, self.xpriv, keyset_info)
}
Expand Down Expand Up @@ -1005,6 +1034,7 @@ impl From<MintKeySetInfo> for KeySetInfo {
}

/// Generate new [`MintKeySetInfo`] from path
#[instrument(skip_all)]
fn create_new_keyset<C: secp256k1::Signing>(
secp: &secp256k1::Secp256k1<C>,
xpriv: ExtendedPrivKey,
Expand Down

0 comments on commit cafa8e3

Please sign in to comment.