@@ -2,10 +2,17 @@ use bytes::Bytes;
22use hex:: prelude:: * ;
33use ldk_node:: config:: { ChannelConfig , MaxDustHTLCExposure } ;
44use ldk_node:: payment:: { PaymentDetails , PaymentDirection , PaymentKind , PaymentStatus } ;
5- use ldk_node:: ChannelDetails ;
5+ use ldk_node:: { ChannelDetails , LightningBalance , PendingSweepBalance } ;
6+ use ldk_server_protos:: types:: lightning_balance:: BalanceType :: {
7+ ClaimableAwaitingConfirmations , ClaimableOnChannelClose , ContentiousClaimable ,
8+ CounterpartyRevokedOutputClaimable , MaybePreimageClaimableHtlc , MaybeTimeoutClaimableHtlc ,
9+ } ;
610use ldk_server_protos:: types:: payment_kind:: Kind :: {
711 Bolt11 , Bolt11Jit , Bolt12Offer , Bolt12Refund , Onchain , Spontaneous ,
812} ;
13+ use ldk_server_protos:: types:: pending_sweep_balance:: BalanceType :: {
14+ AwaitingThresholdConfirmations , BroadcastAwaitingConfirmation , PendingBroadcast ,
15+ } ;
916use ldk_server_protos:: types:: { Channel , LspFeeLimits , OutPoint , Payment } ;
1017
1118pub ( crate ) fn channel_to_proto ( channel : ChannelDetails ) -> Channel {
@@ -152,3 +159,164 @@ pub(crate) fn payment_kind_to_proto(
152159 } ,
153160 }
154161}
162+
163+ pub ( crate ) fn lightning_balance_to_proto (
164+ lightning_balance : LightningBalance ,
165+ ) -> ldk_server_protos:: types:: LightningBalance {
166+ match lightning_balance {
167+ LightningBalance :: ClaimableOnChannelClose {
168+ channel_id,
169+ counterparty_node_id,
170+ amount_satoshis,
171+ transaction_fee_satoshis,
172+ outbound_payment_htlc_rounded_msat,
173+ outbound_forwarded_htlc_rounded_msat,
174+ inbound_claiming_htlc_rounded_msat,
175+ inbound_htlc_rounded_msat,
176+ } => ldk_server_protos:: types:: LightningBalance {
177+ balance_type : Some ( ClaimableOnChannelClose (
178+ ldk_server_protos:: types:: ClaimableOnChannelClose {
179+ channel_id : channel_id. 0 . to_lower_hex_string ( ) ,
180+ counterparty_node_id : counterparty_node_id. to_string ( ) ,
181+ amount_satoshis,
182+ transaction_fee_satoshis,
183+ outbound_payment_htlc_rounded_msat,
184+ outbound_forwarded_htlc_rounded_msat,
185+ inbound_claiming_htlc_rounded_msat,
186+ inbound_htlc_rounded_msat,
187+ } ,
188+ ) ) ,
189+ } ,
190+ LightningBalance :: ClaimableAwaitingConfirmations {
191+ channel_id,
192+ counterparty_node_id,
193+ amount_satoshis,
194+ confirmation_height,
195+ ..
196+ } => ldk_server_protos:: types:: LightningBalance {
197+ balance_type : Some ( ClaimableAwaitingConfirmations (
198+ ldk_server_protos:: types:: ClaimableAwaitingConfirmations {
199+ channel_id : channel_id. 0 . to_lower_hex_string ( ) ,
200+ counterparty_node_id : counterparty_node_id. to_string ( ) ,
201+ amount_satoshis,
202+ confirmation_height,
203+ } ,
204+ ) ) ,
205+ } ,
206+ LightningBalance :: ContentiousClaimable {
207+ channel_id,
208+ counterparty_node_id,
209+ amount_satoshis,
210+ timeout_height,
211+ payment_hash,
212+ payment_preimage,
213+ } => ldk_server_protos:: types:: LightningBalance {
214+ balance_type : Some ( ContentiousClaimable (
215+ ldk_server_protos:: types:: ContentiousClaimable {
216+ channel_id : channel_id. 0 . to_lower_hex_string ( ) ,
217+ counterparty_node_id : counterparty_node_id. to_string ( ) ,
218+ amount_satoshis,
219+ timeout_height,
220+ payment_hash : payment_hash. to_string ( ) ,
221+ payment_preimage : payment_preimage. to_string ( ) ,
222+ } ,
223+ ) ) ,
224+ } ,
225+ LightningBalance :: MaybeTimeoutClaimableHTLC {
226+ channel_id,
227+ counterparty_node_id,
228+ amount_satoshis,
229+ claimable_height,
230+ payment_hash,
231+ outbound_payment,
232+ } => ldk_server_protos:: types:: LightningBalance {
233+ balance_type : Some ( MaybeTimeoutClaimableHtlc (
234+ ldk_server_protos:: types:: MaybeTimeoutClaimableHtlc {
235+ channel_id : channel_id. 0 . to_lower_hex_string ( ) ,
236+ counterparty_node_id : counterparty_node_id. to_string ( ) ,
237+ amount_satoshis,
238+ claimable_height,
239+ payment_hash : payment_hash. to_string ( ) ,
240+ outbound_payment,
241+ } ,
242+ ) ) ,
243+ } ,
244+ LightningBalance :: MaybePreimageClaimableHTLC {
245+ channel_id,
246+ counterparty_node_id,
247+ amount_satoshis,
248+ expiry_height,
249+ payment_hash,
250+ } => ldk_server_protos:: types:: LightningBalance {
251+ balance_type : Some ( MaybePreimageClaimableHtlc (
252+ ldk_server_protos:: types:: MaybePreimageClaimableHtlc {
253+ channel_id : channel_id. 0 . to_lower_hex_string ( ) ,
254+ counterparty_node_id : counterparty_node_id. to_string ( ) ,
255+ amount_satoshis,
256+ expiry_height,
257+ payment_hash : payment_hash. to_string ( ) ,
258+ } ,
259+ ) ) ,
260+ } ,
261+ LightningBalance :: CounterpartyRevokedOutputClaimable {
262+ channel_id,
263+ counterparty_node_id,
264+ amount_satoshis,
265+ } => ldk_server_protos:: types:: LightningBalance {
266+ balance_type : Some ( CounterpartyRevokedOutputClaimable (
267+ ldk_server_protos:: types:: CounterpartyRevokedOutputClaimable {
268+ channel_id : channel_id. 0 . to_lower_hex_string ( ) ,
269+ counterparty_node_id : counterparty_node_id. to_string ( ) ,
270+ amount_satoshis,
271+ } ,
272+ ) ) ,
273+ } ,
274+ }
275+ }
276+
277+ pub ( crate ) fn pending_sweep_balance_to_proto (
278+ pending_sweep_balance : PendingSweepBalance ,
279+ ) -> ldk_server_protos:: types:: PendingSweepBalance {
280+ match pending_sweep_balance {
281+ PendingSweepBalance :: PendingBroadcast { channel_id, amount_satoshis } => {
282+ ldk_server_protos:: types:: PendingSweepBalance {
283+ balance_type : Some ( PendingBroadcast ( ldk_server_protos:: types:: PendingBroadcast {
284+ channel_id : channel_id. map ( |c| c. 0 . to_lower_hex_string ( ) ) ,
285+ amount_satoshis,
286+ } ) ) ,
287+ }
288+ } ,
289+ PendingSweepBalance :: BroadcastAwaitingConfirmation {
290+ channel_id,
291+ latest_broadcast_height,
292+ latest_spending_txid,
293+ amount_satoshis,
294+ } => ldk_server_protos:: types:: PendingSweepBalance {
295+ balance_type : Some ( BroadcastAwaitingConfirmation (
296+ ldk_server_protos:: types:: BroadcastAwaitingConfirmation {
297+ channel_id : channel_id. map ( |c| c. 0 . to_lower_hex_string ( ) ) ,
298+ latest_broadcast_height,
299+ latest_spending_txid : latest_spending_txid. to_string ( ) ,
300+ amount_satoshis,
301+ } ,
302+ ) ) ,
303+ } ,
304+ PendingSweepBalance :: AwaitingThresholdConfirmations {
305+ channel_id,
306+ latest_spending_txid,
307+ confirmation_hash,
308+ confirmation_height,
309+ amount_satoshis,
310+ } => ldk_server_protos:: types:: PendingSweepBalance {
311+ balance_type : Some ( AwaitingThresholdConfirmations (
312+ ldk_server_protos:: types:: AwaitingThresholdConfirmations {
313+ channel_id : channel_id. map ( |c| c. 0 . to_lower_hex_string ( ) ) ,
314+ latest_spending_txid : latest_spending_txid. to_string ( ) ,
315+ confirmation_hash : confirmation_hash. to_string ( ) ,
316+ confirmation_height,
317+ amount_satoshis,
318+ } ,
319+ ) ) ,
320+ } ,
321+ }
322+ }
0 commit comments