Import anyhow::Result across the codebase

There is no need to fully qualify this type because it is a type
alias for std::Result. We can mix and match the two as we want.
This commit is contained in:
Thomas Eizinger 2021-02-19 17:00:45 +11:00 committed by Daniel Karzel
parent 519d1a5701
commit b47b06aa23
11 changed files with 21 additions and 17 deletions

View File

@ -1,4 +1,5 @@
use crate::asb::{LatestRate, Rate};
use anyhow::Result;
pub const RATE: f64 = 0.01;
@ -8,7 +9,7 @@ pub struct RateService(Rate);
impl LatestRate for RateService {
type Error = anyhow::Error;
fn latest_rate(&mut self) -> anyhow::Result<Rate> {
fn latest_rate(&mut self) -> Result<Rate> {
Ok(self.0)
}
}

View File

@ -1,4 +1,5 @@
use crate::asb::{LatestRate, Rate};
use anyhow::Result;
use bitcoin::util::amount::ParseAmountError;
use futures::{SinkExt, StreamExt};
use reqwest::Url;
@ -64,7 +65,7 @@ impl From<serde_json::Error> for Error {
}
impl RateService {
pub async fn new() -> anyhow::Result<Self> {
pub async fn new() -> Result<Self> {
let (tx, rx) = watch::channel(Err(Error::NotYetRetrieved));
let (ws, _response) =

View File

@ -283,7 +283,7 @@ pub async fn current_epoch<W>(
cancel_timelock: CancelTimelock,
punish_timelock: PunishTimelock,
lock_tx_id: ::bitcoin::Txid,
) -> anyhow::Result<ExpiredTimelocks>
) -> Result<ExpiredTimelocks>
where
W: WatchForRawTransaction + TransactionBlockHeight + GetBlockHeight,
{

View File

@ -1,4 +1,5 @@
use crate::bitcoin;
use anyhow::Result;
use libp2p::{core::Multiaddr, PeerId};
use std::path::PathBuf;
use uuid::Uuid;
@ -85,7 +86,7 @@ pub enum Refund {
},
}
fn parse_btc(str: &str) -> anyhow::Result<bitcoin::Amount> {
fn parse_btc(str: &str) -> Result<bitcoin::Amount> {
let amount = bitcoin::Amount::from_str_in(str, ::bitcoin::Denomination::Bitcoin)?;
Ok(amount)
}

View File

@ -65,7 +65,7 @@ impl Database {
.context("Could not flush db")
}
pub fn get_state(&self, swap_id: Uuid) -> anyhow::Result<Swap> {
pub fn get_state(&self, swap_id: Uuid) -> Result<Swap> {
let key = serialize(&swap_id)?;
let encoded = self
@ -97,14 +97,14 @@ impl Database {
}
}
pub fn serialize<T>(t: &T) -> anyhow::Result<Vec<u8>>
pub fn serialize<T>(t: &T) -> Result<Vec<u8>>
where
T: Serialize,
{
Ok(serde_cbor::to_vec(t)?)
}
pub fn deserialize<T>(v: &[u8]) -> anyhow::Result<T>
pub fn deserialize<T>(v: &[u8]) -> Result<T>
where
T: DeserializeOwned,
{

View File

@ -1,4 +1,4 @@
use anyhow::Context;
use anyhow::{Context, Result};
use directories_next::ProjectDirs;
use std::path::{Path, PathBuf};
@ -9,7 +9,7 @@ fn default_config_dir() -> Option<PathBuf> {
ProjectDirs::from("", "", "xmr-btc-swap").map(|proj_dirs| proj_dirs.config_dir().to_path_buf())
}
pub fn default_config_path() -> anyhow::Result<PathBuf> {
pub fn default_config_path() -> Result<PathBuf> {
default_config_dir()
.map(|dir| Path::join(&dir, "config.toml"))
.context("Could not generate default configuration path")

View File

@ -186,7 +186,7 @@ pub trait Transfer {
public_spend_key: PublicKey,
public_view_key: PublicViewKey,
amount: Amount,
) -> anyhow::Result<(TransferProof, Amount)>;
) -> Result<(TransferProof, Amount)>;
}
#[async_trait]
@ -215,17 +215,17 @@ pub trait CreateWalletForOutput {
private_spend_key: PrivateKey,
private_view_key: PrivateViewKey,
restore_height: Option<u32>,
) -> anyhow::Result<()>;
) -> Result<()>;
}
#[async_trait]
pub trait OpenWallet {
async fn open_wallet(&self, file_name: &str) -> anyhow::Result<()>;
async fn open_wallet(&self, file_name: &str) -> Result<()>;
}
#[async_trait]
pub trait CreateWallet {
async fn create_wallet(&self, file_name: &str) -> anyhow::Result<()>;
async fn create_wallet(&self, file_name: &str) -> Result<()>;
}
#[derive(thiserror::Error, Debug, Clone, PartialEq)]

View File

@ -119,7 +119,7 @@ impl Behaviour {
&mut self,
channel: ResponseChannel<QuoteResponse>,
quote_response: QuoteResponse,
) -> anyhow::Result<()> {
) -> Result<()> {
self.quote_response.send(channel, quote_response)?;
info!("Sent quote response");
Ok(())

View File

@ -140,7 +140,7 @@ impl State0 {
}
}
pub async fn receive<W>(self, wallet: &W, msg: Message1) -> anyhow::Result<State1>
pub async fn receive<W>(self, wallet: &W, msg: Message1) -> Result<State1>
where
W: BuildTxLockPsbt + GetNetwork,
{

View File

@ -1,10 +1,11 @@
use anyhow::Result;
use atty::{self};
use log::LevelFilter;
use tracing::{info, subscriber};
use tracing_log::LogTracer;
use tracing_subscriber::FmtSubscriber;
pub fn init_tracing(level: LevelFilter) -> anyhow::Result<()> {
pub fn init_tracing(level: LevelFilter) -> Result<()> {
if level == LevelFilter::Off {
return Ok(());
}

View File

@ -84,7 +84,7 @@ pub struct TestContext {
alice_starting_balances: StartingBalances,
alice_bitcoin_wallet: Arc<bitcoin::Wallet>,
alice_monero_wallet: Arc<monero::Wallet>,
alice_swap_handle: mpsc::Receiver<RemoteHandle<anyhow::Result<AliceState>>>,
alice_swap_handle: mpsc::Receiver<RemoteHandle<Result<AliceState>>>,
bob_params: BobParams,
bob_starting_balances: StartingBalances,