Change anyhow! to bail! in error scenarios

This commit is contained in:
Daniel Karzel 2021-03-01 14:24:44 +11:00
parent 7251588e79
commit 8c40ee1da4

View File

@ -16,7 +16,7 @@ use crate::{
}, },
seed::Seed, seed::Seed,
}; };
use anyhow::{anyhow, Context, Result}; use anyhow::{bail, Context, Result};
use futures::future::RemoteHandle; use futures::future::RemoteHandle;
use libp2p::{ use libp2p::{
core::Multiaddr, futures::FutureExt, request_response::ResponseChannel, PeerId, Swarm, core::Multiaddr, futures::FutureExt, request_response::ResponseChannel, PeerId, Swarm,
@ -221,19 +221,19 @@ where
let xmr_amount = rate.sell_quote(btc_amount)?; let xmr_amount = rate.sell_quote(btc_amount)?;
if xmr_amount > self.max_sell { if xmr_amount > self.max_sell {
anyhow!(MaximumSellAmountExceeded { bail!(MaximumSellAmountExceeded {
actual: xmr_amount, actual: xmr_amount,
max_sell: self.max_sell max_sell: self.max_sell
}); })
} }
let xmr_balance = monero_wallet.get_balance().await?; let xmr_balance = monero_wallet.get_balance().await?;
let xmr_lock_fees = monero_wallet.static_tx_fee_estimate(); let xmr_lock_fees = monero_wallet.static_tx_fee_estimate();
if xmr_balance < xmr_amount + xmr_lock_fees { if xmr_balance < xmr_amount + xmr_lock_fees {
anyhow!(BalanceTooLow { bail!(BalanceTooLow {
balance: xmr_balance balance: xmr_balance
}); })
} }
let quote_response = QuoteResponse { xmr_amount }; let quote_response = QuoteResponse { xmr_amount };