@@ -41,6 +41,15 @@ type LightningClient interface {
41
41
// ListTransactions returns all known transactions of the backing lnd
42
42
// node.
43
43
ListTransactions (ctx context.Context ) ([]* wire.MsgTx , error )
44
+
45
+ // ChannelBackup retrieves the backup for a particular channel. The
46
+ // backup is returned as an encrypted chanbackup.Single payload.
47
+ ChannelBackup (context.Context , wire.OutPoint ) ([]byte , error )
48
+
49
+ // ChannelBackups retrieves backups for all existing pending open and
50
+ // open channels. The backups are returned as an encrypted
51
+ // chanbackup.Multi payload.
52
+ ChannelBackups (ctx context.Context ) ([]byte , error )
44
53
}
45
54
46
55
// Info contains info about the connected lnd node.
@@ -384,3 +393,44 @@ func (s *lightningClient) ListTransactions(ctx context.Context) ([]*wire.MsgTx,
384
393
385
394
return txs , nil
386
395
}
396
+
397
+ // ChannelBackup retrieves the backup for a particular channel. The backup is
398
+ // returned as an encrypted chanbackup.Single payload.
399
+ func (s * lightningClient ) ChannelBackup (ctx context.Context ,
400
+ channelPoint wire.OutPoint ) ([]byte , error ) {
401
+
402
+ rpcCtx , cancel := context .WithTimeout (ctx , rpcTimeout )
403
+ defer cancel ()
404
+
405
+ rpcCtx = s .adminMac .WithMacaroonAuth (rpcCtx )
406
+ req := & lnrpc.ExportChannelBackupRequest {
407
+ ChanPoint : & lnrpc.ChannelPoint {
408
+ FundingTxid : & lnrpc.ChannelPoint_FundingTxidBytes {
409
+ FundingTxidBytes : channelPoint .Hash [:],
410
+ },
411
+ OutputIndex : channelPoint .Index ,
412
+ },
413
+ }
414
+ resp , err := s .client .ExportChannelBackup (rpcCtx , req )
415
+ if err != nil {
416
+ return nil , err
417
+ }
418
+
419
+ return resp .ChanBackup , nil
420
+ }
421
+
422
+ // ChannelBackups retrieves backups for all existing pending open and open
423
+ // channels. The backups are returned as an encrypted chanbackup.Multi payload.
424
+ func (s * lightningClient ) ChannelBackups (ctx context.Context ) ([]byte , error ) {
425
+ rpcCtx , cancel := context .WithTimeout (ctx , rpcTimeout )
426
+ defer cancel ()
427
+
428
+ rpcCtx = s .adminMac .WithMacaroonAuth (rpcCtx )
429
+ req := & lnrpc.ChanBackupExportRequest {}
430
+ resp , err := s .client .ExportAllChannelBackups (rpcCtx , req )
431
+ if err != nil {
432
+ return nil , err
433
+ }
434
+
435
+ return resp .MultiChanBackup .MultiChanBackup , nil
436
+ }
0 commit comments