Skip to content

Commit

Permalink
Add options to see wallet and wallet daemon versions (#2257)
Browse files Browse the repository at this point in the history
  • Loading branch information
someone235 authored Dec 26, 2023
1 parent 91e6c6b commit 629faa8
Show file tree
Hide file tree
Showing 10 changed files with 326 additions and 74 deletions.
19 changes: 17 additions & 2 deletions cmd/kaspawallet/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package main

import (
"os"

"github.com/kaspanet/kaspad/infrastructure/config"
"github.com/pkg/errors"
"os"

"github.com/jessevdk/go-flags"
)
Expand All @@ -22,6 +21,8 @@ const (
newAddressSubCmd = "new-address"
dumpUnencryptedDataSubCmd = "dump-unencrypted-data"
startDaemonSubCmd = "start-daemon"
versionSubCmd = "version"
getDaemonVersionSubCmd = "get-daemon-version"
)

const (
Expand All @@ -30,6 +31,7 @@ const (
)

type configFlags struct {
ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"`
config.NetworkFlags
}

Expand Down Expand Up @@ -129,6 +131,13 @@ type dumpUnencryptedDataConfig struct {
config.NetworkFlags
}

type versionConfig struct {
}

type getDaemonVersionConfig struct {
DaemonAddress string `long:"daemonaddress" short:"d" description:"Wallet daemon server to connect to"`
}

func parseCommandLine() (subCommand string, config interface{}) {
cfg := &configFlags{}
parser := flags.NewParser(cfg, flags.PrintErrors|flags.HelpFlag)
Expand Down Expand Up @@ -185,6 +194,9 @@ func parseCommandLine() (subCommand string, config interface{}) {
Listen: defaultListen,
}
parser.AddCommand(startDaemonSubCmd, "Start the wallet daemon", "Start the wallet daemon", startDaemonConf)
parser.AddCommand(versionSubCmd, "Get the wallet version", "Get the wallet version", &versionConfig{})
getDaemonVersionConf := &getDaemonVersionConfig{DaemonAddress: defaultListen}
parser.AddCommand(getDaemonVersionSubCmd, "Get the wallet daemon version", "Get the wallet daemon version", getDaemonVersionConf)

_, err := parser.Parse()
if err != nil {
Expand Down Expand Up @@ -290,6 +302,9 @@ func parseCommandLine() (subCommand string, config interface{}) {
printErrorAndExit(err)
}
config = startDaemonConf
case versionSubCmd:
case getDaemonVersionSubCmd:
config = getDaemonVersionConf
}

return parser.Command.Active.Name, config
Expand Down
263 changes: 193 additions & 70 deletions cmd/kaspawallet/daemon/pb/kaspawalletd.pb.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions cmd/kaspawallet/daemon/pb/kaspawalletd.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ service kaspawalletd {
rpc Send(SendRequest) returns (SendResponse) {}
// Since SignRequest contains a password - this command should only be used on a trusted or secure connection
rpc Sign(SignRequest) returns (SignResponse) {}
rpc GetVersion(GetVersionRequest) returns (GetVersionResponse) {}
}

message GetBalanceRequest {
Expand Down Expand Up @@ -127,3 +128,10 @@ message SignRequest{
message SignResponse{
repeated bytes signedTransactions = 1;
}

message GetVersionRequest{
}

message GetVersionResponse{
string version = 1;
}
40 changes: 40 additions & 0 deletions cmd/kaspawallet/daemon/pb/kaspawalletd_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cmd/kaspawallet/daemon/server/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (s *server) GetBalance(_ context.Context, _ *pb.GetBalanceRequest) (*pb.Get
pending += balances.pending
}

log.Infof("GetBalance request scanned %d UTXOs overall over %d addresses", len(s.utxosSortedByAmount), len(balancesMap))

return &pb.GetBalanceResponse{
Available: available,
Pending: pending,
Expand Down
2 changes: 2 additions & 0 deletions cmd/kaspawallet/daemon/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"fmt"
"github.com/kaspanet/kaspad/version"
"net"
"os"
"sync"
Expand Down Expand Up @@ -59,6 +60,7 @@ func Start(params *dagconfig.Params, listen, rpcServer string, keysFilePath stri
profiling.Start(profile, log)
}

log.Infof("Version %s", version.Version())
listener, err := net.Listen("tcp", listen)
if err != nil {
return (errors.Wrapf(err, "Error listening to TCP on %s", listen))
Expand Down
16 changes: 16 additions & 0 deletions cmd/kaspawallet/daemon/server/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package server

import (
"context"
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
"github.com/kaspanet/kaspad/version"
)

func (s *server) GetVersion(_ context.Context, _ *pb.GetVersionRequest) (*pb.GetVersionResponse, error) {
s.lock.RLock()
defer s.lock.RUnlock()

return &pb.GetVersionResponse{
Version: version.Version(),
}, nil
}
26 changes: 26 additions & 0 deletions cmd/kaspawallet/get_daemon_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"context"
"fmt"
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/client"
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
)

func getDaemonVersion(conf *getDaemonVersionConfig) error {
daemonClient, tearDown, err := client.Connect(conf.DaemonAddress)
if err != nil {
return err
}
defer tearDown()

ctx, cancel := context.WithTimeout(context.Background(), daemonTimeout)
defer cancel()
response, err := daemonClient.GetVersion(ctx, &pb.GetVersionRequest{})
if err != nil {
return err
}
fmt.Println(response.Version)

return nil
}
9 changes: 7 additions & 2 deletions cmd/kaspawallet/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package main

import "github.com/pkg/errors"
import (
"github.com/pkg/errors"
)

func main() {
subCmd, config := parseCommandLine()

var err error
switch subCmd {
case createSubCmd:
Expand All @@ -31,6 +32,10 @@ func main() {
err = startDaemon(config.(*startDaemonConfig))
case sweepSubCmd:
err = sweep(config.(*sweepConfig))
case versionSubCmd:
showVersion()
case getDaemonVersionSubCmd:
err = getDaemonVersion(config.(*getDaemonVersionConfig))
default:
err = errors.Errorf("Unknown sub-command '%s'\n", subCmd)
}
Expand Down
15 changes: 15 additions & 0 deletions cmd/kaspawallet/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"fmt"
"github.com/kaspanet/kaspad/version"
"os"
"path/filepath"
"strings"
)

func showVersion() {
appName := filepath.Base(os.Args[0])
appName = strings.TrimSuffix(appName, filepath.Ext(appName))
fmt.Println(appName, "version", version.Version())
}

0 comments on commit 629faa8

Please sign in to comment.