mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-12 07:59:33 -05:00
Move state.rs under database module
The types in state are only used for the database
This commit is contained in:
parent
8c7964bfee
commit
b410de01df
@ -11,9 +11,8 @@ use crate::{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
bitcoin::EncryptedSignature,
|
bitcoin::EncryptedSignature,
|
||||||
database::Database,
|
database::{state::Swap, Database},
|
||||||
network::request_response::AliceToBob,
|
network::request_response::AliceToBob,
|
||||||
state::Swap,
|
|
||||||
SwapAmounts,
|
SwapAmounts,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
use crate::{bob::event_loop::EventLoopHandle, database::Database, state, SwapAmounts};
|
use crate::{
|
||||||
|
bob::event_loop::EventLoopHandle,
|
||||||
|
database::{state, Database},
|
||||||
|
SwapAmounts,
|
||||||
|
};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use async_recursion::async_recursion;
|
use async_recursion::async_recursion;
|
||||||
use rand::{CryptoRng, RngCore};
|
use rand::{CryptoRng, RngCore};
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
use crate::state::Swap;
|
|
||||||
use anyhow::{anyhow, bail, Context, Result};
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
|
use state::Swap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
pub mod state;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Database(sled::Db);
|
pub struct Database(sled::Db);
|
||||||
|
|
||||||
@ -82,7 +84,7 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::state::{Alice, AliceEndState, Bob, BobEndState};
|
use crate::database::state::{Alice, AliceEndState, Bob, BobEndState};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ pub mod cli;
|
|||||||
pub mod database;
|
pub mod database;
|
||||||
pub mod monero;
|
pub mod monero;
|
||||||
pub mod network;
|
pub mod network;
|
||||||
pub mod state;
|
|
||||||
pub mod trace;
|
pub mod trace;
|
||||||
|
|
||||||
pub type Never = std::convert::Infallible;
|
pub type Never = std::convert::Infallible;
|
||||||
|
@ -25,10 +25,9 @@ use swap::{
|
|||||||
bitcoin, bob,
|
bitcoin, bob,
|
||||||
bob::swap::BobState,
|
bob::swap::BobState,
|
||||||
cli::{Command, Options, Resume},
|
cli::{Command, Options, Resume},
|
||||||
database::Database,
|
database::{state::Swap, Database},
|
||||||
monero,
|
monero,
|
||||||
network::transport::build,
|
network::transport::build,
|
||||||
state::Swap,
|
|
||||||
trace::init_tracing,
|
trace::init_tracing,
|
||||||
SwapAmounts,
|
SwapAmounts,
|
||||||
};
|
};
|
||||||
|
@ -111,13 +111,14 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
|||||||
|
|
||||||
let alice_db = Database::open(alice_db_datadir.path()).unwrap();
|
let alice_db = Database::open(alice_db_datadir.path()).unwrap();
|
||||||
|
|
||||||
let resume_state =
|
let resume_state = if let swap::database::state::Swap::Alice(state) =
|
||||||
if let swap::state::Swap::Alice(state) = alice_db.get_state(alice_swap_id).unwrap() {
|
alice_db.get_state(alice_swap_id).unwrap()
|
||||||
assert!(matches!(state, swap::state::Alice::EncSigLearned {..}));
|
{
|
||||||
state.into()
|
assert!(matches!(state, swap::database::state::Alice::EncSigLearned {..}));
|
||||||
} else {
|
state.into()
|
||||||
unreachable!()
|
} else {
|
||||||
};
|
unreachable!()
|
||||||
|
};
|
||||||
|
|
||||||
let (mut event_loop_after_restart, event_loop_handle_after_restart) =
|
let (mut event_loop_after_restart, event_loop_handle_after_restart) =
|
||||||
testutils::init_alice_event_loop(alice_multiaddr);
|
testutils::init_alice_event_loop(alice_multiaddr);
|
||||||
|
@ -114,13 +114,13 @@ async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
|
|||||||
|
|
||||||
let bob_db = Database::open(bob_db_datadir.path()).unwrap();
|
let bob_db = Database::open(bob_db_datadir.path()).unwrap();
|
||||||
|
|
||||||
let resume_state = if let swap::state::Swap::Bob(state) = bob_db.get_state(bob_swap_id).unwrap()
|
let resume_state =
|
||||||
{
|
if let swap::database::state::Swap::Bob(state) = bob_db.get_state(bob_swap_id).unwrap() {
|
||||||
assert!(matches!(state, swap::state::Bob::EncSigSent {..}));
|
assert!(matches!(state, swap::database::state::Bob::EncSigSent {..}));
|
||||||
state.into()
|
state.into()
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
let (event_loop_after_restart, event_loop_handle_after_restart) =
|
let (event_loop_after_restart, event_loop_handle_after_restart) =
|
||||||
testutils::init_bob_event_loop(alice_peer_id, alice_multiaddr);
|
testutils::init_bob_event_loop(alice_peer_id, alice_multiaddr);
|
||||||
|
Loading…
Reference in New Issue
Block a user