Impl Base AMP in the receive pipeline and expose payment_secret
[rust-lightning] / lightning / src / ln / onion_utils.rs
index a97621045370366069bdb5e9b2a3d4ebb68dffff..ebea1334a8489bc81000b0df1e272ad4557fab73 100644 (file)
@@ -1,4 +1,4 @@
-use ln::channelmanager::{PaymentHash, HTLCSource};
+use ln::channelmanager::{PaymentHash, PaymentSecret, HTLCSource};
 use ln::msgs;
 use ln::router::{Route,RouteHop};
 use util::byte_utils;
@@ -108,7 +108,7 @@ pub(super) fn construct_onion_keys<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T
 }
 
 /// returns the hop data, as well as the first-hop value_msat and CLTV value we should send.
-pub(super) fn build_onion_payloads(route: &Route, starting_htlc_offset: u32) -> Result<(Vec<msgs::OnionHopData>, u64, u32), APIError> {
+pub(super) fn build_onion_payloads(route: &Route, payment_secret_option: &Option<PaymentSecret>, starting_htlc_offset: u32) -> Result<(Vec<msgs::OnionHopData>, u64, u32), APIError> {
        let mut cur_value_msat = 0u64;
        let mut cur_cltv = starting_htlc_offset;
        let mut last_short_channel_id = 0;
@@ -124,7 +124,12 @@ pub(super) fn build_onion_payloads(route: &Route, starting_htlc_offset: u32) ->
                        format: if hop.node_features.supports_variable_length_onion() {
                                if idx == 0 {
                                        msgs::OnionHopDataFormat::FinalNode {
-                                               payment_data: None,
+                                               payment_data: if let &Some(ref payment_secret) = payment_secret_option {
+                                                       Some(msgs::FinalOnionHopData {
+                                                               payment_secret: payment_secret.clone(),
+                                                               total_msat: hop.fee_msat,
+                                                       })
+                                               } else { None },
                                        }
                                } else {
                                        msgs::OnionHopDataFormat::NonFinalNode {