mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-08 22:42:35 -04:00
Create Database trait
Use domain types in database API to prevent leaking of database types. This trait will allow us to smoothly introduce the sqlite database.
This commit is contained in:
parent
a94c320021
commit
da9d09aa5e
21 changed files with 351 additions and 253 deletions
|
@ -1,16 +1,17 @@
|
|||
use crate::bitcoin::{parse_rpc_error_code, RpcErrorCode, Txid, Wallet};
|
||||
use crate::database::{SledDatabase, Swap};
|
||||
use crate::protocol::bob::BobState;
|
||||
use crate::protocol::Database;
|
||||
use anyhow::{bail, Result};
|
||||
use std::convert::TryInto;
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn cancel(
|
||||
swap_id: Uuid,
|
||||
bitcoin_wallet: Arc<Wallet>,
|
||||
db: SledDatabase,
|
||||
db: Arc<dyn Database>,
|
||||
) -> Result<(Txid, BobState)> {
|
||||
let state = db.get_state(swap_id)?.try_into_bob()?.into();
|
||||
let state = db.get_state(swap_id).await?.try_into()?;
|
||||
|
||||
let state6 = match state {
|
||||
BobState::BtcLocked(state3) => state3.cancel(),
|
||||
|
@ -48,8 +49,8 @@ pub async fn cancel(
|
|||
};
|
||||
|
||||
let state = BobState::BtcCancelled(state6);
|
||||
let db_state = state.clone().into();
|
||||
db.insert_latest_state(swap_id, Swap::Bob(db_state)).await?;
|
||||
db.insert_latest_state(swap_id, state.clone().into())
|
||||
.await?;
|
||||
|
||||
Ok((txid, state))
|
||||
}
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
use crate::bitcoin::Wallet;
|
||||
use crate::database::{SledDatabase, Swap};
|
||||
use crate::protocol::bob::BobState;
|
||||
use crate::protocol::Database;
|
||||
use anyhow::{bail, Result};
|
||||
use std::convert::TryInto;
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn refund(
|
||||
swap_id: Uuid,
|
||||
bitcoin_wallet: Arc<Wallet>,
|
||||
db: SledDatabase,
|
||||
db: Arc<dyn Database>,
|
||||
) -> Result<BobState> {
|
||||
let state = db.get_state(swap_id)?.try_into_bob()?.into();
|
||||
let state = db.get_state(swap_id).await?.try_into()?;
|
||||
|
||||
let state6 = match state {
|
||||
BobState::BtcLocked(state3) => state3.cancel(),
|
||||
|
@ -35,9 +36,8 @@ pub async fn refund(
|
|||
state6.publish_refund_btc(bitcoin_wallet.as_ref()).await?;
|
||||
|
||||
let state = BobState::BtcRefunded(state6);
|
||||
let db_state = state.clone().into();
|
||||
|
||||
db.insert_latest_state(swap_id, Swap::Bob(db_state)).await?;
|
||||
db.insert_latest_state(swap_id, state.clone().into())
|
||||
.await?;
|
||||
|
||||
Ok(state)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue