@@ -41,6 +41,15 @@ type LightningClient interface {
4141 // ListTransactions returns all known transactions of the backing lnd
4242 // node.
4343 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 )
4453}
4554
4655// Info contains info about the connected lnd node.
@@ -384,3 +393,44 @@ func (s *lightningClient) ListTransactions(ctx context.Context) ([]*wire.MsgTx,
384393
385394 return txs , nil
386395}
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