From 3e0301a9d43fbdf788c3c0110272bdc7250841a3 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 1 Apr 2021 16:48:37 +1100 Subject: [PATCH] Move `FixedRate` into event_loop module This is where these types are used, they can be defined in there. --- swap/src/asb.rs | 4 +--- swap/src/asb/fixed_rate.rs | 20 -------------------- swap/src/protocol/alice/event_loop.rs | 24 +++++++++++++++++++++--- swap/tests/harness/mod.rs | 2 +- 4 files changed, 23 insertions(+), 27 deletions(-) delete mode 100644 swap/src/asb/fixed_rate.rs diff --git a/swap/src/asb.rs b/swap/src/asb.rs index f755822e..262f8a6a 100644 --- a/swap/src/asb.rs +++ b/swap/src/asb.rs @@ -1,7 +1,5 @@ pub mod command; pub mod config; -mod fixed_rate; mod rate; -pub use self::fixed_rate::FixedRate; -pub use self::rate::Rate; +pub use rate::Rate; diff --git a/swap/src/asb/fixed_rate.rs b/swap/src/asb/fixed_rate.rs deleted file mode 100644 index 4d0b2045..00000000 --- a/swap/src/asb/fixed_rate.rs +++ /dev/null @@ -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)) - } -} diff --git a/swap/src/protocol/alice/event_loop.rs b/swap/src/protocol/alice/event_loop.rs index f48fd080..7837c96c 100644 --- a/swap/src/protocol/alice/event_loop.rs +++ b/swap/src/protocol/alice/event_loop.rs @@ -1,4 +1,4 @@ -use crate::asb::{FixedRate, Rate}; +use crate::asb::Rate; use crate::database::Database; use crate::env::Config; use crate::monero::BalanceTooLow; @@ -346,6 +346,25 @@ pub trait LatestRate { fn latest_rate(&mut self) -> Result; } +#[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 { type Error = Infallible; @@ -359,9 +378,8 @@ impl LatestRate for kraken::PriceUpdates { fn latest_rate(&mut self) -> Result { let update = self.latest_update()?; - let rate = Rate::new(update.ask); - Ok(rate) + Ok(Rate::new(update.ask)) } } diff --git a/swap/tests/harness/mod.rs b/swap/tests/harness/mod.rs index ad0eb1e8..9549d785 100644 --- a/swap/tests/harness/mod.rs +++ b/swap/tests/harness/mod.rs @@ -15,11 +15,11 @@ use std::fmt; use std::path::{Path, PathBuf}; use std::sync::Arc; use std::time::Duration; -use swap::asb::FixedRate; use swap::bitcoin::{CancelTimelock, PunishTimelock}; use swap::database::Database; use swap::env::{Config, GetConfig}; use swap::network::swarm; +use swap::protocol::alice::event_loop::FixedRate; use swap::protocol::alice::{AliceState, Swap}; use swap::protocol::bob::BobState; use swap::protocol::{alice, bob};