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:
rishflab 2021-09-28 10:15:31 +10:00
parent a94c320021
commit da9d09aa5e
21 changed files with 351 additions and 253 deletions

View file

@ -2,6 +2,7 @@ pub use self::sled::SledDatabase;
pub use alice::Alice;
pub use bob::Bob;
use crate::protocol::State;
use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
use std::fmt::Display;
@ -16,6 +17,24 @@ pub enum Swap {
Bob(Bob),
}
impl From<State> for Swap {
fn from(state: State) -> Self {
match state {
State::Alice(state) => Swap::Alice(state.into()),
State::Bob(state) => Swap::Bob(state.into()),
}
}
}
impl From<Swap> for State {
fn from(value: Swap) -> Self {
match value {
Swap::Alice(alice) => State::Alice(alice.into()),
Swap::Bob(bob) => State::Bob(bob.into()),
}
}
}
impl From<Alice> for Swap {
fn from(from: Alice) -> Self {
Swap::Alice(from)