Skip to content

Commit 50f9f6b

Browse files
committed
Expose txid and confirmation_status for onchain payments.
Onchain payments now provide additional information such as transaction_id and confirmation_status.
1 parent 28575c6 commit 50f9f6b

File tree

3 files changed

+100
-5
lines changed

3 files changed

+100
-5
lines changed

ldk-server-protos/src/proto/types.proto

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,35 @@ message PaymentKind {
3535
}
3636

3737
// Represents an on-chain payment.
38-
message Onchain {}
38+
message Onchain {
39+
// The transaction identifier of this payment.
40+
string txid = 1;
41+
42+
// The confirmation status of this payment.
43+
ConfirmationStatus status = 2;
44+
}
45+
46+
message ConfirmationStatus {
47+
oneof status {
48+
Confirmed confirmed = 1;
49+
Unconfirmed unconfirmed = 2;
50+
}
51+
}
52+
53+
// The on-chain transaction is confirmed in the best chain.
54+
message Confirmed {
55+
// The hex representation of hash of the block in which the transaction was confirmed.
56+
string block_hash = 1;
57+
58+
// The height under which the block was confirmed.
59+
uint32 height = 2;
60+
61+
// The timestamp, in seconds since start of the UNIX epoch, when this entry was last updated.
62+
uint64 timestamp = 3;
63+
}
64+
65+
// The on-chain transaction is unconfirmed.
66+
message Unconfirmed {}
3967

4068
// Represents a BOLT 11 payment.
4169
message Bolt11 {

ldk-server-protos/src/types.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,49 @@ pub mod payment_kind {
5050
/// Represents an on-chain payment.
5151
#[allow(clippy::derive_partial_eq_without_eq)]
5252
#[derive(Clone, PartialEq, ::prost::Message)]
53-
pub struct Onchain {}
53+
pub struct Onchain {
54+
/// The transaction identifier of this payment.
55+
#[prost(string, tag = "1")]
56+
pub txid: ::prost::alloc::string::String,
57+
/// The confirmation status of this payment.
58+
#[prost(message, optional, tag = "2")]
59+
pub status: ::core::option::Option<ConfirmationStatus>,
60+
}
61+
#[allow(clippy::derive_partial_eq_without_eq)]
62+
#[derive(Clone, PartialEq, ::prost::Message)]
63+
pub struct ConfirmationStatus {
64+
#[prost(oneof = "confirmation_status::Status", tags = "1, 2")]
65+
pub status: ::core::option::Option<confirmation_status::Status>,
66+
}
67+
/// Nested message and enum types in `ConfirmationStatus`.
68+
pub mod confirmation_status {
69+
#[allow(clippy::derive_partial_eq_without_eq)]
70+
#[derive(Clone, PartialEq, ::prost::Oneof)]
71+
pub enum Status {
72+
#[prost(message, tag = "1")]
73+
Confirmed(super::Confirmed),
74+
#[prost(message, tag = "2")]
75+
Unconfirmed(super::Unconfirmed),
76+
}
77+
}
78+
/// The on-chain transaction is confirmed in the best chain.
79+
#[allow(clippy::derive_partial_eq_without_eq)]
80+
#[derive(Clone, PartialEq, ::prost::Message)]
81+
pub struct Confirmed {
82+
/// The hex representation of hash of the block in which the transaction was confirmed.
83+
#[prost(string, tag = "1")]
84+
pub block_hash: ::prost::alloc::string::String,
85+
/// The height under which the block was confirmed.
86+
#[prost(uint32, tag = "2")]
87+
pub height: u32,
88+
/// The timestamp, in seconds since start of the UNIX epoch, when this entry was last updated.
89+
#[prost(uint64, tag = "3")]
90+
pub timestamp: u64,
91+
}
92+
/// The on-chain transaction is unconfirmed.
93+
#[allow(clippy::derive_partial_eq_without_eq)]
94+
#[derive(Clone, PartialEq, ::prost::Message)]
95+
pub struct Unconfirmed {}
5496
/// Represents a BOLT 11 payment.
5597
#[allow(clippy::derive_partial_eq_without_eq)]
5698
#[derive(Clone, PartialEq, ::prost::Message)]

ldk-server/src/util/proto_adapter.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ use ldk_node::bitcoin::secp256k1::PublicKey;
55
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
66
use ldk_node::lightning::ln::types::ChannelId;
77
use ldk_node::lightning_invoice::{Bolt11InvoiceDescription, Description, Sha256};
8-
use ldk_node::payment::{PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus};
8+
use ldk_node::payment::{
9+
ConfirmationStatus, PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus,
10+
};
911
use ldk_node::{ChannelDetails, LightningBalance, NodeError, PendingSweepBalance, UserChannelId};
12+
use ldk_server_protos::types::confirmation_status::Status::{Confirmed, Unconfirmed};
1013
use ldk_server_protos::types::lightning_balance::BalanceType::{
1114
ClaimableAwaitingConfirmations, ClaimableOnChannelClose, ContentiousClaimable,
1215
CounterpartyRevokedOutputClaimable, MaybePreimageClaimableHtlc, MaybeTimeoutClaimableHtlc,
@@ -110,8 +113,11 @@ pub(crate) fn payment_kind_to_proto(
110113
payment_kind: PaymentKind,
111114
) -> ldk_server_protos::types::PaymentKind {
112115
match payment_kind {
113-
PaymentKind::Onchain => ldk_server_protos::types::PaymentKind {
114-
kind: Some(Onchain(ldk_server_protos::types::Onchain {})),
116+
PaymentKind::Onchain { txid, status } => ldk_server_protos::types::PaymentKind {
117+
kind: Some(Onchain(ldk_server_protos::types::Onchain {
118+
txid: txid.to_string(),
119+
status: Some(confirmation_status_to_proto(status)),
120+
})),
115121
},
116122
PaymentKind::Bolt11 { hash, preimage, secret } => ldk_server_protos::types::PaymentKind {
117123
kind: Some(Bolt11(ldk_server_protos::types::Bolt11 {
@@ -166,6 +172,25 @@ pub(crate) fn payment_kind_to_proto(
166172
}
167173
}
168174

175+
pub(crate) fn confirmation_status_to_proto(
176+
confirmation_status: ConfirmationStatus,
177+
) -> ldk_server_protos::types::ConfirmationStatus {
178+
match confirmation_status {
179+
ConfirmationStatus::Confirmed { block_hash, height, timestamp } => {
180+
ldk_server_protos::types::ConfirmationStatus {
181+
status: Some(Confirmed(ldk_server_protos::types::Confirmed {
182+
block_hash: block_hash.to_string(),
183+
height,
184+
timestamp,
185+
})),
186+
}
187+
},
188+
ConfirmationStatus::Unconfirmed => ldk_server_protos::types::ConfirmationStatus {
189+
status: Some(Unconfirmed(ldk_server_protos::types::Unconfirmed {})),
190+
},
191+
}
192+
}
193+
169194
pub(crate) fn lightning_balance_to_proto(
170195
lightning_balance: LightningBalance,
171196
) -> ldk_server_protos::types::LightningBalance {

0 commit comments

Comments
 (0)