Allow get_shutdown_scriptpubkey and get_destination_script to return an error
[rust-lightning] / lightning / src / ln / onion_utils.rs
index 2916829f259ec58ee110b95fdf14fb16a702a401..b9f36bbd8dadf94592c9082a303ef378879a4819 100644 (file)
@@ -7,8 +7,8 @@
 // You may not use this file except in accordance with one or both of these
 // licenses.
 
-use crate::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
-use crate::ln::channelmanager::HTLCSource;
+use crate::ln::{PaymentHash, PaymentPreimage};
+use crate::ln::channelmanager::{HTLCSource, RecipientOnionFields};
 use crate::ln::msgs;
 use crate::ln::wire::Encode;
 use crate::routing::gossip::NetworkUpdate;
@@ -149,7 +149,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(path: &Vec<RouteHop>, total_msat: u64, payment_secret_option: &Option<PaymentSecret>, starting_htlc_offset: u32, keysend_preimage: &Option<PaymentPreimage>) -> Result<(Vec<msgs::OnionHopData>, u64, u32), APIError> {
+pub(super) fn build_onion_payloads(path: &Vec<RouteHop>, total_msat: u64, mut recipient_onion: RecipientOnionFields, starting_htlc_offset: u32, keysend_preimage: &Option<PaymentPreimage>) -> 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;
@@ -164,12 +164,13 @@ pub(super) fn build_onion_payloads(path: &Vec<RouteHop>, total_msat: u64, paymen
                res.insert(0, msgs::OnionHopData {
                        format: if idx == 0 {
                                msgs::OnionHopDataFormat::FinalNode {
-                                       payment_data: if let &Some(ref payment_secret) = payment_secret_option {
+                                       payment_data: if let Some(secret) = recipient_onion.payment_secret.take() {
                                                Some(msgs::FinalOnionHopData {
-                                                       payment_secret: payment_secret.clone(),
+                                                       payment_secret: secret,
                                                        total_msat,
                                                })
                                        } else { None },
+                                       payment_metadata: recipient_onion.payment_metadata.take(),
                                        keysend_preimage: *keysend_preimage,
                                }
                        } else {