Skip to content

put route hints in email #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use aws_sdk_sesv2::{
types::{Body, Content, Destination, EmailContent, Message},
Client,
};
use lightning_invoice::RouteHint;
#[cfg(test)]
use mockall::automock;
use secp256k1::{hashes::sha256, PublicKey};
Expand All @@ -12,21 +13,37 @@ use tracing::{debug, error, warn};
pub struct NotifyPaymentFailedRequest {
pub destination: PublicKey,
pub error: anyhow::Error,
pub hints: Vec<RouteHint>,
pub payment_hash: sha256::Hash,
pub invoice: String,
}

impl NotifyPaymentFailedRequest {
pub fn to_html(&self) -> impl Into<String> {
let hints: Vec<_> = self
.hints
.iter()
.filter_map(|r| r.0.last())
.enumerate()
.map(|(i, hint)| {
format!(
"<tr><td>Route hint {}: {}, {}</td></tr>",
i,
hint.src_node_id,
scid_to_string(hint.short_channel_id),
)
})
.collect();
format!(
"
<table>
<tr><td>Destination: {}</td></tr>
<tr><td>Destination: {}</td></tr>{}
<tr><td>Error: {}</td></tr>
<tr><td>Payment hash: {}</td></tr>
<tr><td>Invoice: {}</td></tr>
</table>",
self.destination,
hints.join(""),
self.error
.to_string()
.replace("&", "&amp;")
Expand All @@ -41,6 +58,15 @@ impl NotifyPaymentFailedRequest {
}
}

fn scid_to_string(scid: u64) -> String {
format!(
"{}x{}x{}",
scid >> 40,
(scid >> 16) & 0xFFFFFF,
scid & 0xFFFF
)
}

#[cfg_attr(test, automock)]
#[async_trait::async_trait]
pub trait NotificationService {
Expand Down
1 change: 1 addition & 0 deletions src/htlc_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ async fn payment_lifecycle<B, N, P, S>(
.notify_payment_failed(NotifyPaymentFailedRequest {
destination: trampoline.payee,
error: e,
hints: trampoline.invoice.route_hints(),
payment_hash: *trampoline.invoice.payment_hash(),
invoice: trampoline.bolt11,
})
Expand Down