diff --git a/go.mod b/go.mod index 44d0587..1ac2424 100644 --- a/go.mod +++ b/go.mod @@ -52,7 +52,7 @@ require ( github.com/go-errors/errors v1.0.1 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/go-viper/mapstructure/v2 v2.2.1 // indirect + github.com/go-viper/mapstructure/v2 v2.3.0 // indirect github.com/gofrs/uuid v4.2.0+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt/v4 v4.5.2 // indirect diff --git a/go.sum b/go.sum index 7a72c05..7d844fe 100644 --- a/go.sum +++ b/go.sum @@ -165,8 +165,8 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= -github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/go-viper/mapstructure/v2 v2.3.0 h1:27XbWsHIqhbdR5TIC911OfYvgSaW93HM+dX7970Q7jk= +github.com/go-viper/mapstructure/v2 v2.3.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0= diff --git a/lightning_client.go b/lightning_client.go index 8bfac18..3fba6d3 100644 --- a/lightning_client.go +++ b/lightning_client.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "errors" "fmt" + "image/color" "io" "sync" "time" @@ -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" @@ -325,15 +327,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 @@ -348,9 +362,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 @@ -359,6 +370,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. @@ -1430,19 +1444,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 } diff --git a/lnd_services_test.go b/lnd_services_test.go index 401501b..708bbfc 100644 --- a/lnd_services_test.go +++ b/lnd_services_test.go @@ -197,6 +197,7 @@ func (l *lockLNDMock) GetInfo(ctx context.Context, _ *lnrpc.GetInfoRequest, return &lnrpc.GetInfoResponse{ Chains: []*lnrpc.Chain{{}}, + Color: "#112233", }, err } diff --git a/tools/go.mod b/tools/go.mod index 4b0e23b..530bcae 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -61,7 +61,7 @@ require ( github.com/go-toolsmith/astp v1.1.0 // indirect github.com/go-toolsmith/strparse v1.1.0 // indirect github.com/go-toolsmith/typep v1.1.0 // indirect - github.com/go-viper/mapstructure/v2 v2.2.1 // indirect + github.com/go-viper/mapstructure/v2 v2.3.0 // indirect github.com/go-xmlfmt/xmlfmt v1.1.3 // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/gofrs/flock v0.12.1 // indirect diff --git a/tools/go.sum b/tools/go.sum index 491f84e..e5364d8 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -191,8 +191,8 @@ github.com/go-toolsmith/strparse v1.1.0 h1:GAioeZUK9TGxnLS+qfdqNbA4z0SSm5zVNtCQi github.com/go-toolsmith/strparse v1.1.0/go.mod h1:7ksGy58fsaQkGQlY8WVoBFNyEPMGuJin1rfoPS4lBSQ= github.com/go-toolsmith/typep v1.1.0 h1:fIRYDyF+JywLfqzyhdiHzRop/GQDxxNhLGQ6gFUNHus= github.com/go-toolsmith/typep v1.1.0/go.mod h1:fVIw+7zjdsMxDA3ITWnH1yOiw1rnTQKCsF/sk2H/qig= -github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= -github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/go-viper/mapstructure/v2 v2.3.0 h1:27XbWsHIqhbdR5TIC911OfYvgSaW93HM+dX7970Q7jk= +github.com/go-viper/mapstructure/v2 v2.3.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/go-xmlfmt/xmlfmt v1.1.3 h1:t8Ey3Uy7jDSEisW2K3somuMKIpzktkWptA0iFCnRUWY= github.com/go-xmlfmt/xmlfmt v1.1.3/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=