Cesar Rodas há 1 mês atrás
pai
commit
64a0aec57a
2 ficheiros alterados com 21 adições e 1 exclusões
  1. 5 0
      crates/cashu/src/amount.rs
  2. 16 1
      crates/cdk/src/wallet/keysets.rs

+ 5 - 0
crates/cashu/src/amount.rs

@@ -189,6 +189,11 @@ impl Amount {
         to_unit(self.0, current_unit, target_unit)
     }
 
+    /// Convert to u64
+    pub fn to_u64(self) -> u64 {
+        self.0
+    }
+
     /// Convert to i64
     pub fn to_i64(self) -> Option<i64> {
         if self.0 <= i64::MAX as u64 {

+ 16 - 1
crates/cdk/src/wallet/keysets.rs

@@ -1,4 +1,4 @@
-use std::collections::HashMap;
+use std::collections::{BTreeMap, HashMap};
 
 use cdk_common::nut02::{KeySetInfos, KeySetInfosMethods};
 use tracing::instrument;
@@ -6,6 +6,21 @@ use tracing::instrument;
 use crate::nuts::{Id, KeySetInfo, Keys};
 use crate::{Error, Wallet};
 
+pub struct ActiveKeys {
+    keysets: KeySetInfos,
+    keys: BTreeMap<Id, Keys>,
+}
+
+impl ActiveKeys {
+    /// Get supported amounts for the given keyset info
+    pub fn get_supported_amounts(&self, id: &Id) -> Result<Vec<u64>, Error> {
+        self.keys
+            .get(id)
+            .map(|x| x.iter().map(|(amount, _)| amount.to_u64()).collect())
+            .ok_or(Error::UnknownKeySet)
+    }
+}
+
 impl Wallet {
     /// Load keys for mint keyset
     ///