mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Move CLI network protocols into network module
Adds asb module to the network module.
This commit is contained in:
parent
da7c3a9c9a
commit
c6db22d882
@ -2,6 +2,7 @@ mod impl_from_rr_event;
|
||||
|
||||
pub mod asb;
|
||||
pub mod cbor_request_response;
|
||||
pub mod cli;
|
||||
pub mod encrypted_signature;
|
||||
pub mod json_pull_codec;
|
||||
pub mod quote;
|
||||
|
@ -311,9 +311,8 @@ mod tests {
|
||||
use crate::asb::Rate;
|
||||
use crate::env::GetConfig;
|
||||
use crate::monero;
|
||||
use crate::network::asb;
|
||||
use crate::network::test::{await_events_or_timeout, connect, new_swarm};
|
||||
use crate::protocol::bob;
|
||||
use crate::network::{asb, cli};
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -358,7 +357,7 @@ mod tests {
|
||||
balance: monero::Amount::ZERO,
|
||||
buy: btc_to_swap,
|
||||
},
|
||||
bob::spot_price::Error::BalanceTooLow { buy: btc_to_swap },
|
||||
cli::spot_price::Error::BalanceTooLow { buy: btc_to_swap },
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@ -384,7 +383,7 @@ mod tests {
|
||||
balance: monero::Amount::ZERO,
|
||||
buy: btc_to_swap,
|
||||
},
|
||||
bob::spot_price::Error::BalanceTooLow { buy: btc_to_swap },
|
||||
cli::spot_price::Error::BalanceTooLow { buy: btc_to_swap },
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@ -407,7 +406,7 @@ mod tests {
|
||||
balance,
|
||||
buy: btc_to_swap,
|
||||
},
|
||||
bob::spot_price::Error::BalanceTooLow { buy: btc_to_swap },
|
||||
cli::spot_price::Error::BalanceTooLow { buy: btc_to_swap },
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@ -426,7 +425,7 @@ mod tests {
|
||||
buy: btc_to_swap,
|
||||
min: min_buy,
|
||||
},
|
||||
bob::spot_price::Error::AmountBelowMinimum {
|
||||
cli::spot_price::Error::AmountBelowMinimum {
|
||||
buy: btc_to_swap,
|
||||
min: min_buy,
|
||||
},
|
||||
@ -449,7 +448,7 @@ mod tests {
|
||||
buy: btc_to_swap,
|
||||
max: max_buy,
|
||||
},
|
||||
bob::spot_price::Error::AmountAboveMaximum {
|
||||
cli::spot_price::Error::AmountAboveMaximum {
|
||||
buy: btc_to_swap,
|
||||
max: max_buy,
|
||||
},
|
||||
@ -466,7 +465,7 @@ mod tests {
|
||||
test.construct_and_send_request(btc_to_swap);
|
||||
test.assert_error(
|
||||
asb::spot_price::Error::ResumeOnlyMode,
|
||||
bob::spot_price::Error::NoSwapsAccepted,
|
||||
cli::spot_price::Error::NoSwapsAccepted,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@ -481,7 +480,7 @@ mod tests {
|
||||
test.construct_and_send_request(btc_to_swap);
|
||||
test.assert_error(
|
||||
asb::spot_price::Error::LatestRateFetchFailed(Box::new(TestRateError {})),
|
||||
bob::spot_price::Error::Other,
|
||||
cli::spot_price::Error::Other,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@ -500,7 +499,7 @@ mod tests {
|
||||
asb::spot_price::Error::SellQuoteCalculationFailed(anyhow!(
|
||||
"Error text irrelevant, won't be checked here"
|
||||
)),
|
||||
bob::spot_price::Error::Other,
|
||||
cli::spot_price::Error::Other,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@ -525,7 +524,7 @@ mod tests {
|
||||
monero: monero::Network::Mainnet,
|
||||
},
|
||||
},
|
||||
bob::spot_price::Error::BlockchainNetworkMismatch {
|
||||
cli::spot_price::Error::BlockchainNetworkMismatch {
|
||||
cli: BlockchainNetwork {
|
||||
bitcoin: bitcoin::Network::Testnet,
|
||||
monero: monero::Network::Stagenet,
|
||||
@ -564,7 +563,7 @@ mod tests {
|
||||
monero: monero::Network::Stagenet,
|
||||
},
|
||||
},
|
||||
bob::spot_price::Error::BlockchainNetworkMismatch {
|
||||
cli::spot_price::Error::BlockchainNetworkMismatch {
|
||||
cli: BlockchainNetwork {
|
||||
bitcoin: bitcoin::Network::Bitcoin,
|
||||
monero: monero::Network::Mainnet,
|
||||
@ -598,7 +597,7 @@ mod tests {
|
||||
values.resume_only,
|
||||
)
|
||||
});
|
||||
let (mut bob_swarm, ..) = new_swarm(|_, _| bob::spot_price::bob());
|
||||
let (mut bob_swarm, ..) = new_swarm(|_, _| cli::spot_price::bob());
|
||||
|
||||
connect(&mut alice_swarm, &mut bob_swarm).await;
|
||||
|
||||
@ -660,7 +659,7 @@ mod tests {
|
||||
async fn assert_error(
|
||||
&mut self,
|
||||
alice_assert: asb::spot_price::Error,
|
||||
bob_assert: bob::spot_price::Error,
|
||||
bob_assert: cli::spot_price::Error,
|
||||
) {
|
||||
match await_events_or_timeout(self.alice_swarm.next(), self.bob_swarm.next()).await {
|
||||
(
|
||||
|
3
swap/src/network/cli.rs
Normal file
3
swap/src/network/cli.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub mod behaviour;
|
||||
mod execution_setup;
|
||||
pub mod spot_price;
|
@ -1,12 +1,14 @@
|
||||
use crate::network::quote::BidQuote;
|
||||
use crate::network::{encrypted_signature, quote, redial, spot_price, transfer_proof};
|
||||
use crate::protocol::bob;
|
||||
use crate::protocol::bob::{execution_setup, State2};
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::{anyhow, Error, Result};
|
||||
use libp2p::core::Multiaddr;
|
||||
use libp2p::request_response::{RequestId, ResponseChannel};
|
||||
use libp2p::{NetworkBehaviour, PeerId};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::network::cli::execution_setup;
|
||||
use crate::network::quote::BidQuote;
|
||||
use crate::network::{cli, encrypted_signature, quote, redial, spot_price, transfer_proof};
|
||||
use crate::protocol::bob::State2;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum OutEvent {
|
||||
@ -72,7 +74,7 @@ impl Behaviour {
|
||||
pub fn new(alice: PeerId) -> Self {
|
||||
Self {
|
||||
quote: quote::bob(),
|
||||
spot_price: bob::spot_price::bob(),
|
||||
spot_price: cli::spot_price::bob(),
|
||||
execution_setup: Default::default(),
|
||||
transfer_proof: transfer_proof::bob(),
|
||||
encrypted_signature: encrypted_signature::bob(),
|
@ -1,22 +1,21 @@
|
||||
use crate::database::Database;
|
||||
use crate::{bitcoin, env, monero};
|
||||
use anyhow::Result;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub use self::behaviour::{Behaviour, OutEvent};
|
||||
use crate::database::Database;
|
||||
pub use crate::network::cli::behaviour::{Behaviour, OutEvent};
|
||||
use crate::{bitcoin, env, monero};
|
||||
|
||||
pub use self::cancel::cancel;
|
||||
pub use self::event_loop::{EventLoop, EventLoopHandle};
|
||||
pub use self::refund::refund;
|
||||
pub use self::state::*;
|
||||
pub use self::swap::{run, run_until};
|
||||
|
||||
mod behaviour;
|
||||
pub mod cancel;
|
||||
pub mod event_loop;
|
||||
mod execution_setup;
|
||||
pub mod refund;
|
||||
pub mod spot_price;
|
||||
pub mod state;
|
||||
pub mod swap;
|
||||
|
||||
|
@ -1,21 +1,22 @@
|
||||
use crate::bitcoin::EncryptedSignature;
|
||||
use crate::network::quote::BidQuote;
|
||||
use crate::network::spot_price::{BlockchainNetwork, Response};
|
||||
use crate::network::{encrypted_signature, spot_price};
|
||||
use crate::protocol::bob;
|
||||
use crate::protocol::bob::{Behaviour, OutEvent, State0, State2};
|
||||
use crate::{bitcoin, env, monero};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use futures::future::{BoxFuture, OptionFuture};
|
||||
use futures::{FutureExt, StreamExt};
|
||||
use libp2p::request_response::{RequestId, ResponseChannel};
|
||||
use libp2p::swarm::SwarmEvent;
|
||||
use libp2p::{PeerId, Swarm};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::bitcoin::EncryptedSignature;
|
||||
use crate::network::quote::BidQuote;
|
||||
use crate::network::spot_price::{BlockchainNetwork, Response};
|
||||
use crate::network::{cli, encrypted_signature, spot_price};
|
||||
use crate::protocol::bob::{Behaviour, OutEvent, State0, State2};
|
||||
use crate::{bitcoin, env, monero};
|
||||
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct EventLoop {
|
||||
swap_id: Uuid,
|
||||
@ -280,7 +281,7 @@ impl EventLoopHandle {
|
||||
match response {
|
||||
Response::Xmr(xmr) => Ok(xmr),
|
||||
Response::Error(error) => {
|
||||
let error: bob::spot_price::Error = error.into();
|
||||
let error: cli::spot_price::Error = error.into();
|
||||
bail!(error);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user