Move FixedRate into event_loop module

This is where these types are used, they can be defined in there.
This commit is contained in:
Thomas Eizinger 2021-04-01 16:48:37 +11:00
parent 654cfff2a8
commit 3e0301a9d4
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
4 changed files with 23 additions and 27 deletions

View File

@ -1,7 +1,5 @@
pub mod command; pub mod command;
pub mod config; pub mod config;
mod fixed_rate;
mod rate; mod rate;
pub use self::fixed_rate::FixedRate; pub use rate::Rate;
pub use self::rate::Rate;

View File

@ -1,20 +0,0 @@
use crate::asb::Rate;
#[derive(Clone, Copy, Debug)]
pub struct FixedRate(Rate);
impl FixedRate {
pub const RATE: f64 = 0.01;
pub fn value(&self) -> Rate {
self.0
}
}
impl Default for FixedRate {
fn default() -> Self {
let ask = bitcoin::Amount::from_btc(Self::RATE).expect("Static value should never fail");
Self(Rate::new(ask))
}
}

View File

@ -1,4 +1,4 @@
use crate::asb::{FixedRate, Rate}; use crate::asb::Rate;
use crate::database::Database; use crate::database::Database;
use crate::env::Config; use crate::env::Config;
use crate::monero::BalanceTooLow; use crate::monero::BalanceTooLow;
@ -346,6 +346,25 @@ pub trait LatestRate {
fn latest_rate(&mut self) -> Result<Rate, Self::Error>; fn latest_rate(&mut self) -> Result<Rate, Self::Error>;
} }
#[derive(Clone, Debug)]
pub struct FixedRate(Rate);
impl FixedRate {
pub const RATE: f64 = 0.01;
pub fn value(&self) -> Rate {
self.0
}
}
impl Default for FixedRate {
fn default() -> Self {
let ask = bitcoin::Amount::from_btc(Self::RATE).expect("Static value should never fail");
Self(Rate::new(ask))
}
}
impl LatestRate for FixedRate { impl LatestRate for FixedRate {
type Error = Infallible; type Error = Infallible;
@ -359,9 +378,8 @@ impl LatestRate for kraken::PriceUpdates {
fn latest_rate(&mut self) -> Result<Rate, Self::Error> { fn latest_rate(&mut self) -> Result<Rate, Self::Error> {
let update = self.latest_update()?; let update = self.latest_update()?;
let rate = Rate::new(update.ask);
Ok(rate) Ok(Rate::new(update.ask))
} }
} }

View File

@ -15,11 +15,11 @@ use std::fmt;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use swap::asb::FixedRate;
use swap::bitcoin::{CancelTimelock, PunishTimelock}; use swap::bitcoin::{CancelTimelock, PunishTimelock};
use swap::database::Database; use swap::database::Database;
use swap::env::{Config, GetConfig}; use swap::env::{Config, GetConfig};
use swap::network::swarm; use swap::network::swarm;
use swap::protocol::alice::event_loop::FixedRate;
use swap::protocol::alice::{AliceState, Swap}; use swap::protocol::alice::{AliceState, Swap};
use swap::protocol::bob::BobState; use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};