fixup! Move files from protocol to appropriate module

This commit is contained in:
Daniel Karzel 2021-06-25 18:20:10 +10:00
parent 52e2e7e489
commit a11c9d9c03
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E
28 changed files with 54 additions and 65 deletions

View File

@ -1,16 +1,15 @@
pub use rate::Rate; mod behaviour;
pub mod behaviour;
pub mod command; pub mod command;
pub mod config; pub mod config;
pub mod event_loop; mod event_loop;
mod rate; mod rate;
pub mod recovery; mod recovery;
pub mod tracing; pub mod tracing;
pub mod transport; pub mod transport;
pub use behaviour::{Behaviour, OutEvent}; pub use behaviour::{Behaviour, OutEvent};
pub use event_loop::{EventLoop, EventLoopHandle}; pub use event_loop::{EventLoop, EventLoopHandle, FixedRate, KrakenRate, LatestRate};
pub use rate::Rate;
pub use recovery::cancel::cancel; pub use recovery::cancel::cancel;
pub use recovery::punish::punish; pub use recovery::punish::punish;
pub use recovery::redeem::{redeem, Finality}; pub use recovery::redeem::{redeem, Finality};

View File

@ -26,9 +26,7 @@ use swap::asb::command::{parse_args, Arguments, Command};
use swap::asb::config::{ use swap::asb::config::{
initial_setup, query_user_for_initial_config, read_config, Config, ConfigNotInitialized, initial_setup, query_user_for_initial_config, read_config, Config, ConfigNotInitialized,
}; };
use swap::asb::event_loop::{EventLoop, KrakenRate}; use swap::asb::{cancel, punish, redeem, refund, safely_abort, EventLoop, Finality, KrakenRate};
use swap::asb::recovery::redeem;
use swap::asb::{cancel, punish, redeem, refund, safely_abort};
use swap::database::Database; use swap::database::Database;
use swap::monero::Amount; use swap::monero::Amount;
use swap::network::swarm; use swap::network::swarm;
@ -282,7 +280,7 @@ async fn main() -> Result<()> {
Arc::new(bitcoin_wallet), Arc::new(bitcoin_wallet),
Arc::new(db), Arc::new(db),
force, force,
redeem::Finality::from_bool(do_not_await_finality), Finality::from_bool(do_not_await_finality),
) )
.await?; .await?;

View File

@ -12,24 +12,19 @@
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
#![allow(non_snake_case)] #![allow(non_snake_case)]
use anyhow::{bail, Context, Result};
use prettytable::{row, Table};
use qrcode::render::unicode;
use qrcode::QrCode;
use std::cmp::min; use std::cmp::min;
use std::env; use std::env;
use std::future::Future; use std::future::Future;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use anyhow::{bail, Context, Result};
use prettytable::{row, Table};
use qrcode::render::unicode;
use qrcode::QrCode;
use tracing::{debug, error, info, warn};
use url::Url;
use uuid::Uuid;
use swap::bitcoin::TxLock; use swap::bitcoin::TxLock;
use swap::cli::command::{parse_args_and_apply_defaults, Arguments, Command, ParseResult}; use swap::cli::command::{parse_args_and_apply_defaults, Arguments, Command, ParseResult};
use swap::cli::event_loop::EventLoop; use swap::cli::EventLoop;
use swap::database::Database; use swap::database::Database;
use swap::env::Config; use swap::env::Config;
use swap::network::quote::BidQuote; use swap::network::quote::BidQuote;
@ -38,6 +33,9 @@ use swap::protocol::bob;
use swap::protocol::bob::Swap; use swap::protocol::bob::Swap;
use swap::seed::Seed; use swap::seed::Seed;
use swap::{bitcoin, cli, monero}; use swap::{bitcoin, cli, monero};
use tracing::{debug, error, info, warn};
use url::Url;
use uuid::Uuid;
#[macro_use] #[macro_use]
extern crate prettytable; extern crate prettytable;

View File

@ -1,7 +1,7 @@
pub mod behaviour; mod behaviour;
pub mod cancel; pub mod cancel;
pub mod command; pub mod command;
pub mod event_loop; mod event_loop;
pub mod refund; pub mod refund;
pub mod tracing; pub mod tracing;
pub mod transport; pub mod transport;

View File

@ -1,17 +1,15 @@
use std::sync::Arc;
use std::time::Duration;
use anyhow::{anyhow, Error, Result};
use libp2p::core::Multiaddr;
use libp2p::ping::{Ping, PingEvent};
use libp2p::request_response::{RequestId, ResponseChannel};
use libp2p::{NetworkBehaviour, PeerId};
use crate::network::quote::BidQuote; use crate::network::quote::BidQuote;
use crate::network::swap_setup::bob; use crate::network::swap_setup::bob;
use crate::network::{encrypted_signature, quote, redial, transfer_proof}; use crate::network::{encrypted_signature, quote, redial, transfer_proof};
use crate::protocol::bob::State2; use crate::protocol::bob::State2;
use crate::{bitcoin, env}; use crate::{bitcoin, env};
use anyhow::{anyhow, Error, Result};
use libp2p::core::Multiaddr;
use libp2p::ping::{Ping, PingEvent};
use libp2p::request_response::{RequestId, ResponseChannel};
use libp2p::{NetworkBehaviour, PeerId};
use std::sync::Arc;
use std::time::Duration;
#[derive(Debug)] #[derive(Debug)]
pub enum OutEvent { pub enum OutEvent {

View File

@ -1,7 +1,4 @@
use std::pin::Pin; use crate::cli;
use std::task::{Context, Poll};
use std::time::Duration;
use backoff::backoff::Backoff; use backoff::backoff::Backoff;
use backoff::ExponentialBackoff; use backoff::ExponentialBackoff;
use futures::future::FutureExt; use futures::future::FutureExt;
@ -10,11 +7,12 @@ use libp2p::core::Multiaddr;
use libp2p::swarm::protocols_handler::DummyProtocolsHandler; use libp2p::swarm::protocols_handler::DummyProtocolsHandler;
use libp2p::swarm::{DialPeerCondition, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use libp2p::swarm::{DialPeerCondition, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
use libp2p::PeerId; use libp2p::PeerId;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::Duration;
use tokio::time::{Instant, Sleep}; use tokio::time::{Instant, Sleep};
use void::Void; use void::Void;
use crate::cli;
pub enum OutEvent { pub enum OutEvent {
AllAttemptsExhausted { peer: PeerId }, AllAttemptsExhausted { peer: PeerId },
} }
@ -121,11 +119,11 @@ impl NetworkBehaviour for Behaviour {
} }
} }
impl From<OutEvent> for cli::behaviour::OutEvent { impl From<OutEvent> for cli::OutEvent {
fn from(event: OutEvent) -> Self { fn from(event: OutEvent) -> Self {
match event { match event {
OutEvent::AllAttemptsExhausted { peer } => { OutEvent::AllAttemptsExhausted { peer } => {
cli::behaviour::OutEvent::AllRedialAttemptsExhausted { peer } cli::OutEvent::AllRedialAttemptsExhausted { peer }
} }
} }
} }

View File

@ -1,11 +1,10 @@
use crate::monero;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use libp2p::core::upgrade; use libp2p::core::upgrade;
use libp2p::swarm::NegotiatedSubstream; use libp2p::swarm::NegotiatedSubstream;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::monero;
pub mod alice; pub mod alice;
pub mod bob; pub mod bob;

View File

@ -1,4 +1,4 @@
use crate::asb::event_loop::LatestRate; use crate::asb::LatestRate;
use crate::network::swap_setup; use crate::network::swap_setup;
use crate::network::swap_setup::{ use crate::network::swap_setup::{
protocol, BlockchainNetwork, SpotPriceError, SpotPriceRequest, SpotPriceResponse, protocol, BlockchainNetwork, SpotPriceError, SpotPriceRequest, SpotPriceResponse,

View File

@ -1,4 +1,4 @@
use crate::asb::event_loop::LatestRate; use crate::asb::LatestRate;
use crate::seed::Seed; use crate::seed::Seed;
use crate::{asb, bitcoin, cli, env, tor}; use crate::{asb, bitcoin, cli, env, tor};
use anyhow::Result; use anyhow::Result;

View File

@ -14,7 +14,7 @@ pub mod swap;
pub struct Swap { pub struct Swap {
pub state: AliceState, pub state: AliceState,
pub event_loop_handle: asb::event_loop::EventLoopHandle, pub event_loop_handle: asb::EventLoopHandle,
pub bitcoin_wallet: Arc<bitcoin::Wallet>, pub bitcoin_wallet: Arc<bitcoin::Wallet>,
pub monero_wallet: Arc<monero::Wallet>, pub monero_wallet: Arc<monero::Wallet>,
pub env_config: Config, pub env_config: Config,

View File

@ -1,6 +1,6 @@
//! Run an XMR/BTC swap in the role of Alice. //! Run an XMR/BTC swap in the role of Alice.
//! Alice holds XMR and wishes receive BTC. //! Alice holds XMR and wishes receive BTC.
use crate::asb::event_loop::{EventLoopHandle, LatestRate}; use crate::asb::{EventLoopHandle, LatestRate};
use crate::bitcoin::ExpiredTimelocks; use crate::bitcoin::ExpiredTimelocks;
use crate::env::Config; use crate::env::Config;
use crate::protocol::alice::{AliceState, Swap}; use crate::protocol::alice::{AliceState, Swap};

View File

@ -14,7 +14,7 @@ pub mod swap;
pub struct Swap { pub struct Swap {
pub state: BobState, pub state: BobState,
pub event_loop_handle: cli::event_loop::EventLoopHandle, pub event_loop_handle: cli::EventLoopHandle,
pub db: Database, pub db: Database,
pub bitcoin_wallet: Arc<bitcoin::Wallet>, pub bitcoin_wallet: Arc<bitcoin::Wallet>,
pub monero_wallet: Arc<monero::Wallet>, pub monero_wallet: Arc<monero::Wallet>,
@ -31,7 +31,7 @@ impl Swap {
bitcoin_wallet: Arc<bitcoin::Wallet>, bitcoin_wallet: Arc<bitcoin::Wallet>,
monero_wallet: Arc<monero::Wallet>, monero_wallet: Arc<monero::Wallet>,
env_config: env::Config, env_config: env::Config,
event_loop_handle: cli::event_loop::EventLoopHandle, event_loop_handle: cli::EventLoopHandle,
receive_monero_address: monero::Address, receive_monero_address: monero::Address,
btc_amount: bitcoin::Amount, btc_amount: bitcoin::Amount,
) -> Self { ) -> Self {
@ -53,7 +53,7 @@ impl Swap {
bitcoin_wallet: Arc<bitcoin::Wallet>, bitcoin_wallet: Arc<bitcoin::Wallet>,
monero_wallet: Arc<monero::Wallet>, monero_wallet: Arc<monero::Wallet>,
env_config: env::Config, env_config: env::Config,
event_loop_handle: cli::event_loop::EventLoopHandle, event_loop_handle: cli::EventLoopHandle,
receive_monero_address: monero::Address, receive_monero_address: monero::Address,
) -> Result<Self> { ) -> Result<Self> {
let state = db.get_state(id)?.try_into_bob()?.into(); let state = db.get_state(id)?.try_into_bob()?.into();

View File

@ -1,5 +1,5 @@
use crate::bitcoin::{ExpiredTimelocks, TxCancel, TxRefund}; use crate::bitcoin::{ExpiredTimelocks, TxCancel, TxRefund};
use crate::cli::event_loop::EventLoopHandle; use crate::cli::EventLoopHandle;
use crate::database::Swap; use crate::database::Swap;
use crate::network::swap_setup::bob::NewSwap; use crate::network::swap_setup::bob::NewSwap;
use crate::protocol::bob; use crate::protocol::bob;

View File

@ -3,7 +3,7 @@ pub mod harness;
use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::alice_run_until::is_xmr_lock_transaction_sent;
use harness::bob_run_until::is_btc_locked; use harness::bob_run_until::is_btc_locked;
use harness::FastCancelConfig; use harness::FastCancelConfig;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::alice::AliceState; use swap::protocol::alice::AliceState;
use swap::protocol::bob::BobState; use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};

View File

@ -3,7 +3,7 @@ pub mod harness;
use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::alice_run_until::is_xmr_lock_transaction_sent;
use harness::bob_run_until::is_btc_locked; use harness::bob_run_until::is_btc_locked;
use harness::SlowCancelConfig; use harness::SlowCancelConfig;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::alice::AliceState; use swap::protocol::alice::AliceState;
use swap::protocol::bob::BobState; use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};

View File

@ -3,7 +3,7 @@ pub mod harness;
use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::alice_run_until::is_xmr_lock_transaction_sent;
use harness::bob_run_until::is_btc_locked; use harness::bob_run_until::is_btc_locked;
use harness::SlowCancelConfig; use harness::SlowCancelConfig;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::alice::AliceState; use swap::protocol::alice::AliceState;
use swap::protocol::bob::BobState; use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};

View File

@ -4,7 +4,7 @@ use harness::alice_run_until::is_xmr_lock_transaction_sent;
use harness::bob_run_until::is_btc_locked; use harness::bob_run_until::is_btc_locked;
use harness::FastPunishConfig; use harness::FastPunishConfig;
use swap::asb; use swap::asb;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::alice::AliceState; use swap::protocol::alice::AliceState;
use swap::protocol::bob::BobState; use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};

View File

@ -3,8 +3,7 @@ pub mod harness;
use harness::alice_run_until::is_encsig_learned; use harness::alice_run_until::is_encsig_learned;
use harness::SlowCancelConfig; use harness::SlowCancelConfig;
use swap::asb; use swap::asb;
use swap::asb::event_loop::FixedRate; use swap::asb::{Finality, FixedRate};
use swap::asb::Finality;
use swap::protocol::alice::AliceState; use swap::protocol::alice::AliceState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};

View File

@ -3,7 +3,7 @@ pub mod harness;
use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::alice_run_until::is_xmr_lock_transaction_sent;
use harness::bob_run_until::is_btc_locked; use harness::bob_run_until::is_btc_locked;
use harness::FastPunishConfig; use harness::FastPunishConfig;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::alice::AliceState; use swap::protocol::alice::AliceState;
use swap::protocol::bob::BobState; use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};

View File

@ -2,7 +2,7 @@ pub mod harness;
use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::alice_run_until::is_xmr_lock_transaction_sent;
use harness::FastCancelConfig; use harness::FastCancelConfig;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::alice::AliceState; use swap::protocol::alice::AliceState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};

View File

@ -2,7 +2,7 @@ pub mod harness;
use harness::bob_run_until::is_xmr_locked; use harness::bob_run_until::is_xmr_locked;
use harness::SlowCancelConfig; use harness::SlowCancelConfig;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::alice::AliceState; use swap::protocol::alice::AliceState;
use swap::protocol::bob::BobState; use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};

View File

@ -2,7 +2,7 @@ pub mod harness;
use harness::bob_run_until::is_btc_locked; use harness::bob_run_until::is_btc_locked;
use harness::SlowCancelConfig; use harness::SlowCancelConfig;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::alice::AliceState; use swap::protocol::alice::AliceState;
use swap::protocol::bob::BobState; use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};

View File

@ -1,7 +1,7 @@
pub mod harness; pub mod harness;
use harness::SlowCancelConfig; use harness::SlowCancelConfig;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};
use tokio::join; use tokio::join;

View File

@ -2,7 +2,7 @@ pub mod harness;
use harness::alice_run_until::is_xmr_lock_transaction_sent; use harness::alice_run_until::is_xmr_lock_transaction_sent;
use harness::SlowCancelConfig; use harness::SlowCancelConfig;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::alice::AliceState; use swap::protocol::alice::AliceState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};

View File

@ -2,7 +2,7 @@ pub mod harness;
use harness::bob_run_until::is_xmr_locked; use harness::bob_run_until::is_xmr_locked;
use harness::SlowCancelConfig; use harness::SlowCancelConfig;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::bob::BobState; use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};

View File

@ -2,7 +2,7 @@ pub mod harness;
use harness::bob_run_until::is_xmr_locked; use harness::bob_run_until::is_xmr_locked;
use harness::SlowCancelConfig; use harness::SlowCancelConfig;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::bob::BobState; use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};

View File

@ -14,7 +14,7 @@ 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::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::bitcoin::{CancelTimelock, PunishTimelock, TxCancel, TxPunish, TxRedeem, TxRefund}; use swap::bitcoin::{CancelTimelock, PunishTimelock, TxCancel, TxPunish, TxRedeem, TxRefund};
use swap::database::Database; use swap::database::Database;
use swap::env::{Config, GetConfig}; use swap::env::{Config, GetConfig};

View File

@ -2,7 +2,7 @@ pub mod harness;
use harness::bob_run_until::is_btc_locked; use harness::bob_run_until::is_btc_locked;
use harness::FastPunishConfig; use harness::FastPunishConfig;
use swap::asb::event_loop::FixedRate; use swap::asb::FixedRate;
use swap::protocol::bob::BobState; use swap::protocol::bob::BobState;
use swap::protocol::{alice, bob}; use swap::protocol::{alice, bob};