use bitcoin_hashes::Hash;
use bitcoin_hashes::sha256;
+use lightning::ln::channelmanager::PaymentSecret;
use lightning::routing::network_graph::RoutingFees;
use lightning::routing::router::RouteHintHop;
}
}
-impl FromBase32 for PaymentSecret {
- type Err = ParseError;
-
- fn from_base32(field_data: &[u5]) -> Result<PaymentSecret, ParseError> {
- if field_data.len() != 52 {
- Err(ParseError::Skip)
- } else {
- let data_bytes = Vec::<u8>::from_base32(field_data)?;
- let mut payment_secret = [0; 32];
- payment_secret.copy_from_slice(&data_bytes);
- Ok(PaymentSecret(payment_secret))
- }
- }
-}
-
impl FromBase32 for ExpiryTime {
type Err = ParseError;
use bitcoin_hashes::Hash;
use bitcoin_hashes::sha256;
use lightning::ln::features::InvoiceFeatures;
+use lightning::ln::channelmanager::PaymentSecret;
#[cfg(any(doc, test))]
use lightning::routing::network_graph::RoutingFees;
use lightning::routing::router::RouteHintHop;
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct PayeePubKey(pub PublicKey);
-/// 256-bit payment secret
-#[derive(Eq, PartialEq, Debug, Clone)]
-pub struct PaymentSecret(pub [u8; 32]);
-
/// Positive duration that defines when (relatively to the timestamp) in the future the invoice
/// expires
///
}
}
-impl ToBase32 for PaymentSecret {
- fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
- (&self.0[..]).write_base32(writer)
- }
-}
-
-impl Base32Len for PaymentSecret {
- fn base32_len(&self) -> usize {
- bytes_size_to_base32_size(32)
- }
-}
-
impl ToBase32 for ExpiryTime {
fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
writer.write(&encode_int_be_base32(self.as_seconds()))
extern crate bitcoin_hashes;
+extern crate lightning;
extern crate lightning_invoice;
extern crate secp256k1;
use bitcoin_hashes::hex::FromHex;
use bitcoin_hashes::sha256;
+use lightning::ln::channelmanager::PaymentSecret;
use lightning_invoice::*;
use secp256k1::Secp256k1;
use secp256k1::key::SecretKey;
//! imply it needs to fail HTLCs/payments/channels it manages).
//!
+use bitcoin::bech32;
+use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, WriteBase32, u5};
use bitcoin::blockdata::block::{Block, BlockHeader};
use bitcoin::blockdata::transaction::Transaction;
use bitcoin::blockdata::constants::genesis_block;
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
pub struct PaymentSecret(pub [u8;32]);
+impl FromBase32 for PaymentSecret {
+ type Err = bech32::Error;
+
+ fn from_base32(field_data: &[u5]) -> Result<PaymentSecret, bech32::Error> {
+ if field_data.len() != 52 {
+ return Err(bech32::Error::InvalidLength)
+ } else {
+ let data_bytes = Vec::<u8>::from_base32(field_data)?;
+ let mut payment_secret = [0; 32];
+ payment_secret.copy_from_slice(&data_bytes);
+ Ok(PaymentSecret(payment_secret))
+ }
+ }
+}
+
+impl ToBase32 for PaymentSecret {
+ fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
+ (&self.0[..]).write_base32(writer)
+ }
+}
+
+impl Base32Len for PaymentSecret {
+ fn base32_len(&self) -> usize {
+ 52
+ }
+}
+
type ShutdownResult = (Option<(OutPoint, ChannelMonitorUpdate)>, Vec<(HTLCSource, PaymentHash)>);
/// Error type returned across the channel_state mutex boundary. When an Err is generated for a