mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-25 07:29:32 -05:00
Make sure all error messages start with an uppercase letter
These might potentially be shown to a user, let's make them all consistent.
This commit is contained in:
parent
816e8b9b96
commit
4138039ea0
@ -77,7 +77,7 @@ pub fn read_config(config_path: PathBuf) -> Result<Result<Config, ConfigNotIniti
|
||||
}
|
||||
|
||||
let file = Config::read(&config_path)
|
||||
.with_context(|| format!("failed to read config file {}", config_path.display()))?;
|
||||
.with_context(|| format!("Failed to read config file at {}", config_path.display()))?;
|
||||
|
||||
Ok(Ok(file))
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{bitcoin, monero};
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::{Context, Result};
|
||||
use rust_decimal::prelude::ToPrimitive;
|
||||
use rust_decimal::Decimal;
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
@ -30,20 +30,20 @@ impl Rate {
|
||||
let quote_in_sats = quote.as_sat();
|
||||
let quote_in_btc = Decimal::from(quote_in_sats)
|
||||
.checked_div(Decimal::from(bitcoin::Amount::ONE_BTC.as_sat()))
|
||||
.ok_or_else(|| anyhow!("division overflow"))?;
|
||||
.context("Division overflow")?;
|
||||
|
||||
let rate_in_btc = Decimal::from(rate.as_sat())
|
||||
.checked_div(Decimal::from(bitcoin::Amount::ONE_BTC.as_sat()))
|
||||
.ok_or_else(|| anyhow!("division overflow"))?;
|
||||
.context("Division overflow")?;
|
||||
|
||||
let base_in_xmr = quote_in_btc
|
||||
.checked_div(rate_in_btc)
|
||||
.ok_or_else(|| anyhow!("division overflow"))?;
|
||||
.context("Division overflow")?;
|
||||
let base_in_piconero = base_in_xmr * Decimal::from(monero::Amount::ONE_XMR.as_piconero());
|
||||
|
||||
let base_in_piconero = base_in_piconero
|
||||
.to_u64()
|
||||
.ok_or_else(|| anyhow!("decimal cannot be represented as u64"))?;
|
||||
.context("Failed to fit piconero amount into a u64")?;
|
||||
|
||||
Ok(monero::Amount::from_piconero(base_in_piconero))
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ async fn init_monero_wallet(
|
||||
let _test_wallet_connection = monero_wallet
|
||||
.block_height()
|
||||
.await
|
||||
.context("failed to validate connection to monero-wallet-rpc")?;
|
||||
.context("Failed to validate connection to monero-wallet-rpc")?;
|
||||
|
||||
Ok((monero_wallet, monero_wallet_rpc_process))
|
||||
}
|
||||
@ -299,7 +299,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.context("Failed to request quote")?;
|
||||
|
||||
info!("Received quote: 1 XMR ~ {}", bid_quote.price);
|
||||
|
||||
|
@ -23,7 +23,7 @@ pub use wallet::Wallet;
|
||||
use ::bitcoin::hashes::hex::ToHex;
|
||||
use ::bitcoin::hashes::Hash;
|
||||
use ::bitcoin::{secp256k1, SigHash};
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use ecdsa_fun::adaptor::{Adaptor, HashTranscript};
|
||||
use ecdsa_fun::fun::Point;
|
||||
use ecdsa_fun::nonce::Deterministic;
|
||||
@ -204,7 +204,7 @@ pub fn recover(S: PublicKey, sig: Signature, encsig: EncryptedSignature) -> Resu
|
||||
let s = adaptor
|
||||
.recover_decryption_key(&S.0, &sig, &encsig)
|
||||
.map(SecretKey::from)
|
||||
.ok_or_else(|| anyhow!("secret recovery failure"))?;
|
||||
.context("Failed to recover secret from adaptor signature")?;
|
||||
|
||||
Ok(s)
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ impl TxRedeem {
|
||||
let sig = sigs
|
||||
.into_iter()
|
||||
.find(|sig| verify_sig(&B, &self.digest(), &sig).is_ok())
|
||||
.context("neither signature on witness stack verifies against B")?;
|
||||
.context("Neither signature on witness stack verifies against B")?;
|
||||
|
||||
Ok(sig)
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ impl TxRefund {
|
||||
let sig = sigs
|
||||
.into_iter()
|
||||
.find(|sig| verify_sig(&B, &self.digest(), &sig).is_ok())
|
||||
.context("neither signature on witness stack verifies against B")?;
|
||||
.context("Neither signature on witness stack verifies against B")?;
|
||||
|
||||
Ok(sig)
|
||||
}
|
||||
|
@ -74,13 +74,23 @@ impl Wallet {
|
||||
}
|
||||
|
||||
pub async fn balance(&self) -> Result<Amount> {
|
||||
let balance = self.inner.lock().await.get_balance().context("Failed to calculate Bitcoin balance")?;
|
||||
let balance = self
|
||||
.inner
|
||||
.lock()
|
||||
.await
|
||||
.get_balance()
|
||||
.context("Failed to calculate Bitcoin balance")?;
|
||||
|
||||
Ok(Amount::from_sat(balance))
|
||||
}
|
||||
|
||||
pub async fn new_address(&self) -> Result<Address> {
|
||||
let address = self.inner.lock().await.get_new_address().context("Failed to get new Bitcoin address")?;
|
||||
let address = self
|
||||
.inner
|
||||
.lock()
|
||||
.await
|
||||
.get_new_address()
|
||||
.context("Failed to get new Bitcoin address")?;
|
||||
|
||||
Ok(address)
|
||||
}
|
||||
@ -111,7 +121,7 @@ impl Wallet {
|
||||
.lock()
|
||||
.await
|
||||
.sync(noop_progress(), None)
|
||||
.context("failed to sync balance of Bitcoin wallet")?;
|
||||
.context("Failed to sync balance of Bitcoin wallet")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -166,7 +176,7 @@ impl Wallet {
|
||||
.await
|
||||
.broadcast(transaction)
|
||||
.with_context(|| {
|
||||
format!("failed to broadcast Bitcoin {} transaction {}", kind, txid)
|
||||
format!("Failed to broadcast Bitcoin {} transaction {}", kind, txid)
|
||||
})?;
|
||||
|
||||
tracing::info!("Published Bitcoin {} transaction as {}", txid, kind);
|
||||
@ -209,7 +219,7 @@ impl Wallet {
|
||||
Result::<_, backoff::Error<Error>>::Ok(tx)
|
||||
})
|
||||
.await
|
||||
.context("transient errors to be retried")?;
|
||||
.context("Transient errors should be retried")?;
|
||||
|
||||
Ok(tx)
|
||||
}
|
||||
@ -230,7 +240,7 @@ impl Wallet {
|
||||
Result::<_, backoff::Error<Error>>::Ok(height)
|
||||
})
|
||||
.await
|
||||
.context("transient errors to be retried")?;
|
||||
.context("Transient errors should be retried")?;
|
||||
|
||||
Ok(BlockHeight::new(height))
|
||||
}
|
||||
@ -261,7 +271,7 @@ impl Wallet {
|
||||
Result::<_, backoff::Error<Error>>::Ok(block_height)
|
||||
})
|
||||
.await
|
||||
.context("transient errors to be retried")?;
|
||||
.context("Transient errors should be retried")?;
|
||||
|
||||
Ok(BlockHeight::new(height))
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ pub fn read_config(config_path: PathBuf) -> Result<Result<Config, ConfigNotIniti
|
||||
}
|
||||
|
||||
let file = Config::read(&config_path)
|
||||
.with_context(|| format!("failed to read config file {}", config_path.display()))?;
|
||||
.with_context(|| format!("Failed to read config file at {}", config_path.display()))?;
|
||||
|
||||
Ok(Ok(file))
|
||||
}
|
||||
|
@ -96,15 +96,15 @@ impl Database {
|
||||
.map(|item| match item {
|
||||
Ok((key, value)) => {
|
||||
let swap_id = deserialize::<Uuid>(&key);
|
||||
let swap = deserialize::<Swap>(&value).context("failed to deserialize swap");
|
||||
let swap = deserialize::<Swap>(&value).context("Failed to deserialize swap");
|
||||
|
||||
match (swap_id, swap) {
|
||||
(Ok(swap_id), Ok(swap)) => Ok((swap_id, swap)),
|
||||
(Ok(_), Err(err)) => Err(err),
|
||||
_ => bail!("failed to deserialize swap"),
|
||||
_ => bail!("Failed to deserialize swap"),
|
||||
}
|
||||
}
|
||||
Err(err) => Err(err).context("failed to retrieve swap from DB"),
|
||||
Err(err) => Err(err).context("Failed to retrieve swap from DB"),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ impl WalletRpc {
|
||||
|
||||
let content_length = response.headers()[CONTENT_LENGTH]
|
||||
.to_str()
|
||||
.context("failed to convert content-length to string")?
|
||||
.context("Failed to convert content-length to string")?
|
||||
.parse::<u64>()?;
|
||||
|
||||
tracing::info!(
|
||||
|
@ -184,7 +184,7 @@ impl Behaviour {
|
||||
) -> Result<()> {
|
||||
self.quote
|
||||
.send_response(channel, response)
|
||||
.map_err(|_| anyhow!("failed to respond with quote"))?;
|
||||
.map_err(|_| anyhow!("Failed to respond with quote"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -196,7 +196,7 @@ impl Behaviour {
|
||||
) -> Result<()> {
|
||||
self.spot_price
|
||||
.send_response(channel, response)
|
||||
.map_err(|_| anyhow!("failed to respond with spot price"))?;
|
||||
.map_err(|_| anyhow!("Failed to respond with spot price"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -65,31 +65,31 @@ impl Behaviour {
|
||||
.do_protocol_listener(bob, move |mut substream| async move {
|
||||
let message0 =
|
||||
serde_cbor::from_slice::<Message0>(&substream.read_message(BUF_SIZE).await?)
|
||||
.context("failed to deserialize message0")?;
|
||||
.context("Failed to deserialize message0")?;
|
||||
let state1 = state0.receive(message0)?;
|
||||
|
||||
substream
|
||||
.write_message(
|
||||
&serde_cbor::to_vec(&state1.next_message())
|
||||
.context("failed to serialize message1")?,
|
||||
.context("Failed to serialize message1")?,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let message2 =
|
||||
serde_cbor::from_slice::<Message2>(&substream.read_message(BUF_SIZE).await?)
|
||||
.context("failed to deserialize message2")?;
|
||||
.context("Failed to deserialize message2")?;
|
||||
let state2 = state1.receive(message2);
|
||||
|
||||
substream
|
||||
.write_message(
|
||||
&serde_cbor::to_vec(&state2.next_message())
|
||||
.context("failed to serialize message3")?,
|
||||
.context("Failed to serialize message3")?,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let message4 =
|
||||
serde_cbor::from_slice::<Message4>(&substream.read_message(BUF_SIZE).await?)
|
||||
.context("failed to deserialize message4")?;
|
||||
.context("Failed to deserialize message4")?;
|
||||
let state3 = state2.receive(message4)?;
|
||||
|
||||
Ok((bob, state3))
|
||||
|
@ -106,7 +106,7 @@ pub fn build_bitcoin_redeem_transaction(
|
||||
|
||||
let tx = tx_redeem
|
||||
.add_signatures((a.public(), sig_a), (B, sig_b))
|
||||
.context("sig_{a,b} are invalid for tx_redeem")?;
|
||||
.context("Failed to sign Bitcoin redeem transaction")?;
|
||||
|
||||
Ok(tx)
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ impl EventLoop {
|
||||
let _ = self.conn_established.send(peer_id).await;
|
||||
} else {
|
||||
debug!("Dialing alice at {}", peer_id);
|
||||
libp2p::Swarm::dial(&mut self.swarm, &peer_id).context("failed to dial alice")?;
|
||||
libp2p::Swarm::dial(&mut self.swarm, &peer_id).context("Failed to dial alice")?;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -73,31 +73,31 @@ impl Behaviour {
|
||||
substream
|
||||
.write_message(
|
||||
&serde_cbor::to_vec(&state0.next_message())
|
||||
.context("failed to serialize message0")?,
|
||||
.context("Failed to serialize message0")?,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let message1 =
|
||||
serde_cbor::from_slice::<Message1>(&substream.read_message(BUF_SIZE).await?)
|
||||
.context("failed to deserialize message1")?;
|
||||
.context("Failed to deserialize message1")?;
|
||||
let state1 = state0.receive(bitcoin_wallet.as_ref(), message1).await?;
|
||||
|
||||
substream
|
||||
.write_message(
|
||||
&serde_cbor::to_vec(&state1.next_message())
|
||||
.context("failed to serialize message2")?,
|
||||
.context("Failed to serialize message2")?,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let message3 =
|
||||
serde_cbor::from_slice::<Message3>(&substream.read_message(BUF_SIZE).await?)
|
||||
.context("failed to deserialize message3")?;
|
||||
.context("Failed to deserialize message3")?;
|
||||
let state2 = state1.receive(message3)?;
|
||||
|
||||
substream
|
||||
.write_message(
|
||||
&serde_cbor::to_vec(&state2.next_message())
|
||||
.context("failed to serialize message4")?,
|
||||
.context("Failed to serialize message4")?,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
@ -266,7 +266,7 @@ impl State2 {
|
||||
let signed_tx = bitcoin_wallet
|
||||
.sign_and_finalize(self.tx_lock.clone().into())
|
||||
.await
|
||||
.context("failed to sign Bitcoin lock transaction")?;
|
||||
.context("Failed to sign Bitcoin lock transaction")?;
|
||||
|
||||
let _ = bitcoin_wallet.broadcast(signed_tx, "lock").await?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user