Skip to content

Commit b3d0434

Browse files
Move PaymentPreimage+PaymentHash+PaymentSecret to top-level ln module
1 parent 0444708 commit b3d0434

17 files changed

+73
-62
lines changed

lightning-invoice/src/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use bech32::{u5, FromBase32};
1010

1111
use bitcoin_hashes::Hash;
1212
use bitcoin_hashes::sha256;
13-
use lightning::ln::channelmanager::PaymentSecret;
13+
use lightning::ln::PaymentSecret;
1414
use lightning::routing::network_graph::RoutingFees;
1515
use lightning::routing::router::RouteHintHop;
1616

lightning-invoice/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern crate secp256k1;
2424
use bech32::u5;
2525
use bitcoin_hashes::Hash;
2626
use bitcoin_hashes::sha256;
27-
use lightning::ln::channelmanager::PaymentSecret;
27+
use lightning::ln::PaymentSecret;
2828
use lightning::ln::features::InvoiceFeatures;
2929
use lightning::routing::router::RouteHintHop;
3030

lightning-invoice/tests/ser_de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate secp256k1;
55

66
use bitcoin_hashes::hex::FromHex;
77
use bitcoin_hashes::sha256;
8-
use lightning::ln::channelmanager::PaymentSecret;
8+
use lightning::ln::PaymentSecret;
99
use lightning_invoice::*;
1010
use secp256k1::Secp256k1;
1111
use secp256k1::key::SecretKey;

lightning/src/chain/channelmonitor.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ use bitcoin::secp256k1::{Secp256k1,Signature};
3434
use bitcoin::secp256k1::key::{SecretKey,PublicKey};
3535
use bitcoin::secp256k1;
3636

37+
use ln::{PaymentHash, PaymentPreimage};
3738
use ln::msgs::DecodeError;
3839
use ln::chan_utils;
3940
use ln::chan_utils::{CounterpartyCommitmentSecrets, HTLCOutputInCommitment, HTLCType, ChannelTransactionParameters, HolderCommitmentTransaction};
40-
use ln::channelmanager::{BestBlock, HTLCSource, PaymentPreimage, PaymentHash};
41+
use ln::channelmanager::{BestBlock, HTLCSource};
4142
use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
4243
use chain;
4344
use chain::WatchedOutput;
@@ -3048,7 +3049,8 @@ mod tests {
30483049
use hex;
30493050
use chain::channelmonitor::ChannelMonitor;
30503051
use chain::transaction::OutPoint;
3051-
use ln::channelmanager::{BestBlock, PaymentPreimage, PaymentHash};
3052+
use ln::{PaymentPreimage, PaymentHash};
3053+
use ln::channelmanager::BestBlock;
30523054
use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
30533055
use ln::chan_utils;
30543056
use ln::chan_utils::{HTLCOutputInCommitment, ChannelPublicKeys, ChannelTransactionParameters, HolderCommitmentTransaction, CounterpartyChannelTransactionParameters};

lightning/src/ln/chan_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
2020
use bitcoin::hashes::ripemd160::Hash as Ripemd160;
2121
use bitcoin::hash_types::{Txid, PubkeyHash};
2222

23-
use ln::channelmanager::{PaymentHash, PaymentPreimage};
23+
use ln::{PaymentHash, PaymentPreimage};
2424
use ln::msgs::DecodeError;
2525
use util::ser::{Readable, Writeable, Writer, MAX_BUF_SIZE};
2626
use util::byte_utils;

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr};
1919
use chain::transaction::OutPoint;
2020
use chain::Listen;
2121
use chain::Watch;
22-
use ln::channelmanager::{RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSendFailure};
22+
use ln::{PaymentPreimage, PaymentHash};
23+
use ln::channelmanager::{RAACommitmentOrder, PaymentSendFailure};
2324
use ln::features::{InitFeatures, InvoiceFeatures};
2425
use ln::msgs;
2526
use ln::msgs::{ChannelMessageHandler, ErrorAction, RoutingMessageHandler};

lightning/src/ln/channel.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ use bitcoin::secp256k1::key::{PublicKey,SecretKey};
2121
use bitcoin::secp256k1::{Secp256k1,Signature};
2222
use bitcoin::secp256k1;
2323

24+
use ln::{PaymentPreimage, PaymentHash};
2425
use ln::features::{ChannelFeatures, InitFeatures};
2526
use ln::msgs;
2627
use ln::msgs::{DecodeError, OptionalField, DataLossProtect};
27-
use ln::channelmanager::{BestBlock, PendingHTLCStatus, HTLCSource, HTLCFailReason, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentPreimage, PaymentHash, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
28+
use ln::channelmanager::{BestBlock, PendingHTLCStatus, HTLCSource, HTLCFailReason, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
2829
use ln::chan_utils::{CounterpartyCommitmentSecrets, TxCreationKeys, HTLCOutputInCommitment, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT, make_funding_redeemscript, ChannelPublicKeys, CommitmentTransaction, HolderCommitmentTransaction, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, MAX_HTLCS, get_commitment_transaction_number_obscure_factor};
2930
use ln::chan_utils;
3031
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
@@ -4824,7 +4825,8 @@ mod tests {
48244825
use bitcoin::network::constants::Network;
48254826
use bitcoin::hashes::hex::FromHex;
48264827
use hex;
4827-
use ln::channelmanager::{BestBlock, HTLCSource, PaymentPreimage, PaymentHash};
4828+
use ln::{PaymentPreimage, PaymentHash};
4829+
use ln::channelmanager::{BestBlock, HTLCSource};
48284830
use ln::channel::{Channel,InboundHTLCOutput,OutboundHTLCOutput,InboundHTLCState,OutboundHTLCState,HTLCOutputInCommitment,HTLCCandidate,HTLCInitiator,TxCreationKeys};
48294831
use ln::channel::MAX_FUNDING_SATOSHIS;
48304832
use ln::features::InitFeatures;

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
//! imply it needs to fail HTLCs/payments/channels it manages).
1919
//!
2020
21-
use bitcoin::bech32;
22-
use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, WriteBase32, u5};
2321
use bitcoin::blockdata::block::{Block, BlockHeader};
2422
use bitcoin::blockdata::transaction::Transaction;
2523
use bitcoin::blockdata::constants::genesis_block;
@@ -45,6 +43,7 @@ use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitor
4543
use chain::transaction::{OutPoint, TransactionData};
4644
// Since this struct is returned in `list_channels` methods, expose it here in case users want to
4745
// construct one themselves.
46+
use ln::{PaymentHash, PaymentPreimage, PaymentSecret};
4847
pub use ln::channel::CounterpartyForwardingInfo;
4948
use ln::channel::{Channel, ChannelError};
5049
use ln::features::{InitFeatures, NodeFeatures};
@@ -199,46 +198,6 @@ pub(super) enum HTLCFailReason {
199198
}
200199
}
201200

202-
/// payment_hash type, use to cross-lock hop
203-
/// (C-not exported) as we just use [u8; 32] directly
204-
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
205-
pub struct PaymentHash(pub [u8;32]);
206-
/// payment_preimage type, use to route payment between hop
207-
/// (C-not exported) as we just use [u8; 32] directly
208-
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
209-
pub struct PaymentPreimage(pub [u8;32]);
210-
/// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
211-
/// (C-not exported) as we just use [u8; 32] directly
212-
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
213-
pub struct PaymentSecret(pub [u8;32]);
214-
215-
impl FromBase32 for PaymentSecret {
216-
type Err = bech32::Error;
217-
218-
fn from_base32(field_data: &[u5]) -> Result<PaymentSecret, bech32::Error> {
219-
if field_data.len() != 52 {
220-
return Err(bech32::Error::InvalidLength)
221-
} else {
222-
let data_bytes = Vec::<u8>::from_base32(field_data)?;
223-
let mut payment_secret = [0; 32];
224-
payment_secret.copy_from_slice(&data_bytes);
225-
Ok(PaymentSecret(payment_secret))
226-
}
227-
}
228-
}
229-
230-
impl ToBase32 for PaymentSecret {
231-
fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
232-
(&self.0[..]).write_base32(writer)
233-
}
234-
}
235-
236-
impl Base32Len for PaymentSecret {
237-
fn base32_len(&self) -> usize {
238-
52
239-
}
240-
}
241-
242201
type ShutdownResult = (Option<(OutPoint, ChannelMonitorUpdate)>, Vec<(HTLCSource, PaymentHash)>);
243202

244203
/// Error type returned across the channel_state mutex boundary. When an Err is generated for a

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
use chain::{Confirm, Listen, Watch};
1414
use chain::channelmonitor::ChannelMonitor;
1515
use chain::transaction::OutPoint;
16-
use ln::channelmanager::{BestBlock, ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
16+
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
17+
use ln::channelmanager::{BestBlock, ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure};
1718
use routing::router::{Route, get_route};
1819
use routing::network_graph::{NetGraphMsgHandler, NetworkGraph};
1920
use ln::features::{InitFeatures, InvoiceFeatures};

lightning/src/ln/functional_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ use chain::channelmonitor;
1818
use chain::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
1919
use chain::transaction::OutPoint;
2020
use chain::keysinterface::{KeysInterface, BaseSign};
21+
use ln::{PaymentPreimage, PaymentSecret, PaymentHash};
2122
use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC};
22-
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentSecret, PaymentHash, PaymentSendFailure, BREAKDOWN_TIMEOUT};
23+
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure, BREAKDOWN_TIMEOUT};
2324
use ln::channel::{Channel, ChannelError};
2425
use ln::{chan_utils, onion_utils};
2526
use routing::router::{Route, RouteHop, get_route};

lightning/src/ln/mod.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,46 @@ mod reorg_tests;
5555
mod onion_route_tests;
5656

5757
pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
58+
59+
/// payment_hash type, use to cross-lock hop
60+
/// (C-not exported) as we just use [u8; 32] directly
61+
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
62+
pub struct PaymentHash(pub [u8;32]);
63+
/// payment_preimage type, use to route payment between hop
64+
/// (C-not exported) as we just use [u8; 32] directly
65+
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
66+
pub struct PaymentPreimage(pub [u8;32]);
67+
/// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
68+
/// (C-not exported) as we just use [u8; 32] directly
69+
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
70+
pub struct PaymentSecret(pub [u8;32]);
71+
72+
use bitcoin::bech32;
73+
use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, WriteBase32, u5};
74+
75+
impl FromBase32 for PaymentSecret {
76+
type Err = bech32::Error;
77+
78+
fn from_base32(field_data: &[u5]) -> Result<PaymentSecret, bech32::Error> {
79+
if field_data.len() != 52 {
80+
return Err(bech32::Error::InvalidLength)
81+
} else {
82+
let data_bytes = Vec::<u8>::from_base32(field_data)?;
83+
let mut payment_secret = [0; 32];
84+
payment_secret.copy_from_slice(&data_bytes);
85+
Ok(PaymentSecret(payment_secret))
86+
}
87+
}
88+
}
89+
90+
impl ToBase32 for PaymentSecret {
91+
fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
92+
(&self.0[..]).write_base32(writer)
93+
}
94+
}
95+
96+
impl Base32Len for PaymentSecret {
97+
fn base32_len(&self) -> usize {
98+
52
99+
}
100+
}

lightning/src/ln/msgs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use std::io::Read;
3939
use util::events::MessageSendEventsProvider;
4040
use util::ser::{Readable, Writeable, Writer, FixedLengthReader, HighZeroBytesDroppedVarInt};
4141

42-
use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret};
42+
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
4343

4444
/// 21 million * 10^8 * 1000
4545
pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000;
@@ -854,7 +854,7 @@ pub trait RoutingMessageHandler : Send + Sync + MessageSendEventsProvider {
854854
}
855855

856856
mod fuzzy_internal_msgs {
857-
use ln::channelmanager::PaymentSecret;
857+
use ln::PaymentSecret;
858858

859859
// These types aren't intended to be pub, but are exposed for direct fuzzing (as we deserialize
860860
// them from untrusted input):
@@ -1813,9 +1813,9 @@ impl Writeable for GossipTimestampFilter {
18131813
#[cfg(test)]
18141814
mod tests {
18151815
use hex;
1816+
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
18161817
use ln::msgs;
18171818
use ln::msgs::{ChannelFeatures, FinalOnionHopData, InitFeatures, NodeFeatures, OptionalField, OnionErrorPacket, OnionHopDataFormat};
1818-
use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret};
18191819
use util::ser::{Writeable, Readable};
18201820

18211821
use bitcoin::hashes::hex::FromHex;

lightning/src/ln/onchaintx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use bitcoin::secp256k1::{Secp256k1, Signature};
2222
use bitcoin::secp256k1;
2323

2424
use ln::msgs::DecodeError;
25-
use ln::channelmanager::PaymentPreimage;
25+
use ln::PaymentPreimage;
2626
use ln::chan_utils;
2727
use ln::chan_utils::{TxCreationKeys, ChannelTransactionParameters, HolderCommitmentTransaction};
2828
use chain::chaininterface::{FeeEstimator, BroadcasterInterface, ConfirmationTarget, MIN_RELAY_FEE_SAT_PER_1000_WEIGHT};

lightning/src/ln/onion_route_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
//! returned errors decode to the correct thing.
1313
1414
use chain::channelmonitor::{CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS};
15-
use ln::channelmanager::{HTLCForwardInfo, PaymentPreimage, PaymentHash, PaymentSecret};
15+
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
16+
use ln::channelmanager::HTLCForwardInfo;
1617
use ln::onion_utils;
1718
use routing::router::{Route, get_route};
1819
use ln::features::{InitFeatures, InvoiceFeatures};

lightning/src/ln/onion_utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
// You may not use this file except in accordance with one or both of these
88
// licenses.
99

10-
use ln::channelmanager::{PaymentHash, PaymentSecret, HTLCSource};
10+
use ln::{PaymentHash, PaymentSecret};
11+
use ln::channelmanager::HTLCSource;
1112
use ln::msgs;
1213
use routing::router::RouteHop;
1314
use util::byte_utils;
@@ -477,7 +478,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
477478

478479
#[cfg(test)]
479480
mod tests {
480-
use ln::channelmanager::PaymentHash;
481+
use ln::PaymentHash;
481482
use ln::features::{ChannelFeatures, NodeFeatures};
482483
use routing::router::{Route, RouteHop};
483484
use ln::msgs;

lightning/src/util/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! few other things.
1616
1717
use ln::msgs;
18-
use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret};
18+
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
1919
use chain::keysinterface::SpendableOutputDescriptor;
2020
use util::ser::{Writeable, Writer, MaybeReadable, Readable};
2121

lightning/src/util/ser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash;
2727
use bitcoin::hash_types::{Txid, BlockHash};
2828
use std::marker::Sized;
2929
use ln::msgs::DecodeError;
30-
use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret};
30+
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
3131
use util::byte_utils;
3232

3333
use util::byte_utils::{be64_to_array, be48_to_array, be32_to_array, be16_to_array, slice_to_be16, slice_to_be32, slice_to_be48, slice_to_be64};

0 commit comments

Comments
 (0)