Skip to content

Commit a5f5634

Browse files
committed
lndclient: expose retrieval of channel backups through LightningClient
1 parent 6a078ff commit a5f5634

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

lndclient/lightning_client.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

test/lightning_client_mock.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,16 @@ func (h *mockLightningClient) ListTransactions(
137137
h.lnd.lock.Unlock()
138138
return txs, nil
139139
}
140+
141+
// ChannelBackup retrieves the backup for a particular channel. The
142+
// backup is returned as an encrypted chanbackup.Single payload.
143+
func (h *mockLightningClient) ChannelBackup(context.Context, wire.OutPoint) ([]byte, error) {
144+
return nil, nil
145+
}
146+
147+
// ChannelBackups retrieves backups for all existing pending open and
148+
// open channels. The backups are returned as an encrypted
149+
// chanbackup.Multi payload.
150+
func (h *mockLightningClient) ChannelBackups(ctx context.Context) ([]byte, error) {
151+
return nil, nil
152+
}

0 commit comments

Comments
 (0)