refactor: removed unneeded structs from nut07 state change

This commit is contained in:
thesimplekid
2024-01-06 15:04:13 +00:00
parent f9f88edfd8
commit 7006594933
4 changed files with 5 additions and 77 deletions

View File

@@ -1,7 +1,5 @@
//! Minreq http Client
use std::println;
use async_trait::async_trait;
use cashu::nuts::{
BlindedMessage, CurrencyUnit, KeySet, KeysResponse, KeysetResponse, MeltBolt11Request,
@@ -11,6 +9,7 @@ use cashu::nuts::{
};
#[cfg(feature = "nut07")]
use cashu::nuts::{CheckStateRequest, CheckStateResponse};
#[cfg(feature = "nut07")]
use cashu::secret::Secret;
use cashu::{Amount, Bolt11Invoice};
use serde_json::Value;

View File

@@ -8,6 +8,7 @@ use cashu::nuts::{
MeltQuoteBolt11Response, MintBolt11Response, MintInfo, MintQuoteBolt11Response, PreMintSecrets,
Proof, SwapRequest, SwapResponse,
};
#[cfg(feature = "nut07")]
use cashu::secret::Secret;
use cashu::{utils, Amount};
use serde::{Deserialize, Serialize};

View File

@@ -2,7 +2,7 @@ use std::collections::HashSet;
use cashu::dhke::{sign_message, verify_message};
#[cfg(feature = "nut07")]
use cashu::nuts::nut07::State;
use cashu::nuts::nut07::{ProofState, State};
use cashu::nuts::{
BlindedMessage, BlindedSignature, MeltBolt11Request, MeltBolt11Response, Proof, SwapRequest,
SwapResponse, *,
@@ -373,26 +373,12 @@ impl<L: LocalStore> Mint<L> {
&self,
check_spendable: &CheckStateRequest,
) -> Result<CheckStateResponse, Error> {
use cashu::nuts::nut07::ProofState;
let mut states = Vec::with_capacity(check_spendable.secrets.len());
for secret in &check_spendable.secrets {
let state = if self
.localstore
.get_spent_proof(secret)
.await
.unwrap()
.is_some()
{
let state = if self.localstore.get_spent_proof(secret).await?.is_some() {
State::Spent
} else if self
.localstore
.get_pending_proof(secret)
.await
.unwrap()
.is_some()
{
} else if self.localstore.get_pending_proof(secret).await?.is_some() {
State::Pending
} else {
State::Unspent

View File

@@ -428,64 +428,6 @@ impl PartialOrd for Proof {
}
}
impl From<Proof> for mint::Proof {
fn from(proof: Proof) -> Self {
Self {
amount: Some(proof.amount),
secret: proof.secret,
c: Some(proof.c),
keyset_id: Some(proof.keyset_id),
}
}
}
impl TryFrom<mint::Proof> for Proof {
type Error = Error;
fn try_from(mint_proof: mint::Proof) -> Result<Proof, Self::Error> {
Ok(Self {
keyset_id: mint_proof.keyset_id.ok_or(Error::MissingProofField)?,
amount: mint_proof.amount.ok_or(Error::MissingProofField)?,
secret: mint_proof.secret,
c: mint_proof.c.ok_or(Error::MissingProofField)?,
})
}
}
pub mod mint {
use serde::{Deserialize, Serialize};
use super::PublicKey;
use crate::nuts::nut02::Id;
use crate::secret::Secret;
use crate::Amount;
/// Proofs [NUT-00]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Proof {
/// Amount in satoshi
#[serde(skip_serializing)]
pub amount: Option<Amount>,
/// Secret message
#[serde(skip_serializing)]
pub secret: Secret,
/// Unblinded signature
#[serde(rename = "C")]
pub c: Option<PublicKey>,
/// `Keyset id`
#[serde(skip_serializing)]
#[serde(rename = "id")]
pub keyset_id: Option<Id>,
}
/// List of proofs
pub type Proofs = Vec<Proof>;
pub fn mint_proofs_from_proofs(proofs: crate::nuts::Proofs) -> Proofs {
proofs.iter().map(|p| p.to_owned().into()).collect()
}
}
#[cfg(test)]
mod tests {
use std::str::FromStr;