File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
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
+ self . split_last ( ) . map ( |( _, path_prefix) | path_prefix) . unwrap_or ( & [ ] )
88
+ . iter ( ) . map ( |hop| & hop. fee_msat )
89
+ . sum ( )
90
+ }
91
+ }
92
+
81
93
impl Route {
82
94
/// Returns the total amount of fees paid on this [`Route`].
83
95
///
84
96
/// This doesn't include any extra payment made to the recipient, which can happen in excess of
85
97
/// the amount passed to [`find_route`]'s `params.final_value_msat`.
86
98
pub fn get_total_fees ( & self ) -> u64 {
87
99
// 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