Skip to content

GetInfo: add more fields to response #229

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions lightning_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"image/color"
"io"
"sync"
"time"
Expand All @@ -16,6 +17,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb"
invpkg "github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
"github.com/lightningnetwork/lnd/lntypes"
Expand Down Expand Up @@ -316,15 +318,27 @@ type Info struct {
// Version is the version that lnd is running.
Version string

// CommitHash is the SHA1 commit hash that the daemon is compiled with.
CommitHash string

// BlockHeight is the best block height that lnd has knowledge of.
BlockHeight uint32

// BestHeaderTimeStamp is the best block timestamp known to the wallet.
BestHeaderTimeStamp time.Time

// BestBlockHash is the node's view of the hash of the best block.
BestBlockHash chainhash.Hash

// IdentityPubkey is our node's pubkey.
IdentityPubkey [33]byte

// Alias is our node's alias.
Alias string

// Color is the color of the current node in RGB format.
Color color.RGBA

// Network is the network we are currently operating on.
Network string

Expand All @@ -339,9 +353,6 @@ type Info struct {
// public channel graph.
SyncedToGraph bool

// BestHeaderTimeStamp is the best block timestamp known to the wallet.
BestHeaderTimeStamp time.Time

// ActiveChannels is the number of active channels we have.
ActiveChannels uint32

Expand All @@ -350,6 +361,9 @@ type Info struct {

// PendingChannels is the number of pending channels we have.
PendingChannels uint32

// NumPeers is the number of peers we connect to.
NumPeers uint32
}

// ChannelInfo stores unpacked per-channel info.
Expand Down Expand Up @@ -1419,19 +1433,34 @@ func newInfo(resp *lnrpc.GetInfoResponse) (*Info, error) {
var pubKeyArray [33]byte
copy(pubKeyArray[:], pubKey)

bestBlockHash, err := chainhash.NewHashFromStr(resp.BlockHash)
if err != nil {
return nil, fmt.Errorf("failed to parse BlockHash: %w", err)
}

color, err := lncfg.ParseHexColor(resp.Color)
if err != nil {
return nil, fmt.Errorf("failed to parse color hex %q: %w",
resp.Color, err)
}

return &Info{
Version: resp.Version,
CommitHash: resp.CommitHash,
BlockHeight: resp.BlockHeight,
BestHeaderTimeStamp: time.Unix(resp.BestHeaderTimestamp, 0),
BestBlockHash: *bestBlockHash,
IdentityPubkey: pubKeyArray,
Alias: resp.Alias,
Color: color,
Network: resp.Chains[0].Network,
Uris: resp.Uris,
SyncedToChain: resp.SyncedToChain,
SyncedToGraph: resp.SyncedToGraph,
BestHeaderTimeStamp: time.Unix(resp.BestHeaderTimestamp, 0),
ActiveChannels: resp.NumActiveChannels,
InactiveChannels: resp.NumInactiveChannels,
PendingChannels: resp.NumPendingChannels,
NumPeers: resp.NumPeers,
}, nil
}

Expand Down
Loading