forked from lightninglabs/lndclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
versioner_client.go
71 lines (61 loc) · 1.86 KB
/
versioner_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package lndclient
import (
"context"
"fmt"
"strings"
"time"
"github.com/lightningnetwork/lnd/lnrpc/verrpc"
"google.golang.org/grpc"
)
// VersionerClient exposes the version of lnd.
type VersionerClient interface {
// GetVersion returns the version and build information of the lnd
// daemon.
GetVersion(ctx context.Context) (*verrpc.Version, error)
}
type versionerClient struct {
client verrpc.VersionerClient
readonlyMac serializedMacaroon
timeout time.Duration
}
func newVersionerClient(conn grpc.ClientConnInterface,
readonlyMac serializedMacaroon, timeout time.Duration) *versionerClient {
return &versionerClient{
client: verrpc.NewVersionerClient(conn),
readonlyMac: readonlyMac,
timeout: timeout,
}
}
// GetVersion returns the version and build information of the lnd
// daemon.
//
// NOTE: This method is part of the VersionerClient interface.
func (v *versionerClient) GetVersion(ctx context.Context) (*verrpc.Version,
error) {
rpcCtx, cancel := context.WithTimeout(
v.readonlyMac.WithMacaroonAuth(ctx), v.timeout,
)
defer cancel()
return v.client.GetVersion(rpcCtx, &verrpc.VersionRequest{})
}
// VersionString returns a nice, human readable string of a version returned by
// the VersionerClient, including all build tags.
func VersionString(version *verrpc.Version) string {
short := VersionStringShort(version)
enabledTags := strings.Join(version.BuildTags, ",")
return fmt.Sprintf("%s, build tags '%s'", short, enabledTags)
}
// VersionStringShort returns a nice, human readable string of a version
// returned by the VersionerClient.
func VersionStringShort(version *verrpc.Version) string {
versionStr := fmt.Sprintf(
"v%d.%d.%d", version.AppMajor, version.AppMinor,
version.AppPatch,
)
if version.AppPreRelease != "" {
versionStr = fmt.Sprintf(
"%s-%s", versionStr, version.AppPreRelease,
)
}
return versionStr
}