feat: use only one table up (#590)

This commit is contained in:
thesimplekid
2025-02-08 13:41:42 +00:00
committed by GitHub
4 changed files with 55 additions and 57 deletions

View File

@@ -36,7 +36,7 @@ uuid = { version = "1", features = ["v4"] }
serde = "1"
serde_json = "1"
# ln-regtest-rs = { path = "../../../../ln-regtest-rs" }
ln-regtest-rs = { git = "https://github.com/thesimplekid/ln-regtest-rs", rev = "f9e7bbbb" }
ln-regtest-rs = { git = "https://github.com/thesimplekid/ln-regtest-rs", rev = "bf09ad6" }
lightning-invoice = { version = "0.32.0", features = ["serde", "std"] }
tracing = { version = "0.1", default-features = false, features = [
"attributes",

View File

@@ -18,7 +18,7 @@ wallet = []
[dependencies]
async-trait = "0.1"
cdk-common = { path = "../cdk-common", version = "0.7.0" }
redb = "2.1.0"
redb = "2.2.0"
thiserror = "1"
tracing = { version = "0.1", default-features = false, features = [
"attributes",

View File

@@ -58,6 +58,9 @@ pub enum Error {
/// Unknown Proof Y
#[error("Unknown proof Y")]
UnknownY,
/// Unknown Quote
#[error("Unknown quote")]
UnknownQuote,
/// Unknown Database Version
#[error("Unknown database version")]
UnknownDatabaseVersion,

View File

@@ -295,38 +295,36 @@ impl MintDatabase for MintRedbDatabase {
) -> Result<MintQuoteState, Self::Err> {
let write_txn = self.db.begin_write().map_err(Error::from)?;
let mut mint_quote: MintQuote;
{
let table = write_txn
.open_table(MINT_QUOTES_TABLE)
.map_err(Error::from)?;
let quote_guard = table
.get(quote_id.as_bytes())
.map_err(Error::from)?
.ok_or(Error::UnknownMintInfo)?;
let quote = quote_guard.value();
mint_quote = serde_json::from_str(quote).map_err(Error::from)?;
}
let current_state = mint_quote.state;
mint_quote.state = state;
let current_state;
{
let mut mint_quote: MintQuote;
let mut table = write_txn
.open_table(MINT_QUOTES_TABLE)
.map_err(Error::from)?;
{
let quote_guard = table
.get(quote_id.as_bytes())
.map_err(Error::from)?
.ok_or(Error::UnknownQuote)?;
table
.insert(
quote_id.as_bytes(),
serde_json::to_string(&mint_quote)
.map_err(Error::from)?
.as_str(),
)
.map_err(Error::from)?;
let quote = quote_guard.value();
mint_quote = serde_json::from_str(quote).map_err(Error::from)?;
}
current_state = mint_quote.state;
mint_quote.state = state;
{
table
.insert(
quote_id.as_bytes(),
serde_json::to_string(&mint_quote)
.map_err(Error::from)?
.as_str(),
)
.map_err(Error::from)?;
}
}
write_txn.commit().map_err(Error::from)?;
@@ -454,39 +452,36 @@ impl MintDatabase for MintRedbDatabase {
) -> Result<MeltQuoteState, Self::Err> {
let write_txn = self.db.begin_write().map_err(Error::from)?;
let mut melt_quote: mint::MeltQuote;
{
let table = write_txn
.open_table(MELT_QUOTES_TABLE)
.map_err(Error::from)?;
let quote_guard = table
.get(quote_id.as_bytes())
.map_err(Error::from)?
.ok_or(Error::UnknownMintInfo)?;
let quote = quote_guard.value();
melt_quote = serde_json::from_str(quote).map_err(Error::from)?;
}
let current_state = melt_quote.state;
melt_quote.state = state;
let current_state;
{
let mut melt_quote: mint::MeltQuote;
let mut table = write_txn
.open_table(MELT_QUOTES_TABLE)
.map_err(Error::from)?;
{
let quote_guard = table
.get(quote_id.as_bytes())
.map_err(Error::from)?
.ok_or(Error::UnknownQuote)?;
table
.insert(
quote_id.as_bytes(),
serde_json::to_string(&melt_quote)
.map_err(Error::from)?
.as_str(),
)
.map_err(Error::from)?;
let quote = quote_guard.value();
melt_quote = serde_json::from_str(quote).map_err(Error::from)?;
}
current_state = melt_quote.state;
melt_quote.state = state;
{
table
.insert(
quote_id.as_bytes(),
serde_json::to_string(&melt_quote)
.map_err(Error::from)?
.as_str(),
)
.map_err(Error::from)?;
}
}
write_txn.commit().map_err(Error::from)?;