Skip to content

Commit

Permalink
multiple active keysets and return active keyset with lowest fee (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 authored Nov 12, 2024
1 parent 4e2c013 commit e5c81d3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/cdk/src/wallet/keysets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Wallet {
/// Queries 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> {
pub async fn get_active_mint_keysets(&self) -> Result<Vec<KeySetInfo>, Error> {
let keysets = self.client.get_mint_keysets(self.mint_url.clone()).await?;
let keysets = keysets.keysets;

Expand Down Expand Up @@ -86,6 +86,21 @@ impl Wallet {
}
}

active_keysets.first().ok_or(Error::NoActiveKeyset).cloned()
Ok(active_keysets)
}

/// Get active keyset for mint with the lowest fees
///
/// Queries 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 active_keysets = self.get_active_mint_keysets().await?;

let keyset_with_lowest_fee = active_keysets
.into_iter()
.min_by_key(|key| key.input_fee_ppk)
.ok_or(Error::NoActiveKeyset)?;
Ok(keyset_with_lowest_fee)
}
}

0 comments on commit e5c81d3

Please sign in to comment.