Improve code structure and error messages for running swaps

The quote message was repeated and we should set the overall
failure into a context to know what went wrong.
This commit is contained in:
Thomas Eizinger 2021-03-18 17:48:54 +11:00
parent 0c0a322a8f
commit 2c9ab4f6eb
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
2 changed files with 10 additions and 10 deletions

View File

@ -111,7 +111,7 @@ async fn main() -> Result<()> {
alice_addr,
bitcoin_wallet.clone(),
)?;
let handle = tokio::spawn(event_loop.run());
let event_loop = tokio::spawn(event_loop.run());
let send_bitcoin = determine_btc_to_swap(
event_loop_handle.request_quote(),
@ -142,13 +142,14 @@ async fn main() -> Result<()> {
.with_init_params(send_bitcoin)
.build()?;
let swap = bob::run(swap);
tokio::select! {
event_loop_result = handle => {
event_loop_result??;
result = event_loop => {
result
.context("EventLoop panicked")?
.context("EventLoop failed")?;
},
swap_result = swap => {
swap_result?;
result = bob::run(swap) => {
result.context("Failed to complete swap")?;
}
}
}
@ -207,12 +208,11 @@ async fn main() -> Result<()> {
)
.build()?;
let swap = bob::run(swap);
tokio::select! {
event_loop_result = handle => {
event_loop_result??;
},
swap_result = swap => {
swap_result = bob::run(swap) => {
swap_result?;
}
}
@ -314,7 +314,7 @@ async fn determine_btc_to_swap(
) -> Result<bitcoin::Amount> {
debug!("Requesting quote");
let bid_quote = request_quote.await.context("Failed to request quote")?;
let bid_quote = request_quote.await?;
info!("Received quote: 1 XMR ~ {}", bid_quote.price);

View File

@ -223,7 +223,7 @@ impl EventLoop {
}
OutEvent::ResponseSent => {}
OutEvent::CommunicationError(err) => {
bail!("Communication error: {:#}", err)
bail!(err.context("Communication error"))
}
}
},