Skip to content

Commit 4806a32

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 3bf2169 commit 4806a32

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::{KVStore, EVENT_QUEUE_PERSISTENCE_KEY, EVENT_QUEUE_PERSISTENCE_NAMESPACE};
@@ -223,7 +223,7 @@ where
223223
channel_manager: Arc<ChannelManager>,
224224
network_graph: Arc<NetworkGraph>,
225225
keys_manager: Arc<KeysManager>,
226-
payment_store: Arc<PaymentInfoStorage<K, L>>,
226+
payment_store: Arc<PaymentStore<K, L>>,
227227
tokio_runtime: Arc<tokio::runtime::Runtime>,
228228
logger: L,
229229
_config: Arc<Config>,
@@ -237,7 +237,7 @@ where
237237
pub fn new(
238238
wallet: Arc<Wallet<bdk::database::SqliteDatabase>>, event_queue: Arc<EventQueue<K, L>>,
239239
channel_manager: Arc<ChannelManager>, network_graph: Arc<NetworkGraph>,
240-
keys_manager: Arc<KeysManager>, payment_store: Arc<PaymentInfoStorage<K, L>>,
240+
keys_manager: Arc<KeysManager>, payment_store: Arc<PaymentStore<K, L>>,
241241
tokio_runtime: Arc<tokio::runtime::Runtime>, logger: L, _config: Arc<Config>,
242242
) -> Self {
243243
Self {
@@ -418,16 +418,16 @@ where
418418
}
419419
}
420420
PaymentPurpose::SpontaneousPayment(preimage) => {
421-
let payment_info = PaymentInfo {
421+
let payment = PaymentDetails {
422422
preimage: Some(preimage),
423-
payment_hash,
423+
hash: payment_hash,
424424
secret: None,
425425
amount_msat: Some(amount_msat),
426426
direction: PaymentDirection::Inbound,
427427
status: PaymentStatus::Succeeded,
428428
};
429429

430-
match self.payment_store.insert(payment_info) {
430+
match self.payment_store.insert(payment) {
431431
Ok(false) => (),
432432
Ok(true) => {
433433
log_error!(
@@ -455,17 +455,17 @@ where
455455
.expect("Failed to push to event queue");
456456
}
457457
LdkEvent::PaymentSent { payment_preimage, payment_hash, fee_paid_msat, .. } => {
458-
if let Some(mut payment_info) = self.payment_store.get(&payment_hash) {
459-
payment_info.preimage = Some(payment_preimage);
460-
payment_info.status = PaymentStatus::Succeeded;
458+
if let Some(mut payment) = self.payment_store.get(&payment_hash) {
459+
payment.preimage = Some(payment_preimage);
460+
payment.status = PaymentStatus::Succeeded;
461461
self.payment_store
462-
.insert(payment_info.clone())
462+
.insert(payment.clone())
463463
.expect("Failed to access payment store");
464464
log_info!(
465465
self.logger,
466466
"Successfully sent payment of {}msat{} from \
467467
payment hash {:?} with preimage {:?}",
468-
payment_info.amount_msat.unwrap(),
468+
payment.amount_msat.unwrap(),
469469
if let Some(fee) = fee_paid_msat {
470470
format!(" (fee {} msat)", fee)
471471
} 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)