Skip to content

Commit b4c28b8

Browse files
committed
remove some unused imports and implement Error trait for APIError
1 parent ce44696 commit b4c28b8

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

bindings/src/adaptors/primitives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'a> TryFrom<FFIRouteHop<'a>> for RouteHop {
176176

177177
fn try_from(value: FFIRouteHop<'a>) -> Result<Self, Self::Error> {
178178
Ok(RouteHop {
179-
pubkey: value.pubkey.clone().try_into()?,
179+
pubkey: value.pubkey.try_into()?,
180180
node_features: value.node_features.into(),
181181
short_channel_id: value.short_channel_id,
182182
channel_features: value.channel_features.into(),

bindings/src/channelmanager.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
convert::{TryFrom, TryInto},
2+
convert::{TryInto},
33
sync::Arc,
44
time::{SystemTime, UNIX_EPOCH}
55
};
@@ -8,20 +8,15 @@ use lightning::{
88
ln::channelmanager::{ChannelManager, PaymentHash},
99
chain::keysinterface::{KeysManager, InMemoryChannelKeys},
1010
util::config::UserConfig,
11-
ln::channelmonitor::{ManyChannelMonitor, SimpleManyChannelMonitor},
1211
ln::router::Route,
1312
};
1413

1514
use crate::{
1615
error::FFIResult,
1716
handle::{Out, Ref, HandleShared},
1817
adaptors::*,
19-
adaptors::primitives::{Seed, FFISha256dHash, FFIRoute},
20-
broadcaster::FFIBroadCasterHandle,
21-
chainwatcher::ChainWatchInterfaceHandle,
22-
channelmonitor::{FFIManyChannelMonitorHandle, FFIManyChannelMonitor},
23-
logger::FFILoggerHandle,
24-
fee_estimator::FeeEstimatorHandle
18+
adaptors::primitives::{FFISha256dHash, FFIRoute},
19+
channelmonitor::{FFIManyChannelMonitor},
2520
};
2621

2722
type FFIArcChannelManager = ChannelManager<InMemoryChannelKeys, Arc<FFIManyChannelMonitor>, Arc<FFIBroadCaster>, Arc<KeysManager>, Arc<FFIFeeEstimator>>;
@@ -104,7 +99,7 @@ ffi! {
10499
let payment_hash_ffi: &FFISha256dHash = unsafe_block!("We know it points to valid hash data" => payment_hash_ref.as_ref());
105100
let payment_hash: PaymentHash = payment_hash_ffi.clone().try_into()?;
106101
let route: Route = route_ffi.clone().try_into()?;
107-
chan_man.send_payment(route, payment_hash);
102+
chan_man.send_payment(route, payment_hash)?;
108103
FFIResult::ok()
109104
}
110105

bindings/src/channelmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33

44
use lightning::chain::transaction::OutPoint;
55
use lightning::chain::keysinterface::{InMemoryChannelKeys};
6-
use lightning::ln::channelmonitor::{SimpleManyChannelMonitor, HTLCUpdate, ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr};
6+
use lightning::ln::channelmonitor::{SimpleManyChannelMonitor};
77

88
use crate::adaptors::{FFIBroadCaster, FFIFeeEstimator, FFILogger, FFIChainWatchInterface, chain_watch_interface_fn, broadcaster_fn, fee_estimator_fn, ffilogger_fn};
99
use crate::error::FFIResult;

bindings/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::panic::{catch_unwind, UnwindSafe};
88
use std::any::Any;
99
use std::sync::atomic::{AtomicU32, Ordering};
1010

11+
use lightning::util::errors::APIError;
1112
use crate::utils::option_extensions::OptionMutExt;
1213

1314
static LAST_ERR_ID: AtomicU32 = AtomicU32::new(0);

lightning/src/util/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Error types live here.
22
33
use std::fmt;
4+
use bitcoin_hashes::core::fmt::{Formatter, Error};
45

56
/// Indicates an error on the client's part (usually some variant of attempting to use too-low or
67
/// too-high values)
@@ -50,6 +51,14 @@ impl fmt::Debug for APIError {
5051
}
5152
}
5253

54+
impl fmt::Display for APIError {
55+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
56+
<Self as fmt::Debug>::fmt(self, f)
57+
}
58+
}
59+
60+
impl std::error::Error for APIError {}
61+
5362
#[inline]
5463
pub(crate) fn get_onion_debug_field(error_code: u16) -> (&'static str, usize) {
5564
match error_code & 0xff {

0 commit comments

Comments
 (0)