X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fser_macros.rs;h=94990fcb8a17c8056dfd01d00b18db78d58e466f;hb=90c976394c3bb5726dbb6950256afcbc33ddf4a7;hp=816426b1133cb21a1e703129e6aecfa884f2c00c;hpb=daeb5a62914fef04d9d51e8d30ced9d6c1103b42;p=rust-lightning diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs index 816426b1..94990fcb 100644 --- a/lightning/src/util/ser_macros.rs +++ b/lightning/src/util/ser_macros.rs @@ -99,7 +99,7 @@ macro_rules! check_tlv_order { #[allow(unused_comparisons)] // Note that $type may be 0 making the second comparison always true let invalid_order = ($last_seen_type.is_none() || $last_seen_type.unwrap() < $type) && $typ.0 > $type; if invalid_order { - $field = $default; + $field = $default.into(); } }}; ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, required) => {{ @@ -128,7 +128,7 @@ macro_rules! check_missing_tlv { #[allow(unused_comparisons)] // Note that $type may be 0 making the second comparison always true let missing_req_type = $last_seen_type.is_none() || $last_seen_type.unwrap() < $type; if missing_req_type { - $field = $default; + $field = $default.into(); } }}; ($last_seen_type: expr, $type: expr, $field: ident, required) => {{ @@ -349,7 +349,7 @@ macro_rules! read_tlv_fields { macro_rules! init_tlv_based_struct_field { ($field: ident, (default_value, $default: expr)) => { - $field + $field.0.unwrap() }; ($field: ident, option) => { $field @@ -364,7 +364,7 @@ macro_rules! init_tlv_based_struct_field { macro_rules! init_tlv_field_var { ($field: ident, (default_value, $default: expr)) => { - let mut $field = $default; + let mut $field = ::util::ser::OptionDeserWrapper(None); }; ($field: ident, required) => { let mut $field = ::util::ser::OptionDeserWrapper(None); @@ -563,7 +563,7 @@ mod tests { use io::{self, Cursor}; use prelude::*; use ln::msgs::DecodeError; - use util::ser::{Writeable, HighZeroBytesDroppedVarInt, VecWriter}; + use util::ser::{Writeable, HighZeroBytesDroppedBigSize, VecWriter}; use bitcoin::secp256k1::PublicKey; // The BOLT TLV test cases don't include any tests which use our "required-value" logic since @@ -632,9 +632,9 @@ mod tests { } // BOLT TLV test cases - fn tlv_reader_n1(s: &[u8]) -> Result<(Option>, Option, Option<(PublicKey, u64, u64)>, Option), DecodeError> { + fn tlv_reader_n1(s: &[u8]) -> Result<(Option>, Option, Option<(PublicKey, u64, u64)>, Option), DecodeError> { let mut s = Cursor::new(s); - let mut tlv1: Option> = None; + let mut tlv1: Option> = None; let mut tlv2: Option = None; let mut tlv3: Option<(PublicKey, u64, u64)> = None; let mut tlv4: Option = None; @@ -765,11 +765,11 @@ mod tests { assert_eq!(stream.0, ::hex::decode("06fd00ff02abcd").unwrap()); stream.0.clear(); - encode_varint_length_prefixed_tlv!(&mut stream, {(0, 1u64, required), (42, None::, option), (0xff, HighZeroBytesDroppedVarInt(0u64), required)}); + encode_varint_length_prefixed_tlv!(&mut stream, {(0, 1u64, required), (42, None::, option), (0xff, HighZeroBytesDroppedBigSize(0u64), required)}); assert_eq!(stream.0, ::hex::decode("0e00080000000000000001fd00ff00").unwrap()); stream.0.clear(); - encode_varint_length_prefixed_tlv!(&mut stream, {(0, Some(1u64), option), (0xff, HighZeroBytesDroppedVarInt(0u64), required)}); + encode_varint_length_prefixed_tlv!(&mut stream, {(0, Some(1u64), option), (0xff, HighZeroBytesDroppedBigSize(0u64), required)}); assert_eq!(stream.0, ::hex::decode("0e00080000000000000001fd00ff00").unwrap()); Ok(())