Browse Source
Add guard to disallow adding cfd for same order
This should make this error more explicit and add understanding what goes wrong in the logs.
hotfix/0.1.1
Daniel Karzel
3 years ago
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E
1 changed files with
8 additions and
0 deletions
-
daemon/src/cfd_actors.rs
|
|
@ -1,3 +1,4 @@ |
|
|
|
use crate::db::load_cfd_by_order_id; |
|
|
|
use crate::model::cfd::{Attestation, Cfd, CfdState, CfdStateChangeEvent, OrderId}; |
|
|
|
use crate::wallet::Wallet; |
|
|
|
use crate::{db, monitor, oracle}; |
|
|
@ -11,6 +12,13 @@ pub async fn insert_cfd( |
|
|
|
conn: &mut PoolConnection<Sqlite>, |
|
|
|
update_sender: &watch::Sender<Vec<Cfd>>, |
|
|
|
) -> Result<()> { |
|
|
|
if load_cfd_by_order_id(cfd.order.id, conn).await.is_ok() { |
|
|
|
bail!( |
|
|
|
"Cannot insert cfd because there is already a cfd for order id {}", |
|
|
|
cfd.order.id |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
db::insert_cfd(cfd, conn).await?; |
|
|
|
update_sender.send(db::load_all_cfds(conn).await?)?; |
|
|
|
Ok(()) |
|
|
|