Przeglądaj źródła

refactor: melt and mint quote in sdk-ffi

thesimplekid 1 rok temu
rodzic
commit
1c17c577f7

+ 5 - 1
bindings/cashu-sdk-ffi/src/cashu_sdk.udl

@@ -309,7 +309,9 @@ interface Wallet {
 	// ProofsStatus check_proofs_spent(sequence<Proof> proofs);
     [Throws=CashuSdkError]
 	Token mint_token(Amount amount, CurrencyUnit? unit, string? memo);
-    [Throws=CashuSdkError]
+	[Throws=CashuSdkError]
+	MintQuote mint_quote(Amount amount, CurrencyUnit unit);
+	[Throws=CashuSdkError]
 	sequence<Proof> mint(string quote);
     [Throws=CashuSdkError]
 	sequence<Proof> receive(string encoded_token);
@@ -318,6 +320,8 @@ interface Wallet {
     [Throws=CashuSdkError]
 	SendProofs send(Amount amount, sequence<Proof> proofs);
     [Throws=CashuSdkError]
+	MeltQuote melt_quote(CurrencyUnit unit, Bolt11Invoice request);
+    [Throws=CashuSdkError]
 	Melted melt(string quote_id, sequence<Proof> proofs);
     [Throws=CashuSdkError]
 	string proofs_to_token(sequence<Proof> proof, CurrencyUnit? unit, string? memo);

+ 30 - 1
bindings/cashu-sdk-ffi/src/wallet.rs

@@ -2,7 +2,8 @@ use std::ops::Deref;
 use std::sync::{Arc, RwLock};
 
 use cashu_ffi::{
-    BlindedSignature, CurrencyUnit, MeltQuote, MintQuote, PreMintSecrets, Proof, Token,
+    BlindedSignature, Bolt11Invoice, CurrencyUnit, MeltQuote, MintQuote, PreMintSecrets, Proof,
+    Token,
 };
 use cashu_sdk::client::minreq_client::HttpClient;
 use cashu_sdk::types::ProofsStatus;
@@ -76,6 +77,18 @@ impl Wallet {
         Ok(Arc::new(token.into()))
     }
 
+    pub fn mint_quote(&self, amount: Arc<Amount>, unit: CurrencyUnit) -> Result<Arc<MintQuote>> {
+        let quote = RUNTIME.block_on(async {
+            self.inner
+                .write()
+                .unwrap()
+                .mint_quote(*amount.as_ref().deref(), unit.into())
+                .await
+        })?;
+
+        Ok(Arc::new(quote.into()))
+    }
+
     pub fn mint(&self, quote: String) -> Result<Vec<Arc<Proof>>> {
         let proofs = RUNTIME.block_on(async { self.inner.write().unwrap().mint(&quote).await })?;
 
@@ -122,6 +135,22 @@ impl Wallet {
         Ok(Arc::new(send_proofs.into()))
     }
 
+    pub fn melt_quote(
+        &self,
+        unit: CurrencyUnit,
+        request: Arc<Bolt11Invoice>,
+    ) -> Result<Arc<MeltQuote>> {
+        let melt_quote = RUNTIME.block_on(async {
+            self.inner
+                .write()
+                .unwrap()
+                .melt_quote(unit.into(), request.as_ref().deref().clone())
+                .await
+        })?;
+
+        Ok(Arc::new(melt_quote.into()))
+    }
+
     pub fn melt(&self, quote_id: String, proofs: Vec<Arc<Proof>>) -> Result<Arc<Melted>> {
         let melted = RUNTIME.block_on(async {
             self.inner