Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

use std::error::Error;

use bitcoin::Amount;

use crate::protocol::error::ContractError;

/// Includes all network-related errors.
#[derive(Debug)]
pub enum NetError {
Expand Down Expand Up @@ -40,20 +36,3 @@ impl From<serde_cbor::Error> for NetError {
Self::Cbor(value)
}
}

/// Includes all Protocol-level errors.
#[derive(Debug)]
pub enum ProtocolError {
WrongMessage { expected: String, received: String },
WrongNumOfSigs { expected: usize, received: usize },
WrongNumOfContractTxs { expected: usize, received: usize },
WrongNumOfPrivkeys { expected: usize, received: usize },
IncorrectFundingAmount { expected: Amount, found: Amount },
Contract(ContractError),
}

impl From<ContractError> for ProtocolError {
fn from(value: ContractError) -> Self {
Self::Contract(value)
}
}
2 changes: 1 addition & 1 deletion src/maker/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl Maker {

//check that the provided contract matches the scriptpubkey from the
//cache which was populated when the ReqContractSigsForSender message arrived
let contract_spk = redeemscript_to_scriptpubkey(&funding_info.contract_redeemscript);
let contract_spk = redeemscript_to_scriptpubkey(&funding_info.contract_redeemscript)?;

if !self.wallet.read()?.does_prevout_match_cached_contract(
&(OutPoint {
Expand Down
18 changes: 4 additions & 14 deletions src/maker/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

use bitcoin::secp256k1;

use crate::{
error::{NetError, ProtocolError},
protocol::error::ContractError,
wallet::WalletError,
};
use crate::{error::NetError, protocol::error::ProtocolError, wallet::WalletError};

use super::MakerBehavior;

Expand Down Expand Up @@ -62,9 +58,9 @@
}
}

impl From<ContractError> for MakerError {
fn from(value: ContractError) -> Self {
Self::Protocol(ProtocolError::from(value))
impl From<ProtocolError> for MakerError {
fn from(value: ProtocolError) -> Self {
Self::Protocol(value)

Check warning on line 63 in src/maker/error.rs

View check run for this annotation

Codecov / codecov/patch

src/maker/error.rs#L62-L63

Added lines #L62 - L63 were not covered by tests
}
}

Expand All @@ -85,9 +81,3 @@
Self::Net(value)
}
}

impl From<ProtocolError> for MakerError {
fn from(value: ProtocolError) -> Self {
Self::Protocol(value)
}
}
25 changes: 14 additions & 11 deletions src/maker/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use bitcoin::{
use bitcoind::bitcoincore_rpc::RpcApi;

use crate::{
error::ProtocolError,
maker::api::recover_from_swap,
protocol::{
error::ProtocolError,
messages::{MakerHello, MultisigPrivkey, PrivKeyHandover},
Hash160,
},
Expand Down Expand Up @@ -301,7 +301,7 @@ impl Maker {
funding_output.value,
&funding_info.contract_redeemscript,
Amount::from_sat(message.next_fee_rate),
);
)?;

let (tweakable_privkey, _) = self.wallet.read()?.get_tweakable_keypair()?;
let multisig_privkey =
Expand Down Expand Up @@ -345,15 +345,18 @@ impl Maker {
}

// Calculate output amounts for the next hop
let incoming_amount = message.confirmed_funding_txes.iter().fold(0u64, |acc, fi| {
let index = find_funding_output_index(fi).unwrap();
let txout = fi
.funding_tx
.output
.get(index as usize)
.expect("output at index expected");
acc + txout.value.to_sat()
});
let incoming_amount = message
.confirmed_funding_txes
.iter()
.try_fold(0u64, |acc, fi| {
let index = find_funding_output_index(fi)?;
let txout = fi
.funding_tx
.output
.get(index as usize)
.expect("output at index expected");
Ok::<_, MakerError>(acc + txout.value.to_sat())
})?;

let calc_coinswap_fees = calculate_coinswap_fee(
self.config.absolute_fee_sats,
Expand Down
2 changes: 1 addition & 1 deletion src/maker/rpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
}
RpcMsgReq::GetTorAddress => {
let path = get_maker_dir().join("tor");
let resp = RpcMsgResp::GetTorAddressResp(get_tor_addrs(&path));
let resp = RpcMsgResp::GetTorAddressResp(get_tor_addrs(&path)?);

Check warning on line 155 in src/maker/rpc/server.rs

View check run for this annotation

Codecov / codecov/patch

src/maker/rpc/server.rs#L155

Added line #L155 was not covered by tests
if let Err(e) = send_message(socket, &resp) {
log::info!("Error sending RPC response {:?}", e);
};
Expand Down
2 changes: 1 addition & 1 deletion src/market/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ pub fn start_directory_server(directory: Arc<DirectoryServer>) -> Result<(), Dir

log::info!("Directory tor is instantiated");

let onion_addr = get_tor_addrs(&PathBuf::from("/tmp/tor-rust-directory"));
let onion_addr = get_tor_addrs(&PathBuf::from("/tmp/tor-rust-directory"))?;

log::info!(
"Directory Server is listening at {}:{}",
Expand Down
Loading
Loading