X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fonion_utils.rs;h=4886168dd16cc277adfd536fcedbca83ba03ac1a;hb=0dfcacd22c23f69b6526c9c6507d21427a2b7ccb;hp=8feef1697af40ad33032afe23b7bf5f77e8a6b21;hpb=dba0709b084cd3c1f50f95afed5111e5f8afda39;p=rust-lightning diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 8feef169..4886168d 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -7,10 +7,10 @@ // You may not use this file except in accordance with one or both of these // licenses. -use ln::channelmanager::{PaymentHash, PaymentSecret, HTLCSource}; +use ln::{PaymentHash, PaymentPreimage, PaymentSecret}; +use ln::channelmanager::HTLCSource; use ln::msgs; use routing::router::RouteHop; -use util::byte_utils; use util::chacha20::ChaCha20; use util::errors::{self, APIError}; use util::ser::{Readable, Writeable, LengthCalculatingWriter}; @@ -26,8 +26,10 @@ use bitcoin::secp256k1::Secp256k1; use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1; -use std::io::Cursor; -use std::ops::Deref; +use prelude::*; +use io::Cursor; +use core::convert::TryInto; +use core::ops::Deref; pub(super) struct OnionKeys { #[cfg(test)] @@ -117,7 +119,7 @@ pub(super) fn construct_onion_keys(secp_ctx: &Secp256k1, total_msat: u64, payment_secret_option: &Option, starting_htlc_offset: u32) -> Result<(Vec, u64, u32), APIError> { +pub(super) fn build_onion_payloads(path: &Vec, total_msat: u64, payment_secret_option: &Option, starting_htlc_offset: u32, keysend_preimage: &Option) -> Result<(Vec, u64, u32), APIError> { let mut cur_value_msat = 0u64; let mut cur_cltv = starting_htlc_offset; let mut last_short_channel_id = 0; @@ -139,6 +141,7 @@ pub(super) fn build_onion_payloads(path: &Vec, total_msat: u64, paymen total_msat, }) } else { None }, + keysend_preimage: *keysend_preimage, } } else { msgs::OnionHopDataFormat::NonFinalNode { @@ -365,7 +368,7 @@ pub(super) fn process_onion_failure(secp_ctx: & const NODE: u16 = 0x2000; const UPDATE: u16 = 0x1000; - let error_code = byte_utils::slice_to_be16(&error_code_slice); + let error_code = u16::from_be_bytes(error_code_slice.try_into().expect("len is 2")); error_code_ret = Some(error_code); error_packet_ret = Some(err_packet.failuremsg[2..].to_vec()); @@ -392,7 +395,7 @@ pub(super) fn process_onion_failure(secp_ctx: & } else if error_code & UPDATE == UPDATE { if let Some(update_len_slice) = err_packet.failuremsg.get(debug_field_size+2..debug_field_size+4) { - let update_len = byte_utils::slice_to_be16(&update_len_slice) as usize; + let update_len = u16::from_be_bytes(update_len_slice.try_into().expect("len is 2")) as usize; if let Some(update_slice) = err_packet.failuremsg.get(debug_field_size + 4..debug_field_size + 4 + update_len) { if let Ok(chan_update) = msgs::ChannelUpdate::read(&mut Cursor::new(&update_slice)) { // if channel_update should NOT have caused the failure: @@ -477,7 +480,9 @@ pub(super) fn process_onion_failure(secp_ctx: & #[cfg(test)] mod tests { - use ln::channelmanager::PaymentHash; + use io; + use prelude::*; + use ln::PaymentHash; use ln::features::{ChannelFeatures, NodeFeatures}; use routing::router::{Route, RouteHop}; use ln::msgs; @@ -644,7 +649,7 @@ mod tests { } } impl Writeable for RawOnionHopData { - fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { + fn write(&self, writer: &mut W) -> Result<(), io::Error> { writer.write_all(&self.data[..]) } }