add db handler to remove trade

This commit is contained in:
fbock
2024-08-22 10:09:20 +02:00
parent 9f9f3a370a
commit 6d84f45499
4 changed files with 18 additions and 4 deletions

View File

@ -1,6 +1,3 @@
use bitcoin::secp256k1::Scalar;
use hex::ToHex;
use super::*;
#[derive(Debug)]

View File

@ -379,5 +379,14 @@ pub async fn handle_payout_signature(
.broadcast_keyspend_tx(&keyspend_information)
.await
.map_err(|e| RequestError::CoordinatorError(e.to_string()))?;
database
.delete_complete_offer(&payload.offer_id_hex)
.await
.map_err(|e| {
RequestError::Database(format!(
"Failed to delete complete offer from taken_offers: {}",
e.to_string()
))
})?;
Ok(true)
}

View File

@ -1022,4 +1022,12 @@ impl CoordinatorDB {
trace!("Toggled processing status for offer {}", offer_id);
Ok(result.get::<i64, _>(0) == 1)
}
pub async fn delete_complete_offer(&self, offer_id: &str) -> Result<()> {
sqlx::query("DELETE FROM taken_offers WHERE offer_id = ?")
.bind(offer_id)
.execute(&*self.db_pool)
.await?;
Ok(())
}
}

View File

@ -63,7 +63,7 @@ use tokio::{
sync::{oneshot, Mutex},
};
use validator::{Validate, ValidationError};
use wallet::{escrow_psbt::*, wallet_utils::*, *};
use wallet::{wallet_utils::*, *};
pub struct Coordinator {
pub coordinator_db: Arc<CoordinatorDB>,