Skip to content

Commit e0a772a

Browse files
authored
Merge pull request #290 from mojoX911/last-unwraps
Last unwraps
2 parents f010232 + 64fd3ec commit e0a772a

File tree

20 files changed

+367
-394
lines changed

20 files changed

+367
-394
lines changed

src/error.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
33
use std::error::Error;
44

5-
use bitcoin::Amount;
6-
7-
use crate::protocol::error::ContractError;
8-
95
/// Includes all network-related errors.
106
#[derive(Debug)]
117
pub enum NetError {
@@ -40,20 +36,3 @@ impl From<serde_cbor::Error> for NetError {
4036
Self::Cbor(value)
4137
}
4238
}
43-
44-
/// Includes all Protocol-level errors.
45-
#[derive(Debug)]
46-
pub enum ProtocolError {
47-
WrongMessage { expected: String, received: String },
48-
WrongNumOfSigs { expected: usize, received: usize },
49-
WrongNumOfContractTxs { expected: usize, received: usize },
50-
WrongNumOfPrivkeys { expected: usize, received: usize },
51-
IncorrectFundingAmount { expected: Amount, found: Amount },
52-
Contract(ContractError),
53-
}
54-
55-
impl From<ContractError> for ProtocolError {
56-
fn from(value: ContractError) -> Self {
57-
Self::Contract(value)
58-
}
59-
}

src/maker/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl Maker {
288288

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

293293
if !self.wallet.read()?.does_prevout_match_cached_contract(
294294
&(OutPoint {

src/maker/error.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ use std::sync::{MutexGuard, PoisonError, RwLockReadGuard, RwLockWriteGuard};
44

55
use bitcoin::secp256k1;
66

7-
use crate::{
8-
error::{NetError, ProtocolError},
9-
protocol::error::ContractError,
10-
wallet::WalletError,
11-
};
7+
use crate::{error::NetError, protocol::error::ProtocolError, wallet::WalletError};
128

139
use super::MakerBehavior;
1410

@@ -62,9 +58,9 @@ impl From<secp256k1::Error> for MakerError {
6258
}
6359
}
6460

65-
impl From<ContractError> for MakerError {
66-
fn from(value: ContractError) -> Self {
67-
Self::Protocol(ProtocolError::from(value))
61+
impl From<ProtocolError> for MakerError {
62+
fn from(value: ProtocolError) -> Self {
63+
Self::Protocol(value)
6864
}
6965
}
7066

@@ -85,9 +81,3 @@ impl From<NetError> for MakerError {
8581
Self::Net(value)
8682
}
8783
}
88-
89-
impl From<ProtocolError> for MakerError {
90-
fn from(value: ProtocolError) -> Self {
91-
Self::Protocol(value)
92-
}
93-
}

src/maker/handlers.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use bitcoin::{
1717
use bitcoind::bitcoincore_rpc::RpcApi;
1818

1919
use crate::{
20-
error::ProtocolError,
2120
maker::api::recover_from_swap,
2221
protocol::{
22+
error::ProtocolError,
2323
messages::{MakerHello, MultisigPrivkey, PrivKeyHandover},
2424
Hash160,
2525
},
@@ -301,7 +301,7 @@ impl Maker {
301301
funding_output.value,
302302
&funding_info.contract_redeemscript,
303303
Amount::from_sat(message.next_fee_rate),
304-
);
304+
)?;
305305

306306
let (tweakable_privkey, _) = self.wallet.read()?.get_tweakable_keypair()?;
307307
let multisig_privkey =
@@ -345,15 +345,18 @@ impl Maker {
345345
}
346346

347347
// Calculate output amounts for the next hop
348-
let incoming_amount = message.confirmed_funding_txes.iter().fold(0u64, |acc, fi| {
349-
let index = find_funding_output_index(fi).unwrap();
350-
let txout = fi
351-
.funding_tx
352-
.output
353-
.get(index as usize)
354-
.expect("output at index expected");
355-
acc + txout.value.to_sat()
356-
});
348+
let incoming_amount = message
349+
.confirmed_funding_txes
350+
.iter()
351+
.try_fold(0u64, |acc, fi| {
352+
let index = find_funding_output_index(fi)?;
353+
let txout = fi
354+
.funding_tx
355+
.output
356+
.get(index as usize)
357+
.expect("output at index expected");
358+
Ok::<_, MakerError>(acc + txout.value.to_sat())
359+
})?;
357360

358361
let calc_coinswap_fees = calculate_coinswap_fee(
359362
self.config.absolute_fee_sats,

src/maker/rpc/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn handle_request(maker: &Arc<Maker>, socket: &mut TcpStream) -> Result<(), Make
152152
}
153153
RpcMsgReq::GetTorAddress => {
154154
let path = get_maker_dir().join("tor");
155-
let resp = RpcMsgResp::GetTorAddressResp(get_tor_addrs(&path));
155+
let resp = RpcMsgResp::GetTorAddressResp(get_tor_addrs(&path)?);
156156
if let Err(e) = send_message(socket, &resp) {
157157
log::info!("Error sending RPC response {:?}", e);
158158
};

src/market/directory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ pub fn start_directory_server(directory: Arc<DirectoryServer>) -> Result<(), Dir
249249

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

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

254254
log::info!(
255255
"Directory Server is listening at {}:{}",

0 commit comments

Comments
 (0)