From fa1d54083ee3ed9c73576426c69a7594fee03c89 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Sun, 3 Dec 2023 10:26:04 +0000 Subject: [PATCH] improve: use 'Proof' type for wallet check spendable not 'MintProof' --- bindings/cashu-sdk-ffi/src/cashu_sdk.udl | 8 ++++---- .../cashu-sdk-ffi/src/types/proofs_status.rs | 8 ++++---- bindings/cashu-sdk-ffi/src/wallet.rs | 4 ++-- crates/cashu-sdk/src/wallet.rs | 19 ++++++++++++------- crates/cashu/src/types.rs | 5 ++--- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/bindings/cashu-sdk-ffi/src/cashu_sdk.udl b/bindings/cashu-sdk-ffi/src/cashu_sdk.udl index 6e428746..ceaeee7c 100644 --- a/bindings/cashu-sdk-ffi/src/cashu_sdk.udl +++ b/bindings/cashu-sdk-ffi/src/cashu_sdk.udl @@ -257,9 +257,9 @@ enum InvoiceStatus { }; interface ProofsStatus { - constructor(sequence spendable, sequence spent); - sequence spendable(); - sequence spent(); + constructor(sequence spendable, sequence spent); + sequence spendable(); + sequence spent(); }; @@ -291,7 +291,7 @@ interface Melted { interface Wallet { // [Throws=CashuSdkError] - // ProofsStatus check_proofs_spent(sequence proofs); + // ProofsStatus check_proofs_spent(sequence proofs); [Throws=CashuSdkError] RequestMintResponse request_mint(Amount amount); [Throws=CashuSdkError] diff --git a/bindings/cashu-sdk-ffi/src/types/proofs_status.rs b/bindings/cashu-sdk-ffi/src/types/proofs_status.rs index 992b7ce1..ff54439c 100644 --- a/bindings/cashu-sdk-ffi/src/types/proofs_status.rs +++ b/bindings/cashu-sdk-ffi/src/types/proofs_status.rs @@ -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, @@ -23,7 +23,7 @@ impl From for ProofsStatus { } impl ProofsStatus { - pub fn new(spendable: Vec>, spent: Vec>) -> Self { + pub fn new(spendable: Vec>, spent: Vec>) -> Self { Self { inner: ProofsStatusSdk { spendable: spendable @@ -35,7 +35,7 @@ impl ProofsStatus { } } - pub fn spendable(&self) -> Vec> { + pub fn spendable(&self) -> Vec> { self.inner .spendable .clone() @@ -44,7 +44,7 @@ impl ProofsStatus { .collect() } - pub fn spent(&self) -> Vec> { + pub fn spent(&self) -> Vec> { self.inner .spent .clone() diff --git a/bindings/cashu-sdk-ffi/src/wallet.rs b/bindings/cashu-sdk-ffi/src/wallet.rs index ff7627a9..89318fb3 100644 --- a/bindings/cashu-sdk-ffi/src/wallet.rs +++ b/bindings/cashu-sdk-ffi/src/wallet.rs @@ -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 = Lazy::new(|| Runtime::new().expect("Can't start Tokio runtime")); @@ -33,7 +33,7 @@ impl Wallet { } } - pub fn check_proofs_spent(&self, proofs: Vec>) -> Result> { + pub fn check_proofs_spent(&self, proofs: Vec>) -> Result> { let proofs = RUNTIME.block_on(async { self.inner .check_proofs_spent(proofs.iter().map(|p| p.as_ref().deref().clone()).collect()) diff --git a/crates/cashu-sdk/src/wallet.rs b/crates/cashu-sdk/src/wallet.rs index 7981901b..af8493b1 100644 --- a/crates/cashu-sdk/src/wallet.rs +++ b/crates/cashu-sdk/src/wallet.rs @@ -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, @@ -51,17 +53,20 @@ impl Wallet { } } - // 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, - ) -> Result { + pub async fn check_proofs_spent(&self, proofs: Proofs) -> Result { 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::() + .clone(), + ) .await?; // Separate proofs in spent and unspent based on mint response diff --git a/crates/cashu/src/types.rs b/crates/cashu/src/types.rs index ce2bb65f..128db15b 100644 --- a/crates/cashu/src/types.rs +++ b/crates/cashu/src/types.rs @@ -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)]