mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-22 23:25:22 +01:00
refactor(cdk-redb): abstract error
This commit is contained in:
@@ -26,6 +26,8 @@ cdk = { path = "./crates/cdk", default-features = false }
|
|||||||
thiserror = "1.0.50"
|
thiserror = "1.0.50"
|
||||||
async-trait = "0.1.74"
|
async-trait = "0.1.74"
|
||||||
tracing = { version = "0.1", default-features = false }
|
tracing = { version = "0.1", default-features = false }
|
||||||
|
serde = { version = "1.0.160", default-features = false, features = ["derive"]}
|
||||||
|
serde_json = "1.0.96"
|
||||||
|
|
||||||
[profile]
|
[profile]
|
||||||
|
|
||||||
|
|||||||
@@ -20,4 +20,5 @@ redb = "2.0.0"
|
|||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
serde_json = "1.0.96"
|
serde.workspace = true
|
||||||
|
serde_json.workspace = true
|
||||||
|
|||||||
52
crates/cdk-redb/src/error.rs
Normal file
52
crates/cdk-redb/src/error.rs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
use std::num::ParseIntError;
|
||||||
|
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum Error {
|
||||||
|
/// Redb Error
|
||||||
|
#[error(transparent)]
|
||||||
|
Redb(#[from] redb::Error),
|
||||||
|
/// Redb Database Error
|
||||||
|
#[error(transparent)]
|
||||||
|
Database(#[from] redb::DatabaseError),
|
||||||
|
/// Redb Transaction Error
|
||||||
|
#[error(transparent)]
|
||||||
|
Transaction(#[from] redb::TransactionError),
|
||||||
|
/// Redb Commit Error
|
||||||
|
#[error(transparent)]
|
||||||
|
Commit(#[from] redb::CommitError),
|
||||||
|
/// Redb Table Error
|
||||||
|
#[error(transparent)]
|
||||||
|
Table(#[from] redb::TableError),
|
||||||
|
/// Redb Storage Error
|
||||||
|
#[error(transparent)]
|
||||||
|
Storage(#[from] redb::StorageError),
|
||||||
|
/// Serde Json Error
|
||||||
|
#[error(transparent)]
|
||||||
|
Serde(#[from] serde_json::Error),
|
||||||
|
/// Parse int Error
|
||||||
|
#[error(transparent)]
|
||||||
|
ParseInt(#[from] ParseIntError),
|
||||||
|
/// CDK Database Error
|
||||||
|
#[error(transparent)]
|
||||||
|
CDKDatabase(#[from] cdk::cdk_database::Error),
|
||||||
|
/// CDK Error
|
||||||
|
#[error(transparent)]
|
||||||
|
CDK(#[from] cdk::error::Error),
|
||||||
|
/// NUT02 Error
|
||||||
|
#[error(transparent)]
|
||||||
|
CDKNUT02(#[from] cdk::nuts::nut02::Error),
|
||||||
|
/// NUT00 Error
|
||||||
|
#[error(transparent)]
|
||||||
|
CDKNUT00(#[from] cdk::nuts::nut00::Error),
|
||||||
|
/// Unknown Mint Info
|
||||||
|
#[error("Unknown Mint Info")]
|
||||||
|
UnknownMintInfo,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Error> for cdk::cdk_database::Error {
|
||||||
|
fn from(e: Error) -> Self {
|
||||||
|
Self::Database(Box::new(e))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
pub mod error;
|
||||||
|
|
||||||
#[cfg(feature = "mint")]
|
#[cfg(feature = "mint")]
|
||||||
pub mod mint;
|
pub mod mint;
|
||||||
#[cfg(feature = "wallet")]
|
#[cfg(feature = "wallet")]
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::num::ParseIntError;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cdk::cdk_database::{self, MintDatabase};
|
use cdk::cdk_database::MintDatabase;
|
||||||
use cdk::dhke::hash_to_curve;
|
use cdk::dhke::hash_to_curve;
|
||||||
use cdk::nuts::{
|
use cdk::nuts::{
|
||||||
BlindSignature, CurrencyUnit, Id, MintInfo, MintKeySet as KeySet, Proof, PublicKey,
|
BlindSignature, CurrencyUnit, Id, MintInfo, MintKeySet as KeySet, Proof, PublicKey,
|
||||||
@@ -12,10 +11,11 @@ use cdk::nuts::{
|
|||||||
use cdk::secret::Secret;
|
use cdk::secret::Secret;
|
||||||
use cdk::types::{MeltQuote, MintQuote};
|
use cdk::types::{MeltQuote, MintQuote};
|
||||||
use redb::{Database, ReadableTable, TableDefinition};
|
use redb::{Database, ReadableTable, TableDefinition};
|
||||||
use thiserror::Error;
|
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
use super::error::Error;
|
||||||
|
|
||||||
const ACTIVE_KEYSETS_TABLE: TableDefinition<&str, &str> = TableDefinition::new("active_keysets");
|
const ACTIVE_KEYSETS_TABLE: TableDefinition<&str, &str> = TableDefinition::new("active_keysets");
|
||||||
const KEYSETS_TABLE: TableDefinition<&str, &str> = TableDefinition::new("keysets");
|
const KEYSETS_TABLE: TableDefinition<&str, &str> = TableDefinition::new("keysets");
|
||||||
const MINT_QUOTES_TABLE: TableDefinition<&str, &str> = TableDefinition::new("mint_quotes");
|
const MINT_QUOTES_TABLE: TableDefinition<&str, &str> = TableDefinition::new("mint_quotes");
|
||||||
@@ -30,42 +30,6 @@ const BLINDED_SIGNATURES: TableDefinition<[u8; 33], &str> =
|
|||||||
|
|
||||||
const DATABASE_VERSION: u64 = 0;
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MintRedbDatabase {
|
pub struct MintRedbDatabase {
|
||||||
db: Arc<Mutex<Database>>,
|
db: Arc<Mutex<Database>>,
|
||||||
|
|||||||
@@ -1,44 +1,16 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::num::ParseIntError;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
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::nuts::{Id, KeySetInfo, Keys, MintInfo, Proofs};
|
||||||
use cdk::types::{MeltQuote, MintQuote};
|
use cdk::types::{MeltQuote, MintQuote};
|
||||||
use cdk::url::UncheckedUrl;
|
use cdk::url::UncheckedUrl;
|
||||||
use redb::{Database, MultimapTableDefinition, ReadableTable, TableDefinition};
|
use redb::{Database, MultimapTableDefinition, ReadableTable, TableDefinition};
|
||||||
use thiserror::Error;
|
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
use super::error::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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const MINTS_TABLE: TableDefinition<&str, &str> = TableDefinition::new("mints_table");
|
const MINTS_TABLE: TableDefinition<&str, &str> = TableDefinition::new("mints_table");
|
||||||
const MINT_KEYSETS_TABLE: MultimapTableDefinition<&str, &str> =
|
const MINT_KEYSETS_TABLE: MultimapTableDefinition<&str, &str> =
|
||||||
|
|||||||
Reference in New Issue
Block a user