mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-13 00:19:31 -05:00
Process execution setup failure similarly to other failures
By merging it in the failure event of the root behaviour.
This commit is contained in:
parent
4ade5df0e5
commit
f5ca5faabf
@ -20,7 +20,7 @@ pub enum OutEvent {
|
|||||||
msg: SwapRequest,
|
msg: SwapRequest,
|
||||||
channel: ResponseChannel<SwapResponse>,
|
channel: ResponseChannel<SwapResponse>,
|
||||||
},
|
},
|
||||||
ExecutionSetupDone(anyhow::Result<Box<State3>>),
|
ExecutionSetupDone(Box<State3>),
|
||||||
TransferProofAcknowledged,
|
TransferProofAcknowledged,
|
||||||
EncryptedSignature {
|
EncryptedSignature {
|
||||||
msg: Box<EncryptedSignature>,
|
msg: Box<EncryptedSignature>,
|
||||||
@ -53,8 +53,10 @@ impl From<alice::OutEvent> for OutEvent {
|
|||||||
|
|
||||||
impl From<execution_setup::OutEvent> for OutEvent {
|
impl From<execution_setup::OutEvent> for OutEvent {
|
||||||
fn from(event: execution_setup::OutEvent) -> Self {
|
fn from(event: execution_setup::OutEvent) -> Self {
|
||||||
|
use crate::protocol::alice::execution_setup::OutEvent::*;
|
||||||
match event {
|
match event {
|
||||||
execution_setup::OutEvent::Done(res) => OutEvent::ExecutionSetupDone(res.map(Box::new)),
|
Done(state3) => OutEvent::ExecutionSetupDone(Box::new(state3)),
|
||||||
|
Failure(err) => OutEvent::Failure(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ impl<T> Default for Channels<T> {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EventLoopHandle {
|
pub struct EventLoopHandle {
|
||||||
done_execution_setup: Receiver<Result<State3>>,
|
done_execution_setup: Receiver<State3>,
|
||||||
recv_encrypted_signature: Receiver<EncryptedSignature>,
|
recv_encrypted_signature: Receiver<EncryptedSignature>,
|
||||||
recv_swap_request: Receiver<(SwapRequest, ResponseChannel<SwapResponse>)>,
|
recv_swap_request: Receiver<(SwapRequest, ResponseChannel<SwapResponse>)>,
|
||||||
conn_established: Receiver<PeerId>,
|
conn_established: Receiver<PeerId>,
|
||||||
@ -61,7 +61,7 @@ impl EventLoopHandle {
|
|||||||
self.done_execution_setup
|
self.done_execution_setup
|
||||||
.recv()
|
.recv()
|
||||||
.await
|
.await
|
||||||
.ok_or_else(|| anyhow!("Failed to setup execution with Bob"))?
|
.ok_or_else(|| anyhow!("Failed to setup execution with Bob"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn recv_encrypted_signature(&mut self) -> Result<EncryptedSignature> {
|
pub async fn recv_encrypted_signature(&mut self) -> Result<EncryptedSignature> {
|
||||||
@ -121,7 +121,7 @@ impl EventLoopHandle {
|
|||||||
pub struct EventLoop {
|
pub struct EventLoop {
|
||||||
swarm: libp2p::Swarm<Behaviour>,
|
swarm: libp2p::Swarm<Behaviour>,
|
||||||
start_execution_setup: Receiver<(PeerId, State0)>,
|
start_execution_setup: Receiver<(PeerId, State0)>,
|
||||||
done_execution_setup: Sender<Result<State3>>,
|
done_execution_setup: Sender<State3>,
|
||||||
recv_encrypted_signature: Sender<EncryptedSignature>,
|
recv_encrypted_signature: Sender<EncryptedSignature>,
|
||||||
recv_swap_request: Sender<(SwapRequest, ResponseChannel<SwapResponse>)>,
|
recv_swap_request: Sender<(SwapRequest, ResponseChannel<SwapResponse>)>,
|
||||||
conn_established: Sender<PeerId>,
|
conn_established: Sender<PeerId>,
|
||||||
@ -194,8 +194,8 @@ impl EventLoop {
|
|||||||
OutEvent::SwapRequest { msg, channel } => {
|
OutEvent::SwapRequest { msg, channel } => {
|
||||||
let _ = self.recv_swap_request.send((msg, channel)).await;
|
let _ = self.recv_swap_request.send((msg, channel)).await;
|
||||||
}
|
}
|
||||||
OutEvent::ExecutionSetupDone(res) => {
|
OutEvent::ExecutionSetupDone(state3) => {
|
||||||
let _ = self.done_execution_setup.send(res.map(|state|*state)).await;
|
let _ = self.done_execution_setup.send(*state3).await;
|
||||||
}
|
}
|
||||||
OutEvent::TransferProofAcknowledged => {
|
OutEvent::TransferProofAcknowledged => {
|
||||||
trace!("Bob acknowledged transfer proof");
|
trace!("Bob acknowledged transfer proof");
|
||||||
|
@ -8,7 +8,7 @@ use crate::{
|
|||||||
bob::{Message0, Message2, Message4},
|
bob::{Message0, Message2, Message4},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anyhow::{Context, Error, Result};
|
use anyhow::{Context, Error};
|
||||||
use libp2p::PeerId;
|
use libp2p::PeerId;
|
||||||
use libp2p_async_await::BehaviourOutEvent;
|
use libp2p_async_await::BehaviourOutEvent;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -32,14 +32,15 @@ pub struct Message3 {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum OutEvent {
|
pub enum OutEvent {
|
||||||
Done(Result<State3>),
|
Done(State3),
|
||||||
|
Failure(Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<BehaviourOutEvent<State3, (), anyhow::Error>> for OutEvent {
|
impl From<BehaviourOutEvent<State3, (), Error>> for OutEvent {
|
||||||
fn from(event: BehaviourOutEvent<State3, (), Error>) -> Self {
|
fn from(event: BehaviourOutEvent<State3, (), Error>) -> Self {
|
||||||
match event {
|
match event {
|
||||||
BehaviourOutEvent::Inbound(_, Ok(State3)) => OutEvent::Done(Ok(State3)),
|
BehaviourOutEvent::Inbound(_, Ok(State3)) => OutEvent::Done(State3),
|
||||||
BehaviourOutEvent::Inbound(_, Err(e)) => OutEvent::Done(Err(e)),
|
BehaviourOutEvent::Inbound(_, Err(e)) => OutEvent::Failure(e),
|
||||||
BehaviourOutEvent::Outbound(..) => unreachable!("Alice only supports inbound"),
|
BehaviourOutEvent::Outbound(..) => unreachable!("Alice only supports inbound"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user