2
0
mirror of https://github.com/lightninglabs/loop synced 2024-11-08 01:10:29 +00:00

Merge pull request #143 from wpaulino/lightning-client-channel-backups

lndclient: expose retrieval of channel backups through LightningClient
This commit is contained in:
Oliver Gugger 2020-02-11 09:27:36 +01:00 committed by GitHub
commit 736daafb5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 0 deletions

View File

@ -41,6 +41,15 @@ type LightningClient interface {
// ListTransactions returns all known transactions of the backing lnd
// node.
ListTransactions(ctx context.Context) ([]*wire.MsgTx, error)
// ChannelBackup retrieves the backup for a particular channel. The
// backup is returned as an encrypted chanbackup.Single payload.
ChannelBackup(context.Context, wire.OutPoint) ([]byte, error)
// ChannelBackups retrieves backups for all existing pending open and
// open channels. The backups are returned as an encrypted
// chanbackup.Multi payload.
ChannelBackups(ctx context.Context) ([]byte, error)
}
// Info contains info about the connected lnd node.
@ -384,3 +393,44 @@ func (s *lightningClient) ListTransactions(ctx context.Context) ([]*wire.MsgTx,
return txs, nil
}
// ChannelBackup retrieves the backup for a particular channel. The backup is
// returned as an encrypted chanbackup.Single payload.
func (s *lightningClient) ChannelBackup(ctx context.Context,
channelPoint wire.OutPoint) ([]byte, error) {
rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
defer cancel()
rpcCtx = s.adminMac.WithMacaroonAuth(rpcCtx)
req := &lnrpc.ExportChannelBackupRequest{
ChanPoint: &lnrpc.ChannelPoint{
FundingTxid: &lnrpc.ChannelPoint_FundingTxidBytes{
FundingTxidBytes: channelPoint.Hash[:],
},
OutputIndex: channelPoint.Index,
},
}
resp, err := s.client.ExportChannelBackup(rpcCtx, req)
if err != nil {
return nil, err
}
return resp.ChanBackup, nil
}
// ChannelBackups retrieves backups for all existing pending open and open
// channels. The backups are returned as an encrypted chanbackup.Multi payload.
func (s *lightningClient) ChannelBackups(ctx context.Context) ([]byte, error) {
rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
defer cancel()
rpcCtx = s.adminMac.WithMacaroonAuth(rpcCtx)
req := &lnrpc.ChanBackupExportRequest{}
resp, err := s.client.ExportAllChannelBackups(rpcCtx, req)
if err != nil {
return nil, err
}
return resp.MultiChanBackup.MultiChanBackup, nil
}

View File

@ -137,3 +137,16 @@ func (h *mockLightningClient) ListTransactions(
h.lnd.lock.Unlock()
return txs, nil
}
// ChannelBackup retrieves the backup for a particular channel. The
// backup is returned as an encrypted chanbackup.Single payload.
func (h *mockLightningClient) ChannelBackup(context.Context, wire.OutPoint) ([]byte, error) {
return nil, nil
}
// ChannelBackups retrieves backups for all existing pending open and
// open channels. The backups are returned as an encrypted
// chanbackup.Multi payload.
func (h *mockLightningClient) ChannelBackups(ctx context.Context) ([]byte, error) {
return nil, nil
}