From 1c17c577f759a26826968e49a86c2a7273851567 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Fri, 29 Dec 2023 08:00:24 +0000 Subject: [PATCH] refactor: melt and mint quote in sdk-ffi --- bindings/cashu-sdk-ffi/src/cashu_sdk.udl | 6 ++++- bindings/cashu-sdk-ffi/src/wallet.rs | 31 +++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/bindings/cashu-sdk-ffi/src/cashu_sdk.udl b/bindings/cashu-sdk-ffi/src/cashu_sdk.udl index dae52d71..af5185da 100644 --- a/bindings/cashu-sdk-ffi/src/cashu_sdk.udl +++ b/bindings/cashu-sdk-ffi/src/cashu_sdk.udl @@ -309,7 +309,9 @@ interface Wallet { // ProofsStatus check_proofs_spent(sequence 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 mint(string quote); [Throws=CashuSdkError] sequence receive(string encoded_token); @@ -317,6 +319,8 @@ interface Wallet { sequence process_swap_response(PreMintSecrets blinded_messages, sequence promises); [Throws=CashuSdkError] SendProofs send(Amount amount, sequence proofs); + [Throws=CashuSdkError] + MeltQuote melt_quote(CurrencyUnit unit, Bolt11Invoice request); [Throws=CashuSdkError] Melted melt(string quote_id, sequence proofs); [Throws=CashuSdkError] diff --git a/bindings/cashu-sdk-ffi/src/wallet.rs b/bindings/cashu-sdk-ffi/src/wallet.rs index e6a442b6..6e3464b0 100644 --- a/bindings/cashu-sdk-ffi/src/wallet.rs +++ b/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, unit: CurrencyUnit) -> Result> { + 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>> { let proofs = RUNTIME.block_on(async { self.inner.write().unwrap().mint("e).await })?; @@ -122,6 +135,22 @@ impl Wallet { Ok(Arc::new(send_proofs.into())) } + pub fn melt_quote( + &self, + unit: CurrencyUnit, + request: Arc, + ) -> Result> { + 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>) -> Result> { let melted = RUNTIME.block_on(async { self.inner