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:
commit
736daafb5a
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user