Skip to content

Commit 263faf4

Browse files
committed
f - Move routing::Score parameterization from find_route to Router
1 parent e181887 commit 263faf4

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

lightning-invoice/src/payment.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
//! # }
6060
//! #
6161
//! # struct FakeRouter {};
62-
//! # impl Router for FakeRouter {
63-
//! # fn find_route<S: routing::Score>(
62+
//! # impl<S: routing::Score> Router<S> for FakeRouter {
63+
//! # fn find_route(
6464
//! # &self, payer: &PublicKey, params: &RouteParameters,
6565
//! # first_hops: Option<&[&ChannelDetails]>, scorer: &S
6666
//! # ) -> Result<Route, LightningError> { unimplemented!() }
@@ -134,7 +134,7 @@ use std::time::{Duration, SystemTime};
134134
pub struct InvoicePayer<P: Deref, R, S: Deref, L: Deref, E>
135135
where
136136
P::Target: Payer,
137-
R: Router,
137+
R: for <'a> Router<<<S as Deref>::Target as routing::LockableScore<'a>>::Locked>,
138138
S::Target: for <'a> routing::LockableScore<'a>,
139139
L::Target: Logger,
140140
E: EventHandler,
@@ -166,9 +166,9 @@ pub trait Payer {
166166
}
167167

168168
/// A trait defining behavior for routing an [`Invoice`] payment.
169-
pub trait Router {
169+
pub trait Router<S: routing::Score> {
170170
/// Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
171-
fn find_route<S: routing::Score>(
171+
fn find_route(
172172
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&ChannelDetails]>,
173173
scorer: &S
174174
) -> Result<Route, LightningError>;
@@ -192,7 +192,7 @@ pub enum PaymentError {
192192
impl<P: Deref, R, S: Deref, L: Deref, E> InvoicePayer<P, R, S, L, E>
193193
where
194194
P::Target: Payer,
195-
R: Router,
195+
R: for <'a> Router<<<S as Deref>::Target as routing::LockableScore<'a>>::Locked>,
196196
S::Target: for <'a> routing::LockableScore<'a>,
197197
L::Target: Logger,
198198
E: EventHandler,
@@ -308,7 +308,7 @@ fn has_expired(params: &RouteParameters) -> bool {
308308
impl<P: Deref, R, S: Deref, L: Deref, E> EventHandler for InvoicePayer<P, R, S, L, E>
309309
where
310310
P::Target: Payer,
311-
R: Router,
311+
R: for <'a> Router<<<S as Deref>::Target as routing::LockableScore<'a>>::Locked>,
312312
S::Target: for <'a> routing::LockableScore<'a>,
313313
L::Target: Logger,
314314
E: EventHandler,
@@ -949,8 +949,8 @@ mod tests {
949949
}
950950
}
951951

952-
impl Router for TestRouter {
953-
fn find_route<S: routing::Score>(
952+
impl<S: routing::Score> Router<S> for TestRouter {
953+
fn find_route(
954954
&self,
955955
_payer: &PublicKey,
956956
params: &RouteParameters,
@@ -965,8 +965,8 @@ mod tests {
965965

966966
struct FailingRouter;
967967

968-
impl Router for FailingRouter {
969-
fn find_route<S: routing::Score>(
968+
impl<S: routing::Score> Router<S> for FailingRouter {
969+
fn find_route(
970970
&self,
971971
_payer: &PublicKey,
972972
_params: &RouteParameters,

lightning-invoice/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ impl<G, L: Deref> DefaultRouter<G, L> where G: Deref<Target = NetworkGraph>, L::
109109
}
110110
}
111111

112-
impl<G, L: Deref> Router for DefaultRouter<G, L>
112+
impl<G, L: Deref, S: routing::Score> Router<S> for DefaultRouter<G, L>
113113
where G: Deref<Target = NetworkGraph>, L::Target: Logger {
114-
fn find_route<S: routing::Score>(
114+
fn find_route(
115115
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&ChannelDetails]>,
116116
scorer: &S
117117
) -> Result<Route, LightningError> {

0 commit comments

Comments
 (0)