Skip to content

Commit da21e54

Browse files
committed
f Rename PaymentInfo to PaymentDetails (+..InfoStorage to Store)
We avoid the `Info` umbrella term but opt to introduce `PaymentDetails` to align naming with upcoming `PeerDetails` and `ChannelDetails`.
1 parent 6464c60 commit da21e54

File tree

5 files changed

+98
-106
lines changed

5 files changed

+98
-106
lines changed

src/event.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
hex_utils, ChannelManager, Config, Error, KeysManager, NetworkGraph, PaymentDirection,
3-
PaymentInfo, PaymentInfoStorage, PaymentStatus, Wallet,
2+
hex_utils, ChannelManager, Config, Error, KeysManager, NetworkGraph, PaymentDetails,
3+
PaymentDirection, PaymentStatus, PaymentStore, Wallet,
44
};
55

66
use crate::io::{
@@ -225,7 +225,7 @@ where
225225
channel_manager: Arc<ChannelManager>,
226226
network_graph: Arc<NetworkGraph>,
227227
keys_manager: Arc<KeysManager>,
228-
payment_store: Arc<PaymentInfoStorage<K, L>>,
228+
payment_store: Arc<PaymentStore<K, L>>,
229229
tokio_runtime: Arc<tokio::runtime::Runtime>,
230230
logger: L,
231231
_config: Arc<Config>,
@@ -239,7 +239,7 @@ where
239239
pub fn new(
240240
wallet: Arc<Wallet<bdk::database::SqliteDatabase>>, event_queue: Arc<EventQueue<K, L>>,
241241
channel_manager: Arc<ChannelManager>, network_graph: Arc<NetworkGraph>,
242-
keys_manager: Arc<KeysManager>, payment_store: Arc<PaymentInfoStorage<K, L>>,
242+
keys_manager: Arc<KeysManager>, payment_store: Arc<PaymentStore<K, L>>,
243243
tokio_runtime: Arc<tokio::runtime::Runtime>, logger: L, _config: Arc<Config>,
244244
) -> Self {
245245
Self {
@@ -420,16 +420,16 @@ where
420420
}
421421
}
422422
PaymentPurpose::SpontaneousPayment(preimage) => {
423-
let payment_info = PaymentInfo {
423+
let payment = PaymentDetails {
424424
preimage: Some(preimage),
425-
payment_hash,
425+
hash: payment_hash,
426426
secret: None,
427427
amount_msat: Some(amount_msat),
428428
direction: PaymentDirection::Inbound,
429429
status: PaymentStatus::Succeeded,
430430
};
431431

432-
match self.payment_store.insert(payment_info) {
432+
match self.payment_store.insert(payment) {
433433
Ok(false) => (),
434434
Ok(true) => {
435435
log_error!(
@@ -457,17 +457,17 @@ where
457457
.expect("Failed to push to event queue");
458458
}
459459
LdkEvent::PaymentSent { payment_preimage, payment_hash, fee_paid_msat, .. } => {
460-
if let Some(mut payment_info) = self.payment_store.get(&payment_hash) {
461-
payment_info.preimage = Some(payment_preimage);
462-
payment_info.status = PaymentStatus::Succeeded;
460+
if let Some(mut payment) = self.payment_store.get(&payment_hash) {
461+
payment.preimage = Some(payment_preimage);
462+
payment.status = PaymentStatus::Succeeded;
463463
self.payment_store
464-
.insert(payment_info.clone())
464+
.insert(payment.clone())
465465
.expect("Failed to access payment store");
466466
log_info!(
467467
self.logger,
468468
"Successfully sent payment of {}msat{} from \
469469
payment hash {:?} with preimage {:?}",
470-
payment_info.amount_msat.unwrap(),
470+
payment.amount_msat.unwrap(),
471471
if let Some(fee) = fee_paid_msat {
472472
format!(" (fee {} msat)", fee)
473473
} else {

src/io/utils.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::*;
22
use crate::WALLET_KEYS_SEED_LEN;
33

44
use crate::peer_store::PeerInfoStorage;
5-
use crate::{EventQueue, PaymentInfo};
5+
use crate::{EventQueue, PaymentDetails};
66

77
use lightning::chain::channelmonitor::ChannelMonitor;
88
use lightning::chain::keysinterface::{EntropySource, SignerProvider};
@@ -158,22 +158,20 @@ where
158158
}
159159

160160
/// Read previously persisted payments information from the store.
161-
pub(crate) fn read_payment_info<K: Deref>(kv_store: K) -> Result<Vec<PaymentInfo>, std::io::Error>
161+
pub(crate) fn read_payments<K: Deref>(kv_store: K) -> Result<Vec<PaymentDetails>, std::io::Error>
162162
where
163163
K::Target: KVStore,
164164
{
165165
let mut res = Vec::new();
166166

167167
for stored_key in kv_store.list(PAYMENT_INFO_PERSISTENCE_NAMESPACE)? {
168-
let payment_info =
169-
PaymentInfo::read(&mut kv_store.read(PAYMENT_INFO_PERSISTENCE_NAMESPACE, &stored_key)?)
170-
.map_err(|_| {
171-
std::io::Error::new(
172-
std::io::ErrorKind::InvalidData,
173-
"Failed to deserialize PaymentInfo",
174-
)
175-
})?;
176-
res.push(payment_info);
168+
let payment = PaymentDetails::read(
169+
&mut kv_store.read(PAYMENT_INFO_PERSISTENCE_NAMESPACE, &stored_key)?,
170+
)
171+
.map_err(|_| {
172+
std::io::Error::new(std::io::ErrorKind::InvalidData, "Failed to deserialize Payment")
173+
})?;
174+
res.push(payment);
177175
}
178176
Ok(res)
179177
}

src/lib.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ pub use event::Event;
8787
use event::{EventHandler, EventQueue};
8888
use io::fs_store::FilesystemStore;
8989
use io::{KVStore, CHANNEL_MANAGER_PERSISTENCE_KEY, CHANNEL_MANAGER_PERSISTENCE_NAMESPACE};
90-
use payment_store::PaymentInfoStorage;
91-
pub use payment_store::{PaymentDirection, PaymentInfo, PaymentStatus};
90+
use payment_store::PaymentStore;
91+
pub use payment_store::{PaymentDetails, PaymentDirection, PaymentStatus};
9292
use peer_store::{PeerInfo, PeerInfoStorage};
9393
use types::{
9494
ChainMonitor, ChannelManager, GossipSync, KeysManager, NetworkGraph, OnionMessenger,
@@ -502,8 +502,8 @@ impl Builder {
502502
));
503503

504504
// Init payment info storage
505-
let payment_store = match io::utils::read_payment_info(Arc::clone(&kv_store)) {
506-
Ok(payments) => Arc::new(PaymentInfoStorage::from_payments(
505+
let payment_store = match io::utils::read_payments(Arc::clone(&kv_store)) {
506+
Ok(payments) => Arc::new(PaymentStore::from_payments(
507507
payments,
508508
Arc::clone(&kv_store),
509509
Arc::clone(&logger),
@@ -591,7 +591,7 @@ pub struct Node {
591591
logger: Arc<FilesystemLogger>,
592592
scorer: Arc<Mutex<Scorer>>,
593593
peer_store: Arc<PeerInfoStorage<Arc<FilesystemStore>, Arc<FilesystemLogger>>>,
594-
payment_store: Arc<PaymentInfoStorage<Arc<FilesystemStore>, Arc<FilesystemLogger>>>,
594+
payment_store: Arc<PaymentStore<Arc<FilesystemStore>, Arc<FilesystemLogger>>>,
595595
}
596596

597597
impl Node {
@@ -1023,15 +1023,15 @@ impl Node {
10231023
let amt_msat = invoice.amount_milli_satoshis().unwrap();
10241024
log_info!(self.logger, "Initiated sending {}msat to {}", amt_msat, payee_pubkey);
10251025

1026-
let payment_info = PaymentInfo {
1026+
let payment = PaymentDetails {
10271027
preimage: None,
1028-
payment_hash,
1028+
hash: payment_hash,
10291029
secret: payment_secret,
10301030
amount_msat: invoice.amount_milli_satoshis(),
10311031
direction: PaymentDirection::Outbound,
10321032
status: PaymentStatus::Pending,
10331033
};
1034-
self.payment_store.insert(payment_info)?;
1034+
self.payment_store.insert(payment)?;
10351035

10361036
Ok(payment_hash)
10371037
}
@@ -1118,15 +1118,15 @@ impl Node {
11181118
payee_pubkey
11191119
);
11201120

1121-
let payment_info = PaymentInfo {
1122-
payment_hash,
1121+
let payment = PaymentDetails {
1122+
hash: payment_hash,
11231123
preimage: None,
11241124
secret: payment_secret,
11251125
direction: PaymentDirection::Outbound,
11261126
status: PaymentStatus::Pending,
11271127
amount_msat: Some(amount_msat),
11281128
};
1129-
self.payment_store.insert(payment_info)?;
1129+
self.payment_store.insert(payment)?;
11301130

11311131
Ok(payment_hash)
11321132
}
@@ -1179,30 +1179,30 @@ impl Node {
11791179
Ok(_payment_id) => {
11801180
log_info!(self.logger, "Initiated sending {}msat to {}.", amount_msat, node_id);
11811181

1182-
let payment_info = PaymentInfo {
1183-
payment_hash,
1182+
let payment = PaymentDetails {
1183+
hash: payment_hash,
11841184
preimage: Some(payment_preimage),
11851185
secret: None,
11861186
status: PaymentStatus::Pending,
11871187
direction: PaymentDirection::Outbound,
11881188
amount_msat: Some(amount_msat),
11891189
};
1190-
self.payment_store.insert(payment_info)?;
1190+
self.payment_store.insert(payment)?;
11911191

11921192
Ok(payment_hash)
11931193
}
11941194
Err(e) => {
11951195
log_error!(self.logger, "Failed to send payment: {:?}", e);
11961196

1197-
let payment_info = PaymentInfo {
1198-
payment_hash,
1197+
let payment = PaymentDetails {
1198+
hash: payment_hash,
11991199
preimage: Some(payment_preimage),
12001200
secret: None,
12011201
status: PaymentStatus::Failed,
12021202
direction: PaymentDirection::Outbound,
12031203
amount_msat: Some(amount_msat),
12041204
};
1205-
self.payment_store.insert(payment_info)?;
1205+
self.payment_store.insert(payment)?;
12061206

12071207
Err(Error::PaymentFailed)
12081208
}
@@ -1256,22 +1256,22 @@ impl Node {
12561256
};
12571257

12581258
let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
1259-
let payment_info = PaymentInfo {
1259+
let payment = PaymentDetails {
1260+
hash: payment_hash,
12601261
preimage: None,
1261-
payment_hash,
12621262
secret: Some(invoice.payment_secret().clone()),
12631263
amount_msat,
12641264
direction: PaymentDirection::Inbound,
12651265
status: PaymentStatus::Pending,
12661266
};
12671267

1268-
self.payment_store.insert(payment_info)?;
1268+
self.payment_store.insert(payment)?;
12691269

12701270
Ok(invoice)
12711271
}
12721272

12731273
/// Query for information about the status of a specific payment.
1274-
pub fn payment_info(&self, payment_hash: &PaymentHash) -> Option<PaymentInfo> {
1274+
pub fn payment(&self, payment_hash: &PaymentHash) -> Option<PaymentDetails> {
12751275
self.payment_store.get(payment_hash)
12761276
}
12771277
}

0 commit comments

Comments
 (0)