diff --git a/crates/cdk-integration-tests/Cargo.toml b/crates/cdk-integration-tests/Cargo.toml index 0f482812..ce66f675 100644 --- a/crates/cdk-integration-tests/Cargo.toml +++ b/crates/cdk-integration-tests/Cargo.toml @@ -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", diff --git a/crates/cdk-redb/Cargo.toml b/crates/cdk-redb/Cargo.toml index 9b6062df..2ff431e1 100644 --- a/crates/cdk-redb/Cargo.toml +++ b/crates/cdk-redb/Cargo.toml @@ -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", diff --git a/crates/cdk-redb/src/error.rs b/crates/cdk-redb/src/error.rs index 3b12ef28..9fba14b2 100644 --- a/crates/cdk-redb/src/error.rs +++ b/crates/cdk-redb/src/error.rs @@ -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, diff --git a/crates/cdk-redb/src/mint/mod.rs b/crates/cdk-redb/src/mint/mod.rs index 2d6a5344..e261fffe 100644 --- a/crates/cdk-redb/src/mint/mod.rs +++ b/crates/cdk-redb/src/mint/mod.rs @@ -295,38 +295,36 @@ impl MintDatabase for MintRedbDatabase { ) -> Result { 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 { 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)?;