mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-23 23:55:01 +01:00
fix(wallet): stop sqlite from overwritting keyset counter
This commit is contained in:
@@ -85,7 +85,7 @@ async fn main() -> Result<()> {
|
|||||||
let args: Cli = Cli::parse();
|
let args: Cli = Cli::parse();
|
||||||
let default_filter = args.log_level;
|
let default_filter = args.log_level;
|
||||||
|
|
||||||
let sqlx_filter = "sqlx=warn";
|
let sqlx_filter = "sqlx=warn,hyper_util=warn,reqwest=warn";
|
||||||
|
|
||||||
let env_filter = EnvFilter::new(format!("{},{}", default_filter, sqlx_filter));
|
let env_filter = EnvFilter::new(format!("{},{}", default_filter, sqlx_filter));
|
||||||
|
|
||||||
@@ -132,7 +132,9 @@ async fn main() -> Result<()> {
|
|||||||
let random_bytes: [u8; 32] = rng.gen();
|
let random_bytes: [u8; 32] = rng.gen();
|
||||||
|
|
||||||
let mnemonic = Mnemonic::from_entropy(&random_bytes)?;
|
let mnemonic = Mnemonic::from_entropy(&random_bytes)?;
|
||||||
tracing::info!("Using randomly generated seed you will not be able to restore");
|
tracing::info!("Creating new seed");
|
||||||
|
|
||||||
|
fs::write(seed_path, mnemonic.to_string())?;
|
||||||
|
|
||||||
mnemonic
|
mnemonic
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,10 +260,15 @@ FROM mint
|
|||||||
for keyset in keysets {
|
for keyset in keysets {
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
INSERT OR REPLACE INTO keyset
|
INSERT INTO keyset
|
||||||
(mint_url, id, unit, active, input_fee_ppk)
|
(mint_url, id, unit, active, input_fee_ppk)
|
||||||
VALUES (?, ?, ?, ?, ?);
|
VALUES (?, ?, ?, ?, ?)
|
||||||
"#,
|
ON CONFLICT(id) DO UPDATE SET
|
||||||
|
mint_url = excluded.mint_url,
|
||||||
|
unit = excluded.unit,
|
||||||
|
active = excluded.active,
|
||||||
|
input_fee_ppk = excluded.input_fee_ppk;
|
||||||
|
"#,
|
||||||
)
|
)
|
||||||
.bind(mint_url.to_string())
|
.bind(mint_url.to_string())
|
||||||
.bind(keyset.id.to_string())
|
.bind(keyset.id.to_string())
|
||||||
@@ -675,19 +680,23 @@ FROM proof;
|
|||||||
|
|
||||||
#[instrument(skip(self), fields(keyset_id = %keyset_id))]
|
#[instrument(skip(self), fields(keyset_id = %keyset_id))]
|
||||||
async fn increment_keyset_counter(&self, keyset_id: &Id, count: u32) -> Result<(), Self::Err> {
|
async fn increment_keyset_counter(&self, keyset_id: &Id, count: u32) -> Result<(), Self::Err> {
|
||||||
|
let mut transaction = self.pool.begin().await.map_err(Error::from)?;
|
||||||
|
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
UPDATE keyset
|
UPDATE keyset
|
||||||
SET counter = counter + ?
|
SET counter=counter+?
|
||||||
WHERE id IS ?;
|
WHERE id=?;
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.bind(count)
|
.bind(count as i64)
|
||||||
.bind(keyset_id.to_string())
|
.bind(keyset_id.to_string())
|
||||||
.execute(&self.pool)
|
.execute(&mut transaction)
|
||||||
.await
|
.await
|
||||||
.map_err(Error::from)?;
|
.map_err(Error::from)?;
|
||||||
|
|
||||||
|
transaction.commit().await.map_err(Error::from)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -256,6 +256,12 @@ impl Wallet {
|
|||||||
self.localstore.remove_mint_quote("e_info.id).await?;
|
self.localstore.remove_mint_quote("e_info.id).await?;
|
||||||
|
|
||||||
if spending_conditions.is_none() {
|
if spending_conditions.is_none() {
|
||||||
|
tracing::debug!(
|
||||||
|
"Incrementing keyset {} counter by {}",
|
||||||
|
active_keyset_id,
|
||||||
|
proofs.len()
|
||||||
|
);
|
||||||
|
|
||||||
// Update counter for keyset
|
// Update counter for keyset
|
||||||
self.localstore
|
self.localstore
|
||||||
.increment_keyset_counter(&active_keyset_id, proofs.len() as u32)
|
.increment_keyset_counter(&active_keyset_id, proofs.len() as u32)
|
||||||
|
|||||||
Reference in New Issue
Block a user