Skip to content

Commit 031a987

Browse files
committed
Make LSPS5ServiceEvent::SendWebhookNotification::headers a Vec
While HTTP headers should be a unique K->V mapping, returning three headers to a user in an event via a `HashMap` is substantially overkill (and also not trivial to do in bindings). Instead, we expose them as a `Vec`.
1 parent afb80e5 commit 031a987

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

lightning-liquidity/src/lsps5/event.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use alloc::vec::Vec;
1515
use bitcoin::secp256k1::PublicKey;
1616

1717
use lightning::impl_writeable_tlv_based_enum;
18-
use lightning::util::hash_tables::HashMap;
1918

2019
use super::msgs::LSPS5AppName;
2120
use super::msgs::LSPS5Error;
@@ -70,7 +69,7 @@ pub enum LSPS5ServiceEvent {
7069
/// - `"x-lsps5-timestamp"`: with the timestamp in RFC3339 format (`"YYYY-MM-DDThh:mm:ss.uuuZ"`).
7170
/// - `"x-lsps5-signature"`: with the signature of the notification payload, signed using the LSP's node ID.
7271
/// Other custom headers may also be included as needed.
73-
headers: HashMap<String, String>,
72+
headers: Vec<(String, String)>,
7473
},
7574
}
7675

lightning-liquidity/src/lsps5/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,12 +629,12 @@ where
629629

630630
let signature_hex = self.sign_notification(&notification, &timestamp)?;
631631

632-
let mut headers: HashMap<String, String> = [("Content-Type", "application/json")]
632+
let mut headers: Vec<(String, String)> = [("Content-Type", "application/json")]
633633
.into_iter()
634634
.map(|(k, v)| (k.to_string(), v.to_string()))
635635
.collect();
636-
headers.insert("x-lsps5-timestamp".into(), timestamp.to_rfc3339());
637-
headers.insert("x-lsps5-signature".into(), signature_hex);
636+
headers.push(("x-lsps5-timestamp".into(), timestamp.to_rfc3339()));
637+
headers.push(("x-lsps5-signature".into(), signature_hex));
638638

639639
event_queue_notifier.enqueue(LSPS5ServiceEvent::SendWebhookNotification {
640640
counterparty_node_id,

lightning-liquidity/tests/lsps5_integration_tests.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use lightning::ln::functional_test_utils::{
1717
};
1818
use lightning::ln::msgs::Init;
1919
use lightning::ln::peer_handler::CustomMessageHandler;
20-
use lightning::util::hash_tables::{HashMap, HashSet};
20+
use lightning::util::hash_tables::HashSet;
2121
use lightning::util::test_utils::TestStore;
2222
use lightning_liquidity::events::LiquidityEvent;
2323
use lightning_liquidity::lsps0::ser::LSPSDateTime;
@@ -288,15 +288,20 @@ impl TimeProvider for MockTimeProvider {
288288
}
289289
}
290290

291-
fn extract_ts_sig(headers: &HashMap<String, String>) -> (LSPSDateTime, String) {
291+
fn extract_ts_sig(headers: &Vec<(String, String)>) -> (LSPSDateTime, String) {
292292
let timestamp = headers
293-
.get("x-lsps5-timestamp")
293+
.iter()
294+
.find_map(|(key, value)| (key == "x-lsps5-timestamp").then(|| value))
294295
.expect("missing x-lsps5-timestamp header")
295296
.parse::<LSPSDateTime>()
296297
.expect("failed to parse x-lsps5-timestamp header");
297298

298-
let signature =
299-
headers.get("x-lsps5-signature").expect("missing x-lsps5-signature header").to_owned();
299+
let signature = headers
300+
.iter()
301+
.find(|(key, _)| key == "x-lsps5-signature")
302+
.expect("missing x-lsps5-signature header")
303+
.1
304+
.clone();
300305
(timestamp, signature)
301306
}
302307

0 commit comments

Comments
 (0)