projects
/
rust-lightning
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
`rustfmt`: `lightning-transaction-sync/tests/integration_tests.rs`
[rust-lightning]
/
lightning-invoice
/
src
/
de.rs
diff --git
a/lightning-invoice/src/de.rs
b/lightning-invoice/src/de.rs
index 56e5c53ba1f281e01fb274914b108b0f026ff660..bd9f4a5f6dedcf2b15502f821a6951a92ec5e99f 100644
(file)
--- a/
lightning-invoice/src/de.rs
+++ b/
lightning-invoice/src/de.rs
@@
-10,12
+10,11
@@
use core::str::FromStr;
use bech32::{u5, FromBase32};
use bech32::{u5, FromBase32};
-use bitcoin::{PubkeyHash, ScriptHash};
-use bitcoin::address::WitnessVersion;
+use bitcoin::{PubkeyHash, ScriptHash, WitnessVersion};
use bitcoin::hashes::Hash;
use bitcoin::hashes::sha256;
use crate::prelude::*;
use bitcoin::hashes::Hash;
use bitcoin::hashes::sha256;
use crate::prelude::*;
-use lightning::ln::PaymentSecret;
+use lightning::ln::
types::
PaymentSecret;
use lightning::routing::gossip::RoutingFees;
use lightning::routing::router::{RouteHint, RouteHintHop};
use lightning::routing::gossip::RoutingFees;
use lightning::routing::router::{RouteHint, RouteHintHop};
@@
-43,7
+42,11
@@
mod hrp_sm {
}
impl States {
}
impl States {
- fn next_state(&self, read_symbol: char) -> Result<States, super::Bolt11ParseError> {
+ fn next_state(&self, read_byte: u8) -> Result<States, super::Bolt11ParseError> {
+ let read_symbol = match char::from_u32(read_byte.into()) {
+ Some(symb) if symb.is_ascii() => symb,
+ _ => return Err(super::Bolt11ParseError::MalformedHRP),
+ };
match *self {
States::Start => {
if read_symbol == 'l' {
match *self {
States::Start => {
if read_symbol == 'l' {
@@
-119,7
+122,7
@@
mod hrp_sm {
*range = Some(new_range);
}
*range = Some(new_range);
}
- fn step(&mut self, c:
char
) -> Result<(), super::Bolt11ParseError> {
+ fn step(&mut self, c:
u8
) -> Result<(), super::Bolt11ParseError> {
let next_state = self.state.next_state(c)?;
match next_state {
States::ParseCurrencyPrefix => {
let next_state = self.state.next_state(c)?;
match next_state {
States::ParseCurrencyPrefix => {
@@
-158,7
+161,7
@@
mod hrp_sm {
pub fn parse_hrp(input: &str) -> Result<(&str, &str, &str), super::Bolt11ParseError> {
let mut sm = StateMachine::new();
pub fn parse_hrp(input: &str) -> Result<(&str, &str, &str), super::Bolt11ParseError> {
let mut sm = StateMachine::new();
- for c in input.
char
s() {
+ for c in input.
byte
s() {
sm.step(c)?;
}
sm.step(c)?;
}
@@
-547,10
+550,10
@@
impl FromBase32 for Fallback {
return Err(Bolt11ParseError::UnexpectedEndOfTaggedFields);
}
return Err(Bolt11ParseError::UnexpectedEndOfTaggedFields);
}
- let version = field_data[0];
+ let version = field_data[0]
.to_u8()
;
let bytes = Vec::<u8>::from_base32(&field_data[1..])?;
let bytes = Vec::<u8>::from_base32(&field_data[1..])?;
- match version
.to_u8()
{
+ match version {
0..=16 => {
if bytes.len() < 2 || bytes.len() > 40 {
return Err(Bolt11ParseError::InvalidSegWitProgramLength);
0..=16 => {
if bytes.len() < 2 || bytes.len() > 40 {
return Err(Bolt11ParseError::InvalidSegWitProgramLength);
@@
-564,14
+567,14
@@
impl FromBase32 for Fallback {
17 => {
let pkh = match PubkeyHash::from_slice(&bytes) {
Ok(pkh) => pkh,
17 => {
let pkh = match PubkeyHash::from_slice(&bytes) {
Ok(pkh) => pkh,
- Err(
bitcoin::hashes::Error::InvalidLength(_, _)
) => return Err(Bolt11ParseError::InvalidPubKeyHashLength),
+ Err(
_
) => return Err(Bolt11ParseError::InvalidPubKeyHashLength),
};
Ok(Fallback::PubKeyHash(pkh))
}
18 => {
let sh = match ScriptHash::from_slice(&bytes) {
Ok(sh) => sh,
};
Ok(Fallback::PubKeyHash(pkh))
}
18 => {
let sh = match ScriptHash::from_slice(&bytes) {
Ok(sh) => sh,
- Err(
bitcoin::hashes::Error::InvalidLength(_, _)
) => return Err(Bolt11ParseError::InvalidScriptHashLength),
+ Err(
_
) => return Err(Bolt11ParseError::InvalidScriptHashLength),
};
Ok(Fallback::ScriptHash(sh))
}
};
Ok(Fallback::ScriptHash(sh))
}
@@
-858,8
+861,7
@@
mod test {
fn test_parse_fallback() {
use crate::Fallback;
use bech32::FromBase32;
fn test_parse_fallback() {
use crate::Fallback;
use bech32::FromBase32;
- use bitcoin::{PubkeyHash, ScriptHash};
- use bitcoin::address::WitnessVersion;
+ use bitcoin::{PubkeyHash, ScriptHash, WitnessVersion};
use bitcoin::hashes::Hash;
let cases = vec![
use bitcoin::hashes::Hash;
let cases = vec![