mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
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:
parent
519d1a5701
commit
b47b06aa23
@ -1,4 +1,5 @@
|
|||||||
use crate::asb::{LatestRate, Rate};
|
use crate::asb::{LatestRate, Rate};
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
pub const RATE: f64 = 0.01;
|
pub const RATE: f64 = 0.01;
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ pub struct RateService(Rate);
|
|||||||
impl LatestRate for RateService {
|
impl LatestRate for RateService {
|
||||||
type Error = anyhow::Error;
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
fn latest_rate(&mut self) -> anyhow::Result<Rate> {
|
fn latest_rate(&mut self) -> Result<Rate> {
|
||||||
Ok(self.0)
|
Ok(self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::asb::{LatestRate, Rate};
|
use crate::asb::{LatestRate, Rate};
|
||||||
|
use anyhow::Result;
|
||||||
use bitcoin::util::amount::ParseAmountError;
|
use bitcoin::util::amount::ParseAmountError;
|
||||||
use futures::{SinkExt, StreamExt};
|
use futures::{SinkExt, StreamExt};
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
@ -64,7 +65,7 @@ impl From<serde_json::Error> for Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RateService {
|
impl RateService {
|
||||||
pub async fn new() -> anyhow::Result<Self> {
|
pub async fn new() -> Result<Self> {
|
||||||
let (tx, rx) = watch::channel(Err(Error::NotYetRetrieved));
|
let (tx, rx) = watch::channel(Err(Error::NotYetRetrieved));
|
||||||
|
|
||||||
let (ws, _response) =
|
let (ws, _response) =
|
||||||
|
@ -283,7 +283,7 @@ pub async fn current_epoch<W>(
|
|||||||
cancel_timelock: CancelTimelock,
|
cancel_timelock: CancelTimelock,
|
||||||
punish_timelock: PunishTimelock,
|
punish_timelock: PunishTimelock,
|
||||||
lock_tx_id: ::bitcoin::Txid,
|
lock_tx_id: ::bitcoin::Txid,
|
||||||
) -> anyhow::Result<ExpiredTimelocks>
|
) -> Result<ExpiredTimelocks>
|
||||||
where
|
where
|
||||||
W: WatchForRawTransaction + TransactionBlockHeight + GetBlockHeight,
|
W: WatchForRawTransaction + TransactionBlockHeight + GetBlockHeight,
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::bitcoin;
|
use crate::bitcoin;
|
||||||
|
use anyhow::Result;
|
||||||
use libp2p::{core::Multiaddr, PeerId};
|
use libp2p::{core::Multiaddr, PeerId};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use uuid::Uuid;
|
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)?;
|
let amount = bitcoin::Amount::from_str_in(str, ::bitcoin::Denomination::Bitcoin)?;
|
||||||
Ok(amount)
|
Ok(amount)
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ impl Database {
|
|||||||
.context("Could not flush db")
|
.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 key = serialize(&swap_id)?;
|
||||||
|
|
||||||
let encoded = self
|
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
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
Ok(serde_cbor::to_vec(t)?)
|
Ok(serde_cbor::to_vec(t)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deserialize<T>(v: &[u8]) -> anyhow::Result<T>
|
pub fn deserialize<T>(v: &[u8]) -> Result<T>
|
||||||
where
|
where
|
||||||
T: DeserializeOwned,
|
T: DeserializeOwned,
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use anyhow::Context;
|
use anyhow::{Context, Result};
|
||||||
use directories_next::ProjectDirs;
|
use directories_next::ProjectDirs;
|
||||||
use std::path::{Path, PathBuf};
|
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())
|
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()
|
default_config_dir()
|
||||||
.map(|dir| Path::join(&dir, "config.toml"))
|
.map(|dir| Path::join(&dir, "config.toml"))
|
||||||
.context("Could not generate default configuration path")
|
.context("Could not generate default configuration path")
|
||||||
|
@ -186,7 +186,7 @@ pub trait Transfer {
|
|||||||
public_spend_key: PublicKey,
|
public_spend_key: PublicKey,
|
||||||
public_view_key: PublicViewKey,
|
public_view_key: PublicViewKey,
|
||||||
amount: Amount,
|
amount: Amount,
|
||||||
) -> anyhow::Result<(TransferProof, Amount)>;
|
) -> Result<(TransferProof, Amount)>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@ -215,17 +215,17 @@ pub trait CreateWalletForOutput {
|
|||||||
private_spend_key: PrivateKey,
|
private_spend_key: PrivateKey,
|
||||||
private_view_key: PrivateViewKey,
|
private_view_key: PrivateViewKey,
|
||||||
restore_height: Option<u32>,
|
restore_height: Option<u32>,
|
||||||
) -> anyhow::Result<()>;
|
) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait OpenWallet {
|
pub trait OpenWallet {
|
||||||
async fn open_wallet(&self, file_name: &str) -> anyhow::Result<()>;
|
async fn open_wallet(&self, file_name: &str) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait CreateWallet {
|
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)]
|
#[derive(thiserror::Error, Debug, Clone, PartialEq)]
|
||||||
|
@ -119,7 +119,7 @@ impl Behaviour {
|
|||||||
&mut self,
|
&mut self,
|
||||||
channel: ResponseChannel<QuoteResponse>,
|
channel: ResponseChannel<QuoteResponse>,
|
||||||
quote_response: QuoteResponse,
|
quote_response: QuoteResponse,
|
||||||
) -> anyhow::Result<()> {
|
) -> Result<()> {
|
||||||
self.quote_response.send(channel, quote_response)?;
|
self.quote_response.send(channel, quote_response)?;
|
||||||
info!("Sent quote response");
|
info!("Sent quote response");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -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
|
where
|
||||||
W: BuildTxLockPsbt + GetNetwork,
|
W: BuildTxLockPsbt + GetNetwork,
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
|
use anyhow::Result;
|
||||||
use atty::{self};
|
use atty::{self};
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use tracing::{info, subscriber};
|
use tracing::{info, subscriber};
|
||||||
use tracing_log::LogTracer;
|
use tracing_log::LogTracer;
|
||||||
use tracing_subscriber::FmtSubscriber;
|
use tracing_subscriber::FmtSubscriber;
|
||||||
|
|
||||||
pub fn init_tracing(level: LevelFilter) -> anyhow::Result<()> {
|
pub fn init_tracing(level: LevelFilter) -> Result<()> {
|
||||||
if level == LevelFilter::Off {
|
if level == LevelFilter::Off {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ pub struct TestContext {
|
|||||||
alice_starting_balances: StartingBalances,
|
alice_starting_balances: StartingBalances,
|
||||||
alice_bitcoin_wallet: Arc<bitcoin::Wallet>,
|
alice_bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||||
alice_monero_wallet: Arc<monero::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_params: BobParams,
|
||||||
bob_starting_balances: StartingBalances,
|
bob_starting_balances: StartingBalances,
|
||||||
|
Loading…
Reference in New Issue
Block a user