Move state.rs under database module

The types in state are only used for the database
This commit is contained in:
Franck Royer 2020-12-23 15:20:24 +11:00
parent 8c7964bfee
commit b410de01df
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
8 changed files with 26 additions and 22 deletions

View File

@ -11,9 +11,8 @@ use crate::{
},
},
bitcoin::EncryptedSignature,
database::Database,
database::{state::Swap, Database},
network::request_response::AliceToBob,
state::Swap,
SwapAmounts,
};
use anyhow::Result;

View File

@ -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 async_recursion::async_recursion;
use rand::{CryptoRng, RngCore};

View File

@ -1,9 +1,11 @@
use crate::state::Swap;
use anyhow::{anyhow, bail, Context, Result};
use serde::{de::DeserializeOwned, Serialize};
use state::Swap;
use std::path::Path;
use uuid::Uuid;
pub mod state;
#[derive(Debug)]
pub struct Database(sled::Db);
@ -82,7 +84,7 @@ where
#[cfg(test)]
mod tests {
use crate::state::{Alice, AliceEndState, Bob, BobEndState};
use crate::database::state::{Alice, AliceEndState, Bob, BobEndState};
use super::*;

View File

@ -23,7 +23,6 @@ pub mod cli;
pub mod database;
pub mod monero;
pub mod network;
pub mod state;
pub mod trace;
pub type Never = std::convert::Infallible;

View File

@ -25,10 +25,9 @@ use swap::{
bitcoin, bob,
bob::swap::BobState,
cli::{Command, Options, Resume},
database::Database,
database::{state::Swap, Database},
monero,
network::transport::build,
state::Swap,
trace::init_tracing,
SwapAmounts,
};

View File

@ -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 resume_state =
if let swap::state::Swap::Alice(state) = alice_db.get_state(alice_swap_id).unwrap() {
assert!(matches!(state, swap::state::Alice::EncSigLearned {..}));
state.into()
} else {
unreachable!()
};
let resume_state = if let swap::database::state::Swap::Alice(state) =
alice_db.get_state(alice_swap_id).unwrap()
{
assert!(matches!(state, swap::database::state::Alice::EncSigLearned {..}));
state.into()
} else {
unreachable!()
};
let (mut event_loop_after_restart, event_loop_handle_after_restart) =
testutils::init_alice_event_loop(alice_multiaddr);

View File

@ -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 resume_state = if let swap::state::Swap::Bob(state) = bob_db.get_state(bob_swap_id).unwrap()
{
assert!(matches!(state, swap::state::Bob::EncSigSent {..}));
state.into()
} else {
unreachable!()
};
let resume_state =
if let swap::database::state::Swap::Bob(state) = bob_db.get_state(bob_swap_id).unwrap() {
assert!(matches!(state, swap::database::state::Bob::EncSigSent {..}));
state.into()
} else {
unreachable!()
};
let (event_loop_after_restart, event_loop_handle_after_restart) =
testutils::init_bob_event_loop(alice_peer_id, alice_multiaddr);