mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-10 23:56:18 +01:00
improve: use 'Proof' type for wallet check spendable not 'MintProof'
This commit is contained in:
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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<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
|
||||
@@ -35,7 +35,7 @@ impl ProofsStatus {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spendable(&self) -> Vec<Arc<MintProof>> {
|
||||
pub fn spendable(&self) -> Vec<Arc<Proof>> {
|
||||
self.inner
|
||||
.spendable
|
||||
.clone()
|
||||
@@ -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()
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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<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
|
||||
|
||||
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user