Skip to content
Merged
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
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ export interface PaymentEvent {
amountMsat?: number
reason?: string
payerNote?: string
/** Opaque payment identifier. Present for Sent and Failed (outbound) events. */
paymentId?: string
/** Payment preimage (proof of payment). Present for Sent events. */
preimage?: string
}
export const enum PaymentEventType {
Claimable = 0,
Received = 1,
Failed = 2,
Sent = 3
}
export interface NodeChannel {
channelId: string
Expand Down
26 changes: 26 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,18 @@ pub struct PaymentEvent {
pub amount_msat: Option<i64>,
pub reason: Option<String>,
pub payer_note: Option<String>,
/// Opaque payment identifier. Present for Sent and Failed (outbound) events.
pub payment_id: Option<String>,
/// Payment preimage (proof of payment). Present for Sent events.
pub preimage: Option<String>,
}

#[napi]
pub enum PaymentEventType {
Claimable,
Received,
Failed,
Sent,
Comment on lines 318 to +321
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Regenerate TS bindings after adding new payment event shape

This change extends the N-API surface (PaymentEvent now has payment_id/preimage, and PaymentEventType now includes Sent), but the checked-in generated typings still expose only the old shape (index.d.ts lines 50-61 still lack those fields and enum member). Because publish uses the repository’s index.d.ts, TypeScript consumers cannot type-check handlers for outbound success events and will see an API/type mismatch at compile time; please regenerate and commit the updated bindings with this Rust API change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

#[napi(object)]
Expand Down Expand Up @@ -463,6 +468,8 @@ impl MdkNode {
amount_msat: Some(*claimable_amount_msat as i64),
reason: None,
payer_note: None,
payment_id: None,
preimage: None,
}),
Event::PaymentReceived {
payment_id,
Expand Down Expand Up @@ -490,9 +497,12 @@ impl MdkNode {
amount_msat: Some(*amount_msat as i64),
reason: None,
payer_note,
payment_id: None,
preimage: None,
})
}
Event::PaymentFailed {
payment_id: event_pid,
payment_hash,
reason,
..
Expand All @@ -502,6 +512,22 @@ impl MdkNode {
amount_msat: None,
reason: reason.map(|r| format!("{r:?}")),
payer_note: None,
payment_id: event_pid.map(|id| bytes_to_hex(&id.0)),
preimage: None,
}),
Event::PaymentSuccessful {
payment_id: event_pid,
payment_hash,
payment_preimage,
..
} => Some(PaymentEvent {
event_type: PaymentEventType::Sent,
payment_hash: bytes_to_hex(&payment_hash.0),
amount_msat: None,
reason: None,
payer_note: None,
payment_id: event_pid.map(|id| bytes_to_hex(&id.0)),
preimage: payment_preimage.map(|p| bytes_to_hex(&p.0)),
}),
_ => None,
};
Expand Down