refactor(cdk-redb): abstract error

This commit is contained in:
thesimplekid
2024-04-14 23:25:55 +01:00
parent 1dd08ae537
commit 35540f4304
2 changed files with 5 additions and 69 deletions

View File

@@ -1,20 +1,20 @@
use std::collections::HashMap;
use std::num::ParseIntError;
use std::str::FromStr;
use std::sync::Arc;
use async_trait::async_trait;
use cdk::cdk_database::{self, MintDatabase};
use cdk::cdk_database::MintDatabase;
use cdk::dhke::hash_to_curve;
use cdk::mint::MintKeySetInfo;
use cdk::nuts::{BlindSignature, CurrencyUnit, Id, MintInfo, Proof, PublicKey};
use cdk::secret::Secret;
use cdk::types::{MeltQuote, MintQuote};
use redb::{Database, ReadableTable, TableDefinition};
use thiserror::Error;
use tokio::sync::Mutex;
use tracing::debug;
use super::error::Error;
const ACTIVE_KEYSETS_TABLE: TableDefinition<&str, &str> = TableDefinition::new("active_keysets");
const KEYSETS_TABLE: TableDefinition<&str, &str> = TableDefinition::new("keysets");
const MINT_QUOTES_TABLE: TableDefinition<&str, &str> = TableDefinition::new("mint_quotes");
@@ -29,42 +29,6 @@ const BLINDED_SIGNATURES: TableDefinition<[u8; 33], &str> =
const DATABASE_VERSION: u64 = 0;
#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
Redb(#[from] redb::Error),
#[error(transparent)]
Database(#[from] redb::DatabaseError),
#[error(transparent)]
Transaction(#[from] redb::TransactionError),
#[error(transparent)]
Commit(#[from] redb::CommitError),
#[error(transparent)]
Table(#[from] redb::TableError),
#[error(transparent)]
Storage(#[from] redb::StorageError),
#[error(transparent)]
Serde(#[from] serde_json::Error),
#[error(transparent)]
ParseInt(#[from] ParseIntError),
#[error(transparent)]
CDKDatabase(#[from] cdk_database::Error),
#[error(transparent)]
CDK(#[from] cdk::error::Error),
#[error(transparent)]
CDKNUT02(#[from] cdk::nuts::nut02::Error),
#[error(transparent)]
CDKNUT00(#[from] cdk::nuts::nut00::Error),
#[error("Unknown Mint Info")]
UnknownMintInfo,
}
impl From<Error> for cdk_database::Error {
fn from(e: Error) -> Self {
Self::Database(Box::new(e))
}
}
#[derive(Debug, Clone)]
pub struct MintRedbDatabase {
db: Arc<Mutex<Database>>,

View File

@@ -1,44 +1,16 @@
use std::collections::HashMap;
use std::num::ParseIntError;
use std::str::FromStr;
use std::sync::Arc;
use async_trait::async_trait;
use cdk::cdk_database::{self, WalletDatabase};
use cdk::cdk_database::WalletDatabase;
use cdk::nuts::{Id, KeySetInfo, Keys, MintInfo, Proofs};
use cdk::types::{MeltQuote, MintQuote};
use cdk::url::UncheckedUrl;
use redb::{Database, MultimapTableDefinition, ReadableTable, TableDefinition};
use thiserror::Error;
use tokio::sync::Mutex;
#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
Redb(#[from] redb::Error),
#[error(transparent)]
Database(#[from] redb::DatabaseError),
#[error(transparent)]
Transaction(#[from] redb::TransactionError),
#[error(transparent)]
Commit(#[from] redb::CommitError),
#[error(transparent)]
Table(#[from] redb::TableError),
#[error(transparent)]
Storage(#[from] redb::StorageError),
#[error(transparent)]
Serde(#[from] serde_json::Error),
#[error(transparent)]
ParseInt(#[from] ParseIntError),
#[error(transparent)]
CDKDatabase(#[from] cdk_database::Error),
}
impl From<Error> for cdk_database::Error {
fn from(e: Error) -> Self {
Self::Database(Box::new(e))
}
}
use super::error::Error;
const MINTS_TABLE: TableDefinition<&str, &str> = TableDefinition::new("mints_table");
const MINT_KEYSETS_TABLE: MultimapTableDefinition<&str, &str> =