mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-24 08:05:02 +01:00
refactor: get proofs by spending condition
This commit is contained in:
@@ -5,7 +5,7 @@ use std::sync::Arc;
|
||||
use async_trait::async_trait;
|
||||
use cdk::cdk_database;
|
||||
use cdk::cdk_database::WalletDatabase;
|
||||
use cdk::nuts::{Id, KeySetInfo, Keys, MintInfo, Proofs, PublicKey, State};
|
||||
use cdk::nuts::{Id, KeySetInfo, Keys, MintInfo, Proofs, PublicKey, SpendingConditions, State};
|
||||
use cdk::types::{MeltQuote, MintQuote, ProofInfo};
|
||||
use cdk::url::UncheckedUrl;
|
||||
use redb::{Database, MultimapTableDefinition, ReadableTable, TableDefinition};
|
||||
@@ -400,6 +400,7 @@ impl WalletDatabase for RedbWalletDatabase {
|
||||
&self,
|
||||
mint_url: Option<UncheckedUrl>,
|
||||
state: Option<Vec<State>>,
|
||||
spending_conditions: Option<Vec<SpendingConditions>>,
|
||||
) -> Result<Option<Proofs>, Self::Err> {
|
||||
let db = self.db.lock().await;
|
||||
let read_txn = db.begin_read().map_err(Error::from)?;
|
||||
@@ -414,25 +415,10 @@ impl WalletDatabase for RedbWalletDatabase {
|
||||
let mut proof = None;
|
||||
|
||||
if let Ok(proof_info) = serde_json::from_str::<ProofInfo>(v.value()) {
|
||||
match (&mint_url, &state) {
|
||||
(Some(mint_url), Some(state)) => {
|
||||
if state.contains(&proof_info.state)
|
||||
&& mint_url.eq(&proof_info.mint_url)
|
||||
{
|
||||
proof = Some(proof_info.proof);
|
||||
}
|
||||
}
|
||||
(Some(mint_url), None) => {
|
||||
if mint_url.eq(&proof_info.mint_url) {
|
||||
proof = Some(proof_info.proof);
|
||||
}
|
||||
}
|
||||
(None, Some(state)) => {
|
||||
if state.contains(&proof_info.state) {
|
||||
proof = Some(proof_info.proof);
|
||||
}
|
||||
}
|
||||
(None, None) => proof = Some(proof_info.proof),
|
||||
match proof_info.matches_conditions(&mint_url, &state, &spending_conditions) {
|
||||
Ok(true) => proof = Some(proof_info.proof),
|
||||
Ok(false) => (),
|
||||
Err(_) => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user