X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Foffers%2Fparse.rs;h=c85c2f326b02a816dd85ba285334112ad557c324;hb=caafcedf3fc40fc6253261218c25b254dd955a82;hp=42ed2e002d1f29b60169c86954f39cece3101647;hpb=2cae6f0ccb0e6b9e3d1c94359a906ddb4421be10;p=rust-lightning diff --git a/lightning/src/offers/parse.rs b/lightning/src/offers/parse.rs index 42ed2e00..c85c2f32 100644 --- a/lightning/src/offers/parse.rs +++ b/lightning/src/offers/parse.rs @@ -29,24 +29,24 @@ mod sealed { use bitcoin::bech32::{FromBase32, ToBase32}; use core::convert::TryFrom; use core::fmt; - use super::ParseError; + use super::Bolt12ParseError; use crate::prelude::*; /// Indicates a message can be encoded using bech32. - pub trait Bech32Encode: AsRef<[u8]> + TryFrom, Error=ParseError> { + pub trait Bech32Encode: AsRef<[u8]> + TryFrom, Error=Bolt12ParseError> { /// Human readable part of the message's bech32 encoding. const BECH32_HRP: &'static str; /// Parses a bech32-encoded message into a TLV stream. - fn from_bech32_str(s: &str) -> Result { + fn from_bech32_str(s: &str) -> Result { // Offer encoding may be split by '+' followed by optional whitespace. let encoded = match s.split('+').skip(1).next() { Some(_) => { for chunk in s.split('+') { let chunk = chunk.trim_start(); if chunk.is_empty() || chunk.contains(char::is_whitespace) { - return Err(ParseError::InvalidContinuation); + return Err(Bolt12ParseError::InvalidContinuation); } } @@ -59,7 +59,7 @@ mod sealed { let (hrp, data) = bech32::decode_without_checksum(encoded.as_ref())?; if hrp != Self::BECH32_HRP { - return Err(ParseError::InvalidBech32Hrp); + return Err(Bolt12ParseError::InvalidBech32Hrp); } let data = Vec::::from_base32(&data)?; @@ -116,10 +116,8 @@ impl TryFrom> for ParsedMessage { } /// Error when parsing a bech32 encoded message using [`str::parse`]. -/// -/// This is not exported to bindings users as its name conflicts with the BOLT 11 ParseError type. -#[derive(Debug, PartialEq)] -pub enum ParseError { +#[derive(Clone, Debug, PartialEq)] +pub enum Bolt12ParseError { /// The bech32 encoding does not conform to the BOLT 12 requirements for continuing messages /// across multiple parts (i.e., '+' followed by whitespace). InvalidContinuation, @@ -131,16 +129,14 @@ pub enum ParseError { /// The bech32 decoded string could not be decoded as the expected message type. Decode(DecodeError), /// The parsed message has invalid semantics. - InvalidSemantics(SemanticError), + InvalidSemantics(Bolt12SemanticError), /// The parsed message has an invalid signature. InvalidSignature(secp256k1::Error), } /// Error when interpreting a TLV stream as a specific type. -/// -/// This is not exported to bindings users as its name conflicts with the BOLT 11 SemanticError type. -#[derive(Debug, PartialEq)] -pub enum SemanticError { +#[derive(Clone, Debug, PartialEq)] +pub enum Bolt12SemanticError { /// The current [`std::time::SystemTime`] is past the offer or invoice's expiration. AlreadyExpired, /// The provided chain hash does not correspond to a supported chain. @@ -183,6 +179,8 @@ pub enum SemanticError { MissingPayerMetadata, /// A payer id was expected but was missing. MissingPayerId, + /// The payment id for a refund or request is already in use. + DuplicatePaymentId, /// Blinded paths were expected but were missing. MissingPaths, /// The blinded payinfo given does not match the number of blinded path hops. @@ -195,25 +193,25 @@ pub enum SemanticError { MissingSignature, } -impl From for ParseError { +impl From for Bolt12ParseError { fn from(error: bech32::Error) -> Self { Self::Bech32(error) } } -impl From for ParseError { +impl From for Bolt12ParseError { fn from(error: DecodeError) -> Self { Self::Decode(error) } } -impl From for ParseError { - fn from(error: SemanticError) -> Self { +impl From for Bolt12ParseError { + fn from(error: Bolt12SemanticError) -> Self { Self::InvalidSemantics(error) } } -impl From for ParseError { +impl From for Bolt12ParseError { fn from(error: secp256k1::Error) -> Self { Self::InvalidSignature(error) }