mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-25 15:39:25 -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,
|
||||
channel: ResponseChannel<SwapResponse>,
|
||||
},
|
||||
ExecutionSetupDone(anyhow::Result<Box<State3>>),
|
||||
ExecutionSetupDone(Box<State3>),
|
||||
TransferProofAcknowledged,
|
||||
EncryptedSignature {
|
||||
msg: Box<EncryptedSignature>,
|
||||
@ -53,8 +53,10 @@ impl From<alice::OutEvent> for OutEvent {
|
||||
|
||||
impl From<execution_setup::OutEvent> for OutEvent {
|
||||
fn from(event: execution_setup::OutEvent) -> Self {
|
||||
use crate::protocol::alice::execution_setup::OutEvent::*;
|
||||
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)]
|
||||
pub struct EventLoopHandle {
|
||||
done_execution_setup: Receiver<Result<State3>>,
|
||||
done_execution_setup: Receiver<State3>,
|
||||
recv_encrypted_signature: Receiver<EncryptedSignature>,
|
||||
recv_swap_request: Receiver<(SwapRequest, ResponseChannel<SwapResponse>)>,
|
||||
conn_established: Receiver<PeerId>,
|
||||
@ -61,7 +61,7 @@ impl EventLoopHandle {
|
||||
self.done_execution_setup
|
||||
.recv()
|
||||
.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> {
|
||||
@ -121,7 +121,7 @@ impl EventLoopHandle {
|
||||
pub struct EventLoop {
|
||||
swarm: libp2p::Swarm<Behaviour>,
|
||||
start_execution_setup: Receiver<(PeerId, State0)>,
|
||||
done_execution_setup: Sender<Result<State3>>,
|
||||
done_execution_setup: Sender<State3>,
|
||||
recv_encrypted_signature: Sender<EncryptedSignature>,
|
||||
recv_swap_request: Sender<(SwapRequest, ResponseChannel<SwapResponse>)>,
|
||||
conn_established: Sender<PeerId>,
|
||||
@ -194,8 +194,8 @@ impl EventLoop {
|
||||
OutEvent::SwapRequest { msg, channel } => {
|
||||
let _ = self.recv_swap_request.send((msg, channel)).await;
|
||||
}
|
||||
OutEvent::ExecutionSetupDone(res) => {
|
||||
let _ = self.done_execution_setup.send(res.map(|state|*state)).await;
|
||||
OutEvent::ExecutionSetupDone(state3) => {
|
||||
let _ = self.done_execution_setup.send(*state3).await;
|
||||
}
|
||||
OutEvent::TransferProofAcknowledged => {
|
||||
trace!("Bob acknowledged transfer proof");
|
||||
|
@ -8,7 +8,7 @@ use crate::{
|
||||
bob::{Message0, Message2, Message4},
|
||||
},
|
||||
};
|
||||
use anyhow::{Context, Error, Result};
|
||||
use anyhow::{Context, Error};
|
||||
use libp2p::PeerId;
|
||||
use libp2p_async_await::BehaviourOutEvent;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -32,14 +32,15 @@ pub struct Message3 {
|
||||
|
||||
#[derive(Debug)]
|
||||
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 {
|
||||
match event {
|
||||
BehaviourOutEvent::Inbound(_, Ok(State3)) => OutEvent::Done(Ok(State3)),
|
||||
BehaviourOutEvent::Inbound(_, Err(e)) => OutEvent::Done(Err(e)),
|
||||
BehaviourOutEvent::Inbound(_, Ok(State3)) => OutEvent::Done(State3),
|
||||
BehaviourOutEvent::Inbound(_, Err(e)) => OutEvent::Failure(e),
|
||||
BehaviourOutEvent::Outbound(..) => unreachable!("Alice only supports inbound"),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user