mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-20 14:14:49 +01:00
refactor: use MintUrl::from_str
This commit is contained in:
@@ -32,6 +32,9 @@ pub enum Error {
|
||||
/// BIP32 Error
|
||||
#[error(transparent)]
|
||||
BIP32(#[from] bitcoin::bip32::Error),
|
||||
/// Mint Url Error
|
||||
#[error(transparent)]
|
||||
MintUrl(#[from] cdk::mint_url::Error),
|
||||
/// Could Not Initialize Database
|
||||
#[error("Could not initialize database")]
|
||||
CouldNotInitialize,
|
||||
|
||||
@@ -8,6 +8,7 @@ use async_trait::async_trait;
|
||||
use bitcoin::bip32::DerivationPath;
|
||||
use cdk::cdk_database::{self, MintDatabase};
|
||||
use cdk::mint::{MintKeySetInfo, MintQuote};
|
||||
use cdk::mint_url::MintUrl;
|
||||
use cdk::nuts::nut05::QuoteState;
|
||||
use cdk::nuts::{
|
||||
BlindSignature, CurrencyUnit, Id, MeltQuoteState, MintQuoteState, Proof, Proofs, PublicKey,
|
||||
@@ -792,7 +793,7 @@ fn sqlite_row_to_mint_quote(row: SqliteRow) -> Result<MintQuote, Error> {
|
||||
|
||||
Ok(MintQuote {
|
||||
id: row_id,
|
||||
mint_url: row_mint_url.into(),
|
||||
mint_url: MintUrl::from_str(&row_mint_url)?,
|
||||
amount: Amount::from(row_amount as u64),
|
||||
unit: CurrencyUnit::from_str(&row_unit).map_err(Error::from)?,
|
||||
request: row_request,
|
||||
|
||||
@@ -35,6 +35,9 @@ pub enum Error {
|
||||
/// Secret Error
|
||||
#[error(transparent)]
|
||||
CDKSECRET(#[from] cdk::secret::Error),
|
||||
/// Mint Url
|
||||
#[error(transparent)]
|
||||
MintUrl(#[from] cdk::mint_url::Error),
|
||||
/// BIP32 Error
|
||||
#[error(transparent)]
|
||||
BIP32(#[from] bitcoin::bip32::Error),
|
||||
|
||||
@@ -199,12 +199,15 @@ FROM mint
|
||||
|
||||
let mints = rec
|
||||
.into_iter()
|
||||
.map(|row| {
|
||||
.flat_map(|row| {
|
||||
let mint_url: String = row.get("mint_url");
|
||||
|
||||
// Attempt to parse mint_url and convert mint_info
|
||||
let mint_result = MintUrl::from_str(&mint_url).ok();
|
||||
let mint_info = sqlite_row_to_mint_info(&row).ok();
|
||||
|
||||
(mint_url.into(), mint_info)
|
||||
// Combine mint_result and mint_info into an Option tuple
|
||||
mint_result.map(|mint| (mint, mint_info))
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -811,7 +814,7 @@ fn sqlite_row_to_mint_quote(row: &SqliteRow) -> Result<MintQuote, Error> {
|
||||
|
||||
Ok(MintQuote {
|
||||
id: row_id,
|
||||
mint_url: row_mint_url.into(),
|
||||
mint_url: MintUrl::from_str(&row_mint_url)?,
|
||||
amount: Amount::from(row_amount as u64),
|
||||
unit: CurrencyUnit::from_str(&row_unit).map_err(Error::from)?,
|
||||
request: row_request,
|
||||
@@ -869,7 +872,7 @@ fn sqlite_row_to_proof_info(row: &SqliteRow) -> Result<ProofInfo, Error> {
|
||||
Ok(ProofInfo {
|
||||
proof,
|
||||
y: PublicKey::from_slice(&y)?,
|
||||
mint_url: row_mint_url.into(),
|
||||
mint_url: MintUrl::from_str(&row_mint_url)?,
|
||||
state: State::from_str(&row_state)?,
|
||||
spending_condition: row_spending_condition.and_then(|r| serde_json::from_str(&r).ok()),
|
||||
unit: CurrencyUnit::from_str(&row_unit).map_err(Error::from)?,
|
||||
|
||||
Reference in New Issue
Block a user