refactor: melt and mint quote in sdk-ffi

This commit is contained in:
thesimplekid
2023-12-29 08:00:24 +00:00
parent 754936d701
commit 1c17c577f7
2 changed files with 35 additions and 2 deletions

View File

@@ -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);
@@ -317,6 +319,8 @@ interface Wallet {
sequence<Proof> process_swap_response(PreMintSecrets blinded_messages, sequence<BlindedSignature> promises);
[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]

View File

@@ -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