mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-10 23:56:18 +01:00
fix: set send proofs to reserved instead of removing
This commit is contained in:
@@ -466,32 +466,33 @@ impl WalletDatabase for RedbWalletDatabase {
|
||||
let table = read_txn.open_table(PROOFS_TABLE).map_err(Error::from)?;
|
||||
|
||||
let y_slice = y.to_bytes();
|
||||
let proof = table.get(y_slice.as_slice()).map_err(Error::from)?;
|
||||
let proof = table
|
||||
.get(y_slice.as_slice())
|
||||
.map_err(Error::from)?
|
||||
.ok_or(Error::UnknownY)?;
|
||||
|
||||
let write_txn = db.begin_write().map_err(Error::from)?;
|
||||
|
||||
if let Some(proof) = proof {
|
||||
let mut proof_info =
|
||||
serde_json::from_str::<ProofInfo>(proof.value()).map_err(Error::from)?;
|
||||
let mut proof_info =
|
||||
serde_json::from_str::<ProofInfo>(proof.value()).map_err(Error::from)?;
|
||||
|
||||
proof_info.state = state;
|
||||
proof_info.state = state;
|
||||
|
||||
{
|
||||
let mut table = write_txn.open_table(PROOFS_TABLE).map_err(Error::from)?;
|
||||
table
|
||||
.insert(
|
||||
y_slice.as_slice(),
|
||||
serde_json::to_string(&proof_info)
|
||||
.map_err(Error::from)?
|
||||
.as_str(),
|
||||
)
|
||||
.map_err(Error::from)?;
|
||||
}
|
||||
{
|
||||
let mut table = write_txn.open_table(PROOFS_TABLE).map_err(Error::from)?;
|
||||
table
|
||||
.insert(
|
||||
y_slice.as_slice(),
|
||||
serde_json::to_string(&proof_info)
|
||||
.map_err(Error::from)?
|
||||
.as_str(),
|
||||
)
|
||||
.map_err(Error::from)?;
|
||||
}
|
||||
|
||||
write_txn.commit().map_err(Error::from)?;
|
||||
|
||||
Err(Error::UnknownY.into())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
|
||||
@@ -160,7 +160,7 @@ impl Mint {
|
||||
quote: quote.id,
|
||||
request: quote.request,
|
||||
paid: quote.paid,
|
||||
expiry: quote.expiry,
|
||||
expiry: Some(quote.expiry),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ pub struct MintQuoteBolt11Response {
|
||||
/// Whether the the request haas be paid
|
||||
pub paid: bool,
|
||||
/// Unix timestamp until the quote is valid
|
||||
pub expiry: u64,
|
||||
pub expiry: Option<u64>,
|
||||
}
|
||||
|
||||
impl From<MintQuote> for MintQuoteBolt11Response {
|
||||
@@ -36,7 +36,7 @@ impl From<MintQuote> for MintQuoteBolt11Response {
|
||||
quote: mint_quote.id,
|
||||
request: mint_quote.request,
|
||||
paid: mint_quote.paid,
|
||||
expiry: mint_quote.expiry,
|
||||
expiry: Some(mint_quote.expiry),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ impl Wallet {
|
||||
for (mint, _) in mints {
|
||||
if let Some(proofs) = self
|
||||
.localstore
|
||||
.get_proofs(Some(mint.clone()), None, None, None)
|
||||
.get_proofs(Some(mint.clone()), None, Some(vec![State::Unspent]), None)
|
||||
.await?
|
||||
{
|
||||
let mut balances = HashMap::new();
|
||||
@@ -440,7 +440,7 @@ impl Wallet {
|
||||
unit: unit.clone(),
|
||||
request: quote_res.request,
|
||||
paid: quote_res.paid,
|
||||
expiry: quote_res.expiry,
|
||||
expiry: quote_res.expiry.unwrap_or(0),
|
||||
};
|
||||
|
||||
self.localstore.add_mint_quote(quote.clone()).await?;
|
||||
@@ -693,6 +693,7 @@ impl Wallet {
|
||||
|
||||
let active_keyset_id = self.active_mint_keyset(mint_url, unit).await?;
|
||||
|
||||
// FIXME: Should not increment keyset counter for condition proofs
|
||||
self.localstore
|
||||
.increment_keyset_counter(&active_keyset_id, post_swap_proofs.len() as u32)
|
||||
.await?;
|
||||
@@ -752,8 +753,6 @@ impl Wallet {
|
||||
}
|
||||
}
|
||||
|
||||
self.localstore.remove_proofs(&input_proofs).await?;
|
||||
|
||||
for proof in input_proofs {
|
||||
self.localstore
|
||||
.set_proof_state(proof.y()?, State::Reserved)
|
||||
@@ -849,7 +848,7 @@ impl Wallet {
|
||||
}
|
||||
};
|
||||
|
||||
// Combine the BlindedMessages totoalling the desired amount with change
|
||||
// Combine the BlindedMessages totaling the desired amount with change
|
||||
desired_messages.combine(change_messages);
|
||||
// Sort the premint secrets to avoid finger printing
|
||||
desired_messages.sort_secrets();
|
||||
@@ -926,13 +925,15 @@ impl Wallet {
|
||||
}
|
||||
};
|
||||
|
||||
let send_proofs = send_proofs.ok_or(Error::InsufficientFunds)?;
|
||||
for proof in send_proofs.iter() {
|
||||
self.localstore
|
||||
.set_proof_state(proof.y()?, State::Reserved)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(self
|
||||
.proof_to_token(
|
||||
mint_url.clone(),
|
||||
send_proofs.ok_or(Error::InsufficientFunds)?,
|
||||
memo,
|
||||
Some(unit.clone()),
|
||||
)?
|
||||
.proof_to_token(mint_url.clone(), send_proofs, memo, Some(unit.clone()))?
|
||||
.to_string())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user