Эх сурвалжийг харах

use amount type for blank messages

thesimplekid 1 жил өмнө
parent
commit
77f5165061

+ 2 - 2
integration_test/src/main.rs

@@ -45,7 +45,7 @@ async fn main() {
         Invoice::from_str(MELTINVOICE).unwrap(),
         proofs,
         // TODO:
-        10,
+        Amount::from_sat(10),
     )
     .await;
 
@@ -159,7 +159,7 @@ async fn test_send(wallet: &CashuWallet, proofs: Proofs) -> Proofs {
     send.send_proofs
 }
 
-async fn test_melt(wallet: &CashuWallet, invoice: Invoice, proofs: Proofs, fee_reserve: u64) {
+async fn test_melt(wallet: &CashuWallet, invoice: Invoice, proofs: Proofs, fee_reserve: Amount) {
     let res = wallet.melt(invoice, proofs, fee_reserve).await.unwrap();
 
     println!("{:?}", res);

+ 1 - 1
src/cashu_wallet.rs

@@ -224,7 +224,7 @@ impl CashuWallet {
         &self,
         invoice: Invoice,
         proofs: Proofs,
-        fee_reserve: u64,
+        fee_reserve: Amount,
     ) -> Result<Melted, Error> {
         let change = BlindedMessages::blank(fee_reserve)?;
         let melt_response = self

+ 8 - 4
src/types.rs

@@ -60,10 +60,14 @@ impl BlindedMessages {
     }
 
     /// Blank Outputs used for NUT-08 change
-    pub fn blank(fee_reserve: u64) -> Result<Self, Error> {
+    pub fn blank(fee_reserve: Amount) -> Result<Self, Error> {
         let mut blinded_messages = BlindedMessages::default();
 
-        let count = ((fee_reserve as f64).log2().ceil() as u64).max(1);
+        let count = (fee_reserve
+            .to_float_in(bitcoin::Denomination::Satoshi)
+            .log2()
+            .ceil() as u64)
+            .max(1);
 
         for _i in 0..count {
             let secret = generate_secret();
@@ -390,10 +394,10 @@ mod tests {
 
     #[test]
     fn test_blank_blinded_messages() {
-        let b = BlindedMessages::blank(1000).unwrap();
+        let b = BlindedMessages::blank(Amount::from_sat(1000)).unwrap();
         assert_eq!(b.blinded_messages.len(), 10);
 
-        let b = BlindedMessages::blank(1).unwrap();
+        let b = BlindedMessages::blank(Amount::from_sat(1)).unwrap();
         assert_eq!(b.blinded_messages.len(), 1);
     }
 }