Skip to content

Commit 3e14d69

Browse files
committed
GetInfo: add more fields to response
Add fields: CommitHash, BestBlockHash, Color, NumPeers.
1 parent db1a15b commit 3e14d69

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

lightning_client.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/hex"
77
"errors"
88
"fmt"
9+
"image/color"
910
"io"
1011
"sync"
1112
"time"
@@ -16,6 +17,7 @@ import (
1617
"github.com/btcsuite/btcd/wire"
1718
"github.com/lightningnetwork/lnd/channeldb"
1819
invpkg "github.com/lightningnetwork/lnd/invoices"
20+
"github.com/lightningnetwork/lnd/lncfg"
1921
"github.com/lightningnetwork/lnd/lnrpc"
2022
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
2123
"github.com/lightningnetwork/lnd/lntypes"
@@ -316,15 +318,27 @@ type Info struct {
316318
// Version is the version that lnd is running.
317319
Version string
318320

321+
// CommitHash is the SHA1 commit hash that the daemon is compiled with.
322+
CommitHash string
323+
319324
// BlockHeight is the best block height that lnd has knowledge of.
320325
BlockHeight uint32
321326

327+
// BestHeaderTimeStamp is the best block timestamp known to the wallet.
328+
BestHeaderTimeStamp time.Time
329+
330+
// BestBlockHash is the node's view of the hash of the best block.
331+
BestBlockHash chainhash.Hash
332+
322333
// IdentityPubkey is our node's pubkey.
323334
IdentityPubkey [33]byte
324335

325336
// Alias is our node's alias.
326337
Alias string
327338

339+
// Color is the color of the current node in RGB format.
340+
Color color.RGBA
341+
328342
// Network is the network we are currently operating on.
329343
Network string
330344

@@ -339,9 +353,6 @@ type Info struct {
339353
// public channel graph.
340354
SyncedToGraph bool
341355

342-
// BestHeaderTimeStamp is the best block timestamp known to the wallet.
343-
BestHeaderTimeStamp time.Time
344-
345356
// ActiveChannels is the number of active channels we have.
346357
ActiveChannels uint32
347358

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

351362
// PendingChannels is the number of pending channels we have.
352363
PendingChannels uint32
364+
365+
// NumPeers is the number of peers we connect to.
366+
NumPeers uint32
353367
}
354368

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

1436+
bestBlockHash, err := chainhash.NewHashFromStr(resp.BlockHash)
1437+
if err != nil {
1438+
return nil, fmt.Errorf("failed to parse BlockHash: %w", err)
1439+
}
1440+
1441+
color, err := lncfg.ParseHexColor(resp.Color)
1442+
if err != nil {
1443+
return nil, fmt.Errorf("failed to parse color hex %q: %w",
1444+
resp.Color, err)
1445+
}
1446+
14221447
return &Info{
14231448
Version: resp.Version,
1449+
CommitHash: resp.CommitHash,
14241450
BlockHeight: resp.BlockHeight,
1451+
BestHeaderTimeStamp: time.Unix(resp.BestHeaderTimestamp, 0),
1452+
BestBlockHash: *bestBlockHash,
14251453
IdentityPubkey: pubKeyArray,
14261454
Alias: resp.Alias,
1455+
Color: color,
14271456
Network: resp.Chains[0].Network,
14281457
Uris: resp.Uris,
14291458
SyncedToChain: resp.SyncedToChain,
14301459
SyncedToGraph: resp.SyncedToGraph,
1431-
BestHeaderTimeStamp: time.Unix(resp.BestHeaderTimestamp, 0),
14321460
ActiveChannels: resp.NumActiveChannels,
14331461
InactiveChannels: resp.NumInactiveChannels,
14341462
PendingChannels: resp.NumPendingChannels,
1463+
NumPeers: resp.NumPeers,
14351464
}, nil
14361465
}
14371466

lnd_services_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func (l *lockLNDMock) GetInfo(ctx context.Context, _ *lnrpc.GetInfoRequest,
197197

198198
return &lnrpc.GetInfoResponse{
199199
Chains: []*lnrpc.Chain{{}},
200+
Color: "#112233",
200201
}, err
201202
}
202203

0 commit comments

Comments
 (0)