From b33b4b476fff28bd8a6ff099f44ad675aacefe95 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Wed, 29 Sep 2021 02:04:48 -0400 Subject: [PATCH] working towards lightwalletd deb package --- build.sh | 12 ++++++++++++ cmd/server/main.go | 9 +++++++++ cmd/server/main_test.go | 32 ++++++++++++++++++++++++++++++++ frontend/service.go | 2 +- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 cmd/server/main_test.go diff --git a/build.sh b/build.sh index 7d58360..f9a9794 100755 --- a/build.sh +++ b/build.sh @@ -8,10 +8,22 @@ if ! [ -x "$(command -v go)" ]; then exit 1 fi +echo "" +echo "Welcome to the Hush magic folks..." +echo "" +echo ".------..------..------..------..------..------..------..------..------..------..------..------." +echo "|L.--. ||I.--. ||G.--. ||H.--. ||T.--. ||W.--. ||A.--. ||L.--. ||L.--. ||E.--. ||T.--. ||D.--. |" +echo "| :/\: || (\/) || :/\: || :/\: || :/\: || :/\: || (\/) || :/\: || :/\: || (\/) || :/\: || :/\: |" +echo "| (__) || :\/: || :\/: || (__) || (__) || :\/: || :\/: || (__) || (__) || :\/: || (__) || (__) |" +echo "| '--'L|| '--'I|| '--'G|| '--'H|| '--'T|| '--'W|| '--'A|| '--'L|| '--'L|| '--'E|| '--'T|| '--'D|" +echo "+------'+------'+------'+------'+------'+------'+------'+------'+------'+------'+------'+------'" + # now to compiling... +echo "" echo "You have go installed, so starting to compile hush lightwalletd for you..." cd `pwd`/cmd/server go build -o lightwalletd main.go mv lightwalletd `pwd`/../../lightwalletd +echo "" echo "lightwalletd is now compiled for you." echo "for options, run ./lightwalletd --help" diff --git a/cmd/server/main.go b/cmd/server/main.go index 31ef6b9..1c72be3 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,6 +3,7 @@ package main import ( "context" "flag" + "fmt" "net" "os" "os/signal" @@ -97,6 +98,14 @@ func main() { flag.StringVar(&opts.hush3ConfPath, "conf-file", "", "conf file to pull RPC creds from") flag.IntVar(&opts.cacheSize, "cache-size", 40000, "number of blocks to hold in the cache") + // creating --version so help2man will work + if len(os.Args) > 1 && (os.Args[1] == "--version" || os.Args[1] == "-v") { + // TODO find a better method than hardcode the version number here + fmt.Printf("hush lightwalletd version 0.1.1\n") + os.Exit(0) + } + // TODO determine why help2man is now complaining about --help even after I tried creating one... + // TODO prod metrics // TODO support config from file and env vars flag.Parse() diff --git a/cmd/server/main_test.go b/cmd/server/main_test.go new file mode 100644 index 0000000..77cf485 --- /dev/null +++ b/cmd/server/main_test.go @@ -0,0 +1,32 @@ +// Copyright 2021 The Hush developers +// Released under the GPLv3 +package main + +import ( + "os" + "testing" +) + +// TestFileExists checks whether or not the file exists +func TestFileExists(t *testing.T) { + if fileExists("nonexistent-file") { + t.Fatal("fileExists unexpected success") + } + // If the path exists but is a directory, should return false + if fileExists(".") { + t.Fatal("fileExists unexpected success") + } + // The following file should exist, it's what's being tested + if !fileExists("main.go") { + t.Fatal("fileExists failed") + } +} + +// fileExists checks if file exists and is not directory to prevent further errors +func fileExists(filename string) bool { + info, err := os.Stat(filename) + if os.IsNotExist(err) { + return false + } + return !info.IsDir() +} diff --git a/frontend/service.go b/frontend/service.go index 08f45ea..998628e 100644 --- a/frontend/service.go +++ b/frontend/service.go @@ -249,7 +249,7 @@ func (s *SqlStreamer) GetLightdInfo(ctx context.Context, in *walletrpc.Empty) (* // TODO these are called Error but they aren't at the moment. // A success will return code 0 and message txhash. return &walletrpc.LightdInfo{ - Version: "0.1-hushlightd", + Version: "0.1.1-hushlightd", Vendor: "Silentdragonlite LightWalletD", TaddrSupport: true, ChainName: chainName,