Переглянути джерело

refactor: store keys amount as string

thesimplekid 11 місяців тому
батько
коміт
60f7c39183

+ 3 - 3
crates/cdk-rexie/src/wallet.rs

@@ -1,6 +1,6 @@
 use std::collections::HashMap;
+use std::rc::Rc;
 use std::result::Result;
-use std::sync::Arc;
 
 use async_trait::async_trait;
 use cdk::cdk_database::WalletDatabase;
@@ -48,7 +48,7 @@ unsafe impl Sync for Error {}
 
 #[derive(Debug, Clone)]
 pub struct RexieWalletDatabase {
-    db: Arc<Mutex<Rexie>>,
+    db: Rc<Mutex<Rexie>>,
 }
 
 // These are okay because we never actually send across threads in the browser
@@ -105,7 +105,7 @@ impl RexieWalletDatabase {
             .unwrap();
 
         Ok(Self {
-            db: Arc::new(Mutex::new(rexie)),
+            db: Rc::new(Mutex::new(rexie)),
         })
     }
 }

+ 2 - 2
crates/cdk/src/mint.rs

@@ -716,8 +716,8 @@ impl Mint {
             quote: quote.id,
             paid: quote.paid,
             expiry: quote.expiry,
-            amount: u64::from(quote.amount),
-            fee_reserve: u64::from(quote.fee_reserve),
+            amount: quote.amount,
+            fee_reserve: quote.fee_reserve,
         })
     }
 

+ 2 - 2
crates/cdk/src/nuts/nut00.rs

@@ -538,7 +538,7 @@ impl Token {
         })
     }
 
-    pub fn token_info(&self) -> (u64, String) {
+    pub fn token_info(&self) -> (Amount, String) {
         let mut amount = Amount::ZERO;
 
         for proofs in &self.token {
@@ -547,7 +547,7 @@ impl Token {
             }
         }
 
-        (amount.into(), self.token[0].mint.to_string())
+        (amount, self.token[0].mint.to_string())
     }
 }
 

Різницю між файлами не показано, бо вона завелика
+ 7 - 6
crates/cdk/src/nuts/nut01/mod.rs


+ 4 - 2
crates/cdk/src/nuts/nut02.rs

@@ -186,9 +186,11 @@ impl From<&Keys> for Id {
             5 - prefix it with a keyset ID version byte
         */
 
-        // Note: Keys are a BTreeMap so are already sorted by amount in ascending order
+        let mut keys: Vec<(&String, &super::PublicKey)> = map.iter().collect();
 
-        let pubkeys_concat: Vec<u8> = map
+        keys.sort_by_key(|(k, _v)| u64::from_str(k).unwrap());
+
+        let pubkeys_concat: Vec<u8> = keys
             .iter()
             .map(|(_, pubkey)| pubkey.to_bytes())
             .collect::<Vec<[u8; 33]>>()

+ 4 - 4
crates/cdk/src/nuts/nut05.rs

@@ -23,9 +23,9 @@ pub struct MeltQuoteBolt11Response {
     /// Quote Id
     pub quote: String,
     /// The amount that needs to be provided
-    pub amount: u64,
+    pub amount: Amount,
     /// The fee reserve that is required
-    pub fee_reserve: u64,
+    pub fee_reserve: Amount,
     /// Whether the the request haas be paid
     pub paid: bool,
     /// Unix timestamp until the quote is valid
@@ -36,8 +36,8 @@ impl From<MeltQuote> for MeltQuoteBolt11Response {
     fn from(melt_quote: MeltQuote) -> MeltQuoteBolt11Response {
         MeltQuoteBolt11Response {
             quote: melt_quote.id,
-            amount: u64::from(melt_quote.amount),
-            fee_reserve: u64::from(melt_quote.fee_reserve),
+            amount: melt_quote.amount,
+            fee_reserve: melt_quote.fee_reserve,
             paid: melt_quote.paid,
             expiry: melt_quote.expiry,
         }

+ 4 - 4
crates/cdk/src/wallet.rs

@@ -425,7 +425,7 @@ impl Wallet {
             )
             .await?;
 
-        let keys = self.get_keyset_keys(&mint_url, active_keyset_id).await?;
+        let keys = self.localstore.get_keys(&active_keyset_id).await?; //.get_keyset_keys(&mint_url, active_keyset_id).await?;
 
         // Verify the signature DLEQ is valid
         {
@@ -443,7 +443,7 @@ impl Wallet {
             mint_res.signatures,
             premint_secrets.rs(),
             premint_secrets.secrets(),
-            &keys,
+            &keys.unwrap(),
         )?;
 
         let minted_amount = proofs.iter().map(|p| p.amount).sum();
@@ -758,10 +758,10 @@ impl Wallet {
 
         let quote = MeltQuote {
             id: quote_res.quote,
-            amount: quote_res.amount.into(),
+            amount: quote_res.amount,
             request,
             unit,
-            fee_reserve: quote_res.fee_reserve.into(),
+            fee_reserve: quote_res.fee_reserve,
             paid: quote_res.paid,
             expiry: quote_res.expiry,
         };

Деякі файли не було показано, через те що забагато файлів було змінено