File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -78,17 +78,26 @@ pub struct Route {
78
78
pub payee : Option < Payee > ,
79
79
}
80
80
81
+ pub ( crate ) trait RoutePath {
82
+ /// Gets the fees for a given path, excluding any excess paid to the recipient.
83
+ fn get_path_fees ( & self ) -> u64 ;
84
+ }
85
+ impl RoutePath for Vec < RouteHop > {
86
+ fn get_path_fees ( & self ) -> u64 {
87
+ // Do not count last hop of each path since that's the full value of the payment
88
+ self . split_last ( ) . map ( |( _, path_prefix) | path_prefix) . unwrap_or ( & [ ] )
89
+ . iter ( ) . map ( |hop| & hop. fee_msat )
90
+ . sum ( )
91
+ }
92
+ }
93
+
81
94
impl Route {
82
95
/// Returns the total amount of fees paid on this [`Route`].
83
96
///
84
97
/// This doesn't include any extra payment made to the recipient, which can happen in excess of
85
98
/// the amount passed to [`find_route`]'s `params.final_value_msat`.
86
99
pub fn get_total_fees ( & self ) -> u64 {
87
- // Do not count last hop of each path since that's the full value of the payment
88
- return self . paths . iter ( )
89
- . flat_map ( |path| path. split_last ( ) . map ( |( _, path_prefix) | path_prefix) . unwrap_or ( & [ ] ) )
90
- . map ( |hop| & hop. fee_msat )
91
- . sum ( ) ;
100
+ self . paths . iter ( ) . map ( |path| path. get_path_fees ( ) ) . sum ( )
92
101
}
93
102
94
103
/// Returns the total amount paid on this [`Route`], excluding the fees.
You can’t perform that action at this time.
0 commit comments