X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-invoice%2Fsrc%2Fde.rs;h=ab9fd9cb2bc21446920360759feefec87291f774;hb=9f8e832c7b2a48f6cbc58165b16b6f79e9ca329c;hp=5de2b038e8b2d29a25df42705d5d7d378009a7fb;hpb=ce5a9f528a96d1c10a992a1e89a27d58e5aecf86;p=rust-lightning diff --git a/lightning-invoice/src/de.rs b/lightning-invoice/src/de.rs index 5de2b038..ab9fd9cb 100644 --- a/lightning-invoice/src/de.rs +++ b/lightning-invoice/src/de.rs @@ -6,23 +6,21 @@ use core::num::ParseIntError; use core::str; use core::str::FromStr; -use bech32; use bech32::{u5, FromBase32}; use bitcoin_hashes::Hash; use bitcoin_hashes::sha256; use crate::prelude::*; use lightning::ln::PaymentSecret; -use lightning::routing::network_graph::RoutingFees; +use lightning::routing::gossip::RoutingFees; use lightning::routing::router::{RouteHint, RouteHintHop}; use num_traits::{CheckedAdd, CheckedMul}; -use secp256k1; -use secp256k1::recovery::{RecoveryId, RecoverableSignature}; -use secp256k1::key::PublicKey; +use secp256k1::ecdsa::{RecoveryId, RecoverableSignature}; +use secp256k1::PublicKey; -use super::{Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiry, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp, +use super::{Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiryDelta, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp, SemanticError, PrivateRoute, ParseError, ParseOrSemanticError, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawInvoice, constants, SignedRawInvoice, RawDataPart, InvoiceFeatures}; @@ -197,7 +195,7 @@ impl FromStr for SiPrefix { type Err = ParseError; fn from_str(currency_prefix: &str) -> Result { - use SiPrefix::*; + use crate::SiPrefix::*; match currency_prefix { "m" => Ok(Milli), "u" => Ok(Micro), @@ -323,9 +321,9 @@ impl FromStr for RawHrp { }; Ok(RawHrp { - currency: currency, + currency, raw_amount: amount, - si_prefix: si_prefix, + si_prefix, }) } } @@ -342,7 +340,7 @@ impl FromBase32 for RawDataPart { let tagged = parse_tagged_parts(&data[7..])?; Ok(RawDataPart { - timestamp: timestamp, + timestamp, tagged_fields: tagged, }) } @@ -451,8 +449,8 @@ impl FromBase32 for TaggedField { Ok(TaggedField::DescriptionHash(Sha256::from_base32(field_data)?)), constants::TAG_EXPIRY_TIME => Ok(TaggedField::ExpiryTime(ExpiryTime::from_base32(field_data)?)), - constants::TAG_MIN_FINAL_CLTV_EXPIRY => - Ok(TaggedField::MinFinalCltvExpiry(MinFinalCltvExpiry::from_base32(field_data)?)), + constants::TAG_MIN_FINAL_CLTV_EXPIRY_DELTA => + Ok(TaggedField::MinFinalCltvExpiryDelta(MinFinalCltvExpiryDelta::from_base32(field_data)?)), constants::TAG_FALLBACK => Ok(TaggedField::Fallback(Fallback::from_base32(field_data)?)), constants::TAG_PRIVATE_ROUTE => @@ -515,7 +513,7 @@ impl FromBase32 for ExpiryTime { fn from_base32(field_data: &[u5]) -> Result { match parse_int_be::(field_data, 32) - .map(|t| ExpiryTime::from_seconds(t)) + .map(ExpiryTime::from_seconds) { Some(t) => Ok(t), None => Err(ParseError::IntegerOverflowError), @@ -523,13 +521,13 @@ impl FromBase32 for ExpiryTime { } } -impl FromBase32 for MinFinalCltvExpiry { +impl FromBase32 for MinFinalCltvExpiryDelta { type Err = ParseError; - fn from_base32(field_data: &[u5]) -> Result { + fn from_base32(field_data: &[u5]) -> Result { let expiry = parse_int_be::(field_data, 32); if let Some(expiry) = expiry { - Ok(MinFinalCltvExpiry(expiry)) + Ok(MinFinalCltvExpiryDelta(expiry)) } else { Err(ParseError::IntegerOverflowError) } @@ -540,7 +538,7 @@ impl FromBase32 for Fallback { type Err = ParseError; fn from_base32(field_data: &[u5]) -> Result { - if field_data.len() < 1 { + if field_data.is_empty() { return Err(ParseError::UnexpectedEndOfTaggedFields); } @@ -554,7 +552,7 @@ impl FromBase32 for Fallback { } Ok(Fallback::SegWitProgram { - version: version, + version, program: bytes }) }, @@ -715,7 +713,7 @@ impl From for ParseOrSemanticError { } } -impl From<::SemanticError> for ParseOrSemanticError { +impl From for ParseOrSemanticError { fn from(e: SemanticError) -> Self { ParseOrSemanticError::SemanticError(e) } @@ -723,7 +721,7 @@ impl From<::SemanticError> for ParseOrSemanticError { #[cfg(test)] mod test { - use de::ParseError; + use crate::de::ParseError; use secp256k1::PublicKey; use bech32::u5; use bitcoin_hashes::hex::FromHex; @@ -749,7 +747,7 @@ mod test { #[test] fn test_parse_currency_prefix() { - use Currency; + use crate::Currency; assert_eq!("bc".parse::(), Ok(Currency::Bitcoin)); assert_eq!("tb".parse::(), Ok(Currency::BitcoinTestnet)); @@ -761,7 +759,7 @@ mod test { #[test] fn test_parse_int_from_bytes_be() { - use de::parse_int_be; + use crate::de::parse_int_be; assert_eq!(parse_int_be::(&[1, 2, 3, 4], 256), Some(16909060)); assert_eq!(parse_int_be::(&[1, 3], 32), Some(35)); @@ -771,7 +769,7 @@ mod test { #[test] fn test_parse_sha256_hash() { - use Sha256; + use crate::Sha256; use bech32::FromBase32; let input = from_bech32( @@ -794,7 +792,7 @@ mod test { #[test] fn test_parse_description() { - use ::Description; + use crate::Description; use bech32::FromBase32; let input = from_bech32("xysxxatsyp3k7enxv4js".as_bytes()); @@ -804,7 +802,7 @@ mod test { #[test] fn test_parse_payee_pub_key() { - use ::PayeePubKey; + use crate::PayeePubKey; use bech32::FromBase32; let input = from_bech32("q0n326hr8v9zprg8gsvezcch06gfaqqhde2aj730yg0durunfhv66".as_bytes()); @@ -828,7 +826,7 @@ mod test { #[test] fn test_parse_expiry_time() { - use ::ExpiryTime; + use crate::ExpiryTime; use bech32::FromBase32; let input = from_bech32("pu".as_bytes()); @@ -840,19 +838,19 @@ mod test { } #[test] - fn test_parse_min_final_cltv_expiry() { - use ::MinFinalCltvExpiry; + fn test_parse_min_final_cltv_expiry_delta() { + use crate::MinFinalCltvExpiryDelta; use bech32::FromBase32; let input = from_bech32("pr".as_bytes()); - let expected = Ok(MinFinalCltvExpiry(35)); + let expected = Ok(MinFinalCltvExpiryDelta(35)); - assert_eq!(MinFinalCltvExpiry::from_base32(&input), expected); + assert_eq!(MinFinalCltvExpiryDelta::from_base32(&input), expected); } #[test] fn test_parse_fallback() { - use Fallback; + use crate::Fallback; use bech32::FromBase32; let cases = vec![ @@ -909,11 +907,11 @@ mod test { #[test] fn test_parse_route() { - use lightning::routing::network_graph::RoutingFees; + use lightning::routing::gossip::RoutingFees; use lightning::routing::router::{RouteHint, RouteHintHop}; - use ::PrivateRoute; + use crate::PrivateRoute; use bech32::FromBase32; - use de::parse_int_be; + use crate::de::parse_int_be; let input = from_bech32( "q20q82gphp2nflc7jtzrcazrra7wwgzxqc8u7754cdlpfrmccae92qgzqvzq2ps8pqqqqqqpqqqqq9qqqvpeuqa\ @@ -967,9 +965,9 @@ mod test { #[test] fn test_payment_secret_and_features_de_and_ser() { use lightning::ln::features::InvoiceFeatures; - use secp256k1::recovery::{RecoveryId, RecoverableSignature}; - use TaggedField::*; - use {SiPrefix, SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, + use secp256k1::ecdsa::{RecoveryId, RecoverableSignature}; + use crate::TaggedField::*; + use crate::{SiPrefix, SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp}; // Feature bits 9, 15, and 99 are set. @@ -988,8 +986,8 @@ mod test { PaymentHash(Sha256(sha256::Hash::from_hex( "0001020304050607080900010203040506070809000102030405060708090102" ).unwrap())).into(), - Description(::Description::new("coffee beans".to_owned()).unwrap()).into(), - PaymentSecret(::PaymentSecret([17; 32])).into(), + Description(crate::Description::new("coffee beans".to_owned()).unwrap()).into(), + PaymentSecret(crate::PaymentSecret([17; 32])).into(), Features(expected_features).into()]} }, hash: [0xb1, 0x96, 0x46, 0xc3, 0xbc, 0x56, 0x76, 0x1d, 0x20, 0x65, 0x6e, 0x0e, 0x32, @@ -1013,9 +1011,9 @@ mod test { #[test] fn test_raw_signed_invoice_deserialization() { - use TaggedField::*; - use secp256k1::recovery::{RecoveryId, RecoverableSignature}; - use {SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256, + use crate::TaggedField::*; + use secp256k1::ecdsa::{RecoveryId, RecoverableSignature}; + use crate::{SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp}; assert_eq!( @@ -1036,7 +1034,7 @@ mod test { "0001020304050607080900010203040506070809000102030405060708090102" ).unwrap())).into(), Description( - ::Description::new( + crate::Description::new( "Please consider supporting this project".to_owned() ).unwrap() ).into(),