-
Notifications
You must be signed in to change notification settings - Fork 123
lndclient: extend LightningClient with ListChannels and RouterClient with keysend #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import ( | |
| "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" | ||
| "github.com/lightningnetwork/lnd/lntypes" | ||
| "github.com/lightningnetwork/lnd/lnwire" | ||
| "github.com/lightningnetwork/lnd/routing/route" | ||
| "github.com/lightningnetwork/lnd/zpay32" | ||
| "google.golang.org/grpc" | ||
| "google.golang.org/grpc/codes" | ||
|
|
@@ -46,6 +47,9 @@ type LightningClient interface { | |
| // node. | ||
| ListTransactions(ctx context.Context) ([]*wire.MsgTx, error) | ||
|
|
||
| // ListChannels retrieves all channels of the backing lnd node. | ||
| ListChannels(ctx context.Context) ([]ChannelInfo, 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) | ||
|
|
@@ -65,6 +69,29 @@ type Info struct { | |
| Uris []string | ||
| } | ||
|
|
||
| // ChannelInfo stores unpacked per-channel info. | ||
| type ChannelInfo struct { | ||
| // Active indecates whether the channel is active. | ||
| Active bool | ||
|
|
||
| // ChannelID holds the unique channel ID for the channel. The first 3 bytes | ||
| // are the block height, the next 3 the index within the block, and the last | ||
| // 2 bytes are the /output index for the channel. | ||
| ChannelID uint64 | ||
|
|
||
| // PubKeyBytes is the raw bytes of the public key of the remote node. | ||
| PubKeyBytes route.Vertex | ||
|
|
||
| // Capacity is the total amount of funds held in this channel. | ||
| Capacity btcutil.Amount | ||
|
|
||
| // LocalBalance is the current balance of this node in this channel. | ||
| LocalBalance btcutil.Amount | ||
|
|
||
| // RemoteBalance is the counterparty's current balance in this channel. | ||
| RemoteBalance btcutil.Amount | ||
| } | ||
|
|
||
| var ( | ||
| // ErrMalformedServerResponse is returned when the swap and/or prepay | ||
| // invoice is malformed. | ||
|
|
@@ -495,6 +522,41 @@ func (s *lightningClient) ListTransactions(ctx context.Context) ([]*wire.MsgTx, | |
| return txs, nil | ||
| } | ||
|
|
||
| // ListChannels retrieves all channels of the backing lnd node. | ||
| func (s *lightningClient) ListChannels(ctx context.Context) ( | ||
| []ChannelInfo, error) { | ||
|
|
||
| rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout) | ||
| defer cancel() | ||
|
|
||
| response, err := s.client.ListChannels( | ||
| s.adminMac.WithMacaroonAuth(rpcCtx), | ||
| &lnrpc.ListChannelsRequest{}, | ||
| ) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| result := make([]ChannelInfo, len(response.Channels)) | ||
| for i, channel := range response.Channels { | ||
| remoteVertex, err := route.NewVertexFromStr(channel.RemotePubkey) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Future devs will thank you for the luxury of not having to parse everywhere :) |
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| result[i] = ChannelInfo{ | ||
| Active: channel.Active, | ||
| ChannelID: channel.ChanId, | ||
| PubKeyBytes: remoteVertex, | ||
| Capacity: btcutil.Amount(channel.Capacity), | ||
| LocalBalance: btcutil.Amount(channel.LocalBalance), | ||
| RemoteBalance: btcutil.Amount(channel.RemoteBalance), | ||
| } | ||
| } | ||
|
|
||
| return result, 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, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[]*ChannelInfo?