mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-09 23:12:40 -04:00
swap_setup
instead of spot_price
and execution_setup
Having `spot_price` and `execution_setup` as separate protocols did not bring any advantages, but was problematic because we had to ensure that `execution_setup` would be triggered after `spot_price`. Because of this dependency it is better to combine the protocols into one. Combining the protocols also allows a refactoring to get rid of the `libp2p-async-await` dependency. Alice always listens for the `swap_setup` protocol. When Bob opens a substream on that protocol the spot price is communicated, and then all execution setup messages (swap-id and signature exchange).
This commit is contained in:
parent
ada5acb2b5
commit
85f5635663
30 changed files with 1064 additions and 1567 deletions
|
@ -1,34 +1,34 @@
|
|||
use crate::network::quote::BidQuote;
|
||||
use crate::network::{encrypted_signature, quote, transfer_proof};
|
||||
use crate::protocol::alice::event_loop::LatestRate;
|
||||
use crate::protocol::alice::{execution_setup, spot_price, State3};
|
||||
use crate::{env, monero};
|
||||
use anyhow::{anyhow, Error};
|
||||
use libp2p::ping::{Ping, PingEvent};
|
||||
use libp2p::request_response::{RequestId, ResponseChannel};
|
||||
use libp2p::{NetworkBehaviour, PeerId};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::env;
|
||||
use crate::network::quote::BidQuote;
|
||||
use crate::network::{encrypted_signature, quote, transfer_proof};
|
||||
use crate::protocol::alice::event_loop::LatestRate;
|
||||
use crate::protocol::alice::swap_setup::WalletSnapshot;
|
||||
use crate::protocol::alice::{swap_setup, State3};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum OutEvent {
|
||||
SwapRequestDeclined {
|
||||
peer: PeerId,
|
||||
error: spot_price::Error,
|
||||
SwapSetupInitiated {
|
||||
send_wallet_snapshot: bmrng::RequestReceiver<bitcoin::Amount, WalletSnapshot>,
|
||||
},
|
||||
ExecutionSetupStart {
|
||||
SwapSetupCompleted {
|
||||
peer_id: PeerId,
|
||||
swap_id: Uuid,
|
||||
state3: Box<State3>,
|
||||
},
|
||||
SwapDeclined {
|
||||
peer: PeerId,
|
||||
btc: bitcoin::Amount,
|
||||
xmr: monero::Amount,
|
||||
error: swap_setup::Error,
|
||||
},
|
||||
QuoteRequested {
|
||||
channel: ResponseChannel<BidQuote>,
|
||||
peer: PeerId,
|
||||
},
|
||||
ExecutionSetupDone {
|
||||
bob_peer_id: PeerId,
|
||||
swap_id: Uuid,
|
||||
state3: Box<State3>,
|
||||
},
|
||||
TransferProofAcknowledged {
|
||||
peer: PeerId,
|
||||
id: RequestId,
|
||||
|
@ -72,8 +72,7 @@ where
|
|||
LR: LatestRate + Send + 'static,
|
||||
{
|
||||
pub quote: quote::Behaviour,
|
||||
pub spot_price: spot_price::Behaviour<LR>,
|
||||
pub execution_setup: execution_setup::Behaviour,
|
||||
pub swap_setup: swap_setup::Behaviour<LR>,
|
||||
pub transfer_proof: transfer_proof::Behaviour,
|
||||
pub encrypted_signature: encrypted_signature::Behaviour,
|
||||
|
||||
|
@ -88,8 +87,6 @@ where
|
|||
LR: LatestRate + Send + 'static,
|
||||
{
|
||||
pub fn new(
|
||||
balance: monero::Amount,
|
||||
lock_fee: monero::Amount,
|
||||
min_buy: bitcoin::Amount,
|
||||
max_buy: bitcoin::Amount,
|
||||
latest_rate: LR,
|
||||
|
@ -98,16 +95,13 @@ where
|
|||
) -> Self {
|
||||
Self {
|
||||
quote: quote::alice(),
|
||||
spot_price: spot_price::Behaviour::new(
|
||||
balance,
|
||||
lock_fee,
|
||||
swap_setup: swap_setup::Behaviour::new(
|
||||
min_buy,
|
||||
max_buy,
|
||||
env_config,
|
||||
latest_rate,
|
||||
resume_only,
|
||||
),
|
||||
execution_setup: Default::default(),
|
||||
transfer_proof: transfer_proof::alice(),
|
||||
encrypted_signature: encrypted_signature::alice(),
|
||||
ping: Ping::default(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue