Skip to content

Commit

Permalink
improve: use 'Proof' type for wallet check spendable not 'MintProof'
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Dec 3, 2023
1 parent dd3e962 commit fa1d540
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
8 changes: 4 additions & 4 deletions bindings/cashu-sdk-ffi/src/cashu_sdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ enum InvoiceStatus {
};

interface ProofsStatus {
constructor(sequence<MintProof> spendable, sequence<MintProof> spent);
sequence<MintProof> spendable();
sequence<MintProof> spent();
constructor(sequence<Proof> spendable, sequence<Proof> spent);
sequence<Proof> spendable();
sequence<Proof> spent();
};


Expand Down Expand Up @@ -291,7 +291,7 @@ interface Melted {

interface Wallet {
// [Throws=CashuSdkError]
// ProofsStatus check_proofs_spent(sequence<MintProof> proofs);
// ProofsStatus check_proofs_spent(sequence<Proof> proofs);
[Throws=CashuSdkError]
RequestMintResponse request_mint(Amount amount);
[Throws=CashuSdkError]
Expand Down
8 changes: 4 additions & 4 deletions bindings/cashu-sdk-ffi/src/types/proofs_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;

use cashu_sdk::types::ProofsStatus as ProofsStatusSdk;

use crate::MintProof;
use crate::Proof;

pub struct ProofsStatus {
inner: ProofsStatusSdk,
Expand All @@ -23,7 +23,7 @@ impl From<ProofsStatusSdk> for ProofsStatus {
}

impl ProofsStatus {
pub fn new(spendable: Vec<Arc<MintProof>>, spent: Vec<Arc<MintProof>>) -> Self {
pub fn new(spendable: Vec<Arc<Proof>>, spent: Vec<Arc<Proof>>) -> Self {
Self {
inner: ProofsStatusSdk {
spendable: spendable
Expand All @@ -35,7 +35,7 @@ impl ProofsStatus {
}
}

pub fn spendable(&self) -> Vec<Arc<MintProof>> {
pub fn spendable(&self) -> Vec<Arc<Proof>> {
self.inner
.spendable
.clone()
Expand All @@ -44,7 +44,7 @@ impl ProofsStatus {
.collect()
}

pub fn spent(&self) -> Vec<Arc<MintProof>> {
pub fn spent(&self) -> Vec<Arc<Proof>> {
self.inner
.spent
.clone()
Expand Down
4 changes: 2 additions & 2 deletions bindings/cashu-sdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tokio::runtime::Runtime;

use crate::error::Result;
use crate::types::{Melted, SendProofs};
use crate::{Amount, Keys, MintProof};
use crate::{Amount, Keys};

static RUNTIME: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("Can't start Tokio runtime"));

Expand All @@ -33,7 +33,7 @@ impl Wallet {
}
}

pub fn check_proofs_spent(&self, proofs: Vec<Arc<MintProof>>) -> Result<Arc<ProofsStatus>> {
pub fn check_proofs_spent(&self, proofs: Vec<Arc<Proof>>) -> Result<Arc<ProofsStatus>> {
let proofs = RUNTIME.block_on(async {
self.inner
.check_proofs_spent(proofs.iter().map(|p| p.as_ref().deref().clone()).collect())
Expand Down
19 changes: 12 additions & 7 deletions crates/cashu-sdk/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
use std::str::FromStr;

use cashu::dhke::{construct_proofs, unblind_message};
#[cfg(feature = "nut07")]
use cashu::nuts::nut00::mint;
use cashu::nuts::{
BlindedMessages, BlindedSignature, Keys, Proof, Proofs, RequestMintResponse, SplitPayload,
SplitRequest, Token,
Expand Down Expand Up @@ -51,17 +53,20 @@ impl<C: Client> Wallet<C> {
}
}

// TODO: getter method for keys that if it cant get them try again

/// Check if a proof is spent
#[cfg(feature = "nut07")]
pub async fn check_proofs_spent(
&self,
proofs: Vec<cashu::nuts::nut00::mint::Proof>,
) -> Result<ProofsStatus, Error> {
pub async fn check_proofs_spent(&self, proofs: Proofs) -> Result<ProofsStatus, Error> {
let spendable = self
.client
.post_check_spendable(self.mint_url.clone().try_into()?, proofs.clone())
.post_check_spendable(
self.mint_url.clone().try_into()?,
proofs
.clone()
.into_iter()
.map(|p| p.into())
.collect::<mint::Proofs>()
.clone(),
)
.await?;

// Separate proofs in spent and unspent based on mint response
Expand Down
5 changes: 2 additions & 3 deletions crates/cashu/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
use serde::{Deserialize, Serialize};

use crate::nuts::nut00::mint;
use crate::nuts::{Id, Proofs};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProofsStatus {
pub spendable: mint::Proofs,
pub spent: mint::Proofs,
pub spendable: Proofs,
pub spent: Proofs,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
Expand Down

0 comments on commit fa1d540

Please sign in to comment.