diff --git a/cmd/cmd.go b/cmd/cmd.go index 3e3ad609..dc05a54d 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -7,10 +7,10 @@ import ( "os" "time" + vgterm "code.vegaprotocol.io/shared/libs/term" "code.vegaprotocol.io/shared/paths" "code.vegaprotocol.io/vegawallet/cmd/flags" "code.vegaprotocol.io/vegawallet/cmd/printer" - vgterm "code.vegaprotocol.io/vegawallet/libs/term" netstore "code.vegaprotocol.io/vegawallet/network/store/v1" "code.vegaprotocol.io/vegawallet/wallet" "code.vegaprotocol.io/vegawallet/wallets" diff --git a/cmd/command_send.go b/cmd/command_send.go index e27edd5f..57184eb3 100644 --- a/cmd/command_send.go +++ b/cmd/command_send.go @@ -8,11 +8,11 @@ import ( api "code.vegaprotocol.io/protos/vega/api/v1" walletpb "code.vegaprotocol.io/protos/vega/wallet/v1" + vglog "code.vegaprotocol.io/shared/libs/zap" "code.vegaprotocol.io/vegawallet/cmd/cli" "code.vegaprotocol.io/vegawallet/cmd/flags" "code.vegaprotocol.io/vegawallet/cmd/printer" wcommands "code.vegaprotocol.io/vegawallet/commands" - vglog "code.vegaprotocol.io/vegawallet/libs/zap" "code.vegaprotocol.io/vegawallet/network" "code.vegaprotocol.io/vegawallet/node" "code.vegaprotocol.io/vegawallet/wallets" diff --git a/cmd/flags/passphrase.go b/cmd/flags/passphrase.go index bb65bbe1..57779706 100644 --- a/cmd/flags/passphrase.go +++ b/cmd/flags/passphrase.go @@ -7,7 +7,7 @@ import ( "strings" vgfs "code.vegaprotocol.io/shared/libs/fs" - vgterm "code.vegaprotocol.io/vegawallet/libs/term" + vgterm "code.vegaprotocol.io/shared/libs/term" "golang.org/x/term" ) diff --git a/cmd/network_delete.go b/cmd/network_delete.go index daed057e..339c1be9 100644 --- a/cmd/network_delete.go +++ b/cmd/network_delete.go @@ -4,11 +4,11 @@ import ( "fmt" "io" + vgterm "code.vegaprotocol.io/shared/libs/term" "code.vegaprotocol.io/shared/paths" "code.vegaprotocol.io/vegawallet/cmd/cli" "code.vegaprotocol.io/vegawallet/cmd/flags" "code.vegaprotocol.io/vegawallet/cmd/printer" - vgterm "code.vegaprotocol.io/vegawallet/libs/term" "code.vegaprotocol.io/vegawallet/network" netstore "code.vegaprotocol.io/vegawallet/network/store/v1" "github.com/spf13/cobra" diff --git a/cmd/root.go b/cmd/root.go index ed864ee0..8b9a35b3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -11,6 +11,8 @@ import ( "code.vegaprotocol.io/vegawallet/cmd/flags" "code.vegaprotocol.io/vegawallet/cmd/printer" "code.vegaprotocol.io/vegawallet/version" + + vgversion "code.vegaprotocol.io/shared/libs/version" "github.com/blang/semver/v4" "github.com/spf13/cobra" ) @@ -39,7 +41,7 @@ func NewCmdRoot(w io.Writer) *cobra.Command { vh := func() (*semver.Version, error) { ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) defer cancel() - v, err := version.Check(version.BuildReleasesRequestFromGithub(ctx), version.Version) + v, err := version.Check(vgversion.BuildGithubReleasesRequestFrom(ctx, version.ReleasesAPI), version.Version) if err != nil { return nil, fmt.Errorf("couldn't check latest releases: %w", err) } @@ -87,7 +89,7 @@ func BuildCmdRoot(w io.Writer, vh CheckVersionHandler) *cobra.Command { if v != nil { p.Text("Version ").SuccessText(v.String()).Text(" is available. Your current version is ").DangerText(version.Version).Text(".").NextLine() - p.Text("Download the latest version at: ").Underline(version.GetReleaseURL(v)).NextSection() + p.Text("Download the latest version at: ").Underline(vgversion.GetGithubReleaseURL(version.ReleasesAPI, v)).NextSection() } } return nil diff --git a/cmd/service_run.go b/cmd/service_run.go index 6ba7761b..e6f6742d 100644 --- a/cmd/service_run.go +++ b/cmd/service_run.go @@ -11,11 +11,11 @@ import ( "syscall" "text/template" + vglog "code.vegaprotocol.io/shared/libs/zap" "code.vegaprotocol.io/shared/paths" "code.vegaprotocol.io/vegawallet/cmd/cli" "code.vegaprotocol.io/vegawallet/cmd/flags" "code.vegaprotocol.io/vegawallet/cmd/printer" - vglog "code.vegaprotocol.io/vegawallet/libs/zap" "code.vegaprotocol.io/vegawallet/network" netstore "code.vegaprotocol.io/vegawallet/network/store/v1" "code.vegaprotocol.io/vegawallet/node" diff --git a/cmd/tx_send.go b/cmd/tx_send.go index 8f011e28..f802035e 100644 --- a/cmd/tx_send.go +++ b/cmd/tx_send.go @@ -8,10 +8,10 @@ import ( api "code.vegaprotocol.io/protos/vega/api/v1" commandspb "code.vegaprotocol.io/protos/vega/commands/v1" + vglog "code.vegaprotocol.io/shared/libs/zap" "code.vegaprotocol.io/vegawallet/cmd/cli" "code.vegaprotocol.io/vegawallet/cmd/flags" "code.vegaprotocol.io/vegawallet/cmd/printer" - vglog "code.vegaprotocol.io/vegawallet/libs/zap" "code.vegaprotocol.io/vegawallet/network" "code.vegaprotocol.io/vegawallet/node" "github.com/golang/protobuf/proto" diff --git a/cmd/wallet_delete.go b/cmd/wallet_delete.go index bb0c7b33..9f32f2ec 100644 --- a/cmd/wallet_delete.go +++ b/cmd/wallet_delete.go @@ -5,10 +5,10 @@ import ( "fmt" "io" + vgterm "code.vegaprotocol.io/shared/libs/term" "code.vegaprotocol.io/vegawallet/cmd/cli" "code.vegaprotocol.io/vegawallet/cmd/flags" "code.vegaprotocol.io/vegawallet/cmd/printer" - vgterm "code.vegaprotocol.io/vegawallet/libs/term" "code.vegaprotocol.io/vegawallet/wallets" "github.com/spf13/cobra" ) diff --git a/go.mod b/go.mod index be464b72..87d45692 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,13 @@ go 1.17 require ( code.vegaprotocol.io/protos v0.47.1-0.20220127103033-82bb68d654eb - code.vegaprotocol.io/shared v0.0.0-20211015074835-9ed837d93090 + code.vegaprotocol.io/shared v0.0.0-20220127162227-dbe0bfac4efa github.com/blang/semver/v4 v4.0.0 github.com/cenkalti/backoff/v4 v4.0.2 github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 github.com/golang/mock v1.4.3 github.com/golang/protobuf v1.4.3 github.com/julienschmidt/httprouter v1.3.0 - github.com/mattn/go-isatty v0.0.13 github.com/muesli/termenv v0.9.0 github.com/oasisprotocol/curve25519-voi v0.0.0-20210716083614-f38f8e8b0b84 github.com/rs/cors v1.7.0 @@ -20,36 +19,30 @@ require ( github.com/stretchr/testify v1.7.0 github.com/tyler-smith/go-bip39 v1.1.0 github.com/vegaprotocol/go-slip10 v0.1.0 - go.uber.org/zap v1.13.0 - golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 + go.uber.org/zap v1.20.0 + golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b google.golang.org/grpc v1.38.0 ) require ( - github.com/BurntSushi/toml v0.3.1 // indirect github.com/adrg/xdg v0.3.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/zannen/toml v0.3.2 // indirect - go.uber.org/atomic v1.5.0 // indirect - go.uber.org/multierr v1.3.0 // indirect - go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee // indirect + go.uber.org/atomic v1.7.0 // indirect + go.uber.org/multierr v1.6.0 // indirect golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect - golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect - golang.org/x/mod v0.4.2 // indirect golang.org/x/net v0.0.0-20210610132358-84b48f89b13b // indirect golang.org/x/text v0.3.6 // indirect - golang.org/x/tools v0.1.2 // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4 // indirect google.golang.org/protobuf v1.26.0-rc.1 // indirect - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect - honnef.co/go/tools v0.0.1-2019.2.3 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 310f7212..4edcdcd8 100644 --- a/go.sum +++ b/go.sum @@ -12,10 +12,9 @@ cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2k cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= code.vegaprotocol.io/protos v0.47.1-0.20220127103033-82bb68d654eb h1:P78Y9OnURVweFaErPyQXmbQDHsgGaI0ZImFVPuH3Tek= code.vegaprotocol.io/protos v0.47.1-0.20220127103033-82bb68d654eb/go.mod h1:KqJcg62sUHV0qEhlZIZojEypzk3V1ZE3tBS+wdqjddU= -code.vegaprotocol.io/shared v0.0.0-20211015074835-9ed837d93090 h1:SF7ZRvZ/JASJNEQigbuUwk1rQuugLy6gqbOFs8D8VXI= -code.vegaprotocol.io/shared v0.0.0-20211015074835-9ed837d93090/go.mod h1:dmahiiphuDJvjXXDvQvo22tFPx7yk9wW8z1glU/JgHE= +code.vegaprotocol.io/shared v0.0.0-20220127162227-dbe0bfac4efa h1:9w5f5T/ufidwfEf58qIlgBalpoIwza4MZM24JG9P9dU= +code.vegaprotocol.io/shared v0.0.0-20220127162227-dbe0bfac4efa/go.mod h1:TIOZeN20FcXwKSdQAgHfUQOwGoK82MihSwetxgdKIMA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= @@ -46,6 +45,8 @@ github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6l github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -284,8 +285,9 @@ github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA= github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -481,16 +483,20 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= +go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= +go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +go.uber.org/zap v1.20.0 h1:N4oPlghZwYG55MlU6LXk/Zp00FVNE9X9wrYO8CEs4lc= +go.uber.org/zap v1.20.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -525,8 +531,6 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= @@ -535,7 +539,6 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -623,8 +626,9 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE= @@ -664,12 +668,10 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA= -golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -760,15 +762,16 @@ gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= diff --git a/libs/term/tty.go b/libs/term/tty.go deleted file mode 100644 index 134c4750..00000000 --- a/libs/term/tty.go +++ /dev/null @@ -1,15 +0,0 @@ -package term - -import ( - "os" - - "github.com/mattn/go-isatty" -) - -func HasTTY() bool { - return isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) -} - -func HasNoTTY() bool { - return !HasTTY() -} diff --git a/libs/zap/zap.go b/libs/zap/zap.go deleted file mode 100644 index c9eb64ce..00000000 --- a/libs/zap/zap.go +++ /dev/null @@ -1,17 +0,0 @@ -package zap - -import ( - "fmt" - - "go.uber.org/zap" -) - -func Sync(logger *zap.Logger) func() { - return func() { - err := logger.Sync() - if err != nil { - // This is the ultimate warning, as we can't do anything else. - fmt.Printf("couldn't flush logger: %v", err) //nolint:forbidigo - } - } -} diff --git a/version/adapter.go b/version/adapter.go deleted file mode 100644 index 85bca16e..00000000 --- a/version/adapter.go +++ /dev/null @@ -1,60 +0,0 @@ -package version - -import ( - "context" - "encoding/json" - "fmt" - "io" - "net/http" -) - -const ReleaseAPI = "https://api.github.com/repos/vegaprotocol/vegawallet/releases" - -type ReleasesGetter func() ([]string, error) - -type releaseResponse struct { - Name string `json:"name"` -} - -func BuildReleasesRequestFromGithub(ctx context.Context) ReleasesGetter { - return func() ([]string, error) { - req, err := http.NewRequestWithContext(ctx, http.MethodGet, ReleaseAPI, nil) - if err != nil { - return nil, fmt.Errorf("couldn't build request: %w", err) - } - req.Header.Add("Accept", "application/vnd.github.v3+json") - - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - return nil, fmt.Errorf("couldn't deliver request: %w", err) - } - defer resp.Body.Close() - - body, err := io.ReadAll(resp.Body) - if err != nil { - return nil, fmt.Errorf("couldn't read response body: %w", err) - } - - responses := []releaseResponse{} - if err = json.Unmarshal(body, &responses); err != nil { - // try to parse as a general error message which would be useful information - // to know eg. if we were blocked due to githubs rate-limiting - m := struct { - Message string `json:"message"` - }{} - if mErr := json.Unmarshal(body, &m); mErr == nil { - return nil, fmt.Errorf("couldn't read response message: %s: %w", m.Message, err) - } - - return nil, fmt.Errorf("couldn't unmarshal response body: %w", err) - } - - releases := make([]string, 0, len(responses)) - for _, response := range responses { - releases = append(releases, response.Name) - } - - return releases, nil - } -} diff --git a/version/version.go b/version/version.go index f5343c8c..fd7977f3 100644 --- a/version/version.go +++ b/version/version.go @@ -1,14 +1,13 @@ package version import ( - "fmt" - "strings" + vgversion "code.vegaprotocol.io/shared/libs/version" "github.com/blang/semver/v4" ) const ( - TaggedReleaseURL = "https://github.com/vegaprotocol/vegawallet/releases/tag" + ReleasesAPI = "https://api.github.com/repos/vegaprotocol/vegawallet/releases" defaultVersionHash = "unknown" defaultVersion = "v0.12.0+dev" ) @@ -24,13 +23,7 @@ var ( ) func IsUnreleased() bool { - v, err := extractVersionFromRelease(Version) - if err != nil { - // unsupported version, considered unreleased - return true - } - - return v.isDevelopmentVersion + return vgversion.IsUnreleased(Version) } type GetVersionResponse struct { @@ -45,92 +38,6 @@ func GetVersionInfo() *GetVersionResponse { } } -// Check returns a newer version, or an error or nil for both -// if no error happened, and no updates are needed. -func Check(releasesGetterFn ReleasesGetter, currentRelease string) (*semver.Version, error) { - releases, err := releasesGetterFn() - if err != nil { - return nil, fmt.Errorf("couldn't get releases: %w", err) - } - - currentVersion, err := extractVersionFromRelease(currentRelease) - if err != nil { - return nil, fmt.Errorf("couldn't extract version from release: %w", err) - } - latestVersion := currentVersion - - var updateAvailable bool - for _, release := range releases { - comparedVersion, err := extractVersionFromRelease(release) - if err != nil { - // unsupported version - continue - } - - if shouldUpdate(latestVersion, comparedVersion) { - updateAvailable = true - latestVersion = comparedVersion - } - } - - if !updateAvailable { - return nil, nil - } - - return latestVersion.version, nil -} - -func GetReleaseURL(v *semver.Version) string { - return fmt.Sprintf("%v/v%v", TaggedReleaseURL, v) -} - -func shouldUpdate(latestVersion *cachedVersion, comparedVersion *cachedVersion) bool { - if latestVersion.isStable && !comparedVersion.isStable { - return false - } - - if latestVersion.isDevelopmentVersion && nonDevelopmentVersionAvailable(latestVersion, comparedVersion) { - return true - } - - return comparedVersion.version.GT(*latestVersion.version) -} - -// nonDevelopmentVersionAvailable verifies if the compared version is the -// non-development equivalent of the latest version. -// For example, 0.9.0-pre1 is the non-development version of 0.9.0-pre1+dev. -// In semantic versioning, we don't compare the `build` annotation, so verifying -// equality is safe. -func nonDevelopmentVersionAvailable(latestVersion *cachedVersion, comparedVersion *cachedVersion) bool { - return comparedVersion.version.EQ(*latestVersion.version) -} - -func extractVersionFromRelease(release string) (*cachedVersion, error) { - version, err := semver.New(strings.TrimPrefix(release, "v")) - return asCachedVersion(version), err -} - -type cachedVersion struct { - // version is the original version - version *semver.Version - // isDevelopmentVersion tells if the version has a `dev` build annotation. - isDevelopmentVersion bool - // isStable tells if the version has any pre-release annotations. - isStable bool -} - -func asCachedVersion(v *semver.Version) *cachedVersion { - lv := &cachedVersion{ - version: v, - } - - for _, build := range v.Build { - if build == "dev" { - lv.isDevelopmentVersion = true - } - } - - lv.isStable = !lv.isDevelopmentVersion && len(v.Pre) == 0 - - return lv +func Check(releasesGetterFn vgversion.ReleasesGetter, currentRelease string) (*semver.Version, error) { + return vgversion.Check(releasesGetterFn, currentRelease) } diff --git a/version/version_test.go b/version/version_test.go deleted file mode 100644 index 2c5ac3f2..00000000 --- a/version/version_test.go +++ /dev/null @@ -1,162 +0,0 @@ -package version_test - -import ( - "testing" - - "code.vegaprotocol.io/vegawallet/version" - "github.com/blang/semver/v4" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestCheckVersion(t *testing.T) { - t.Run("Checking current version succeeds", testCheckingCurrentVersionSucceeds) - t.Run("Verifying unreleased version succeeds", testVerifyingUnreleasedVersionSucceeds) -} - -func testCheckingCurrentVersionSucceeds(t *testing.T) { - tcs := []struct { - name string - currentVersion string - releases []string - expectedResult *semver.Version - }{ - { - name: "stable release against older stable releases should not update", - currentVersion: "v0.4.0", - releases: []string{"v0.2.0", "v0.3.0"}, - expectedResult: nil, // means no update - }, { - name: "stable release against newer stable releases should update to latest stable release", - currentVersion: "v0.1.0", - releases: []string{"v0.2.0", "v0.3.0"}, - expectedResult: toSemVer(t, "0.3.0"), - }, { - name: "stable release against same stable release should not update", - currentVersion: "v0.3.0", - releases: []string{"v0.2.0", "v0.3.0"}, - expectedResult: nil, // means no update - }, { - name: "stable against newer pre-release should update to latest stable release", - currentVersion: "v0.1.0", - releases: []string{"v0.2.0", "v0.3.0-alpha"}, - expectedResult: toSemVer(t, "0.2.0"), - }, { - name: "stable release against older pre-release should not update", - currentVersion: "v0.3.0", - releases: []string{"v0.2.0", "v0.3.0-alpha"}, - expectedResult: nil, // means no update - }, { - name: "pre-release against newer stable release should update to latest stable release", - currentVersion: "v0.3.0-alpha", - releases: []string{"v0.2.0", "v0.3.0"}, - expectedResult: toSemVer(t, "0.3.0"), - }, { - name: "pre-release against older stable release should not update", - currentVersion: "v0.4.0-alpha", - releases: []string{"v0.2.0", "v0.3.0"}, - expectedResult: nil, // means no update - }, { - name: "pre-release against newer pre-release should update to latest pre-release", - currentVersion: "v0.4.0-alpha", - releases: []string{"v0.2.0", "v0.3.0", "v0.4.0-alpha", "v0.4.0-beta"}, - expectedResult: toSemVer(t, "0.4.0-beta"), - }, { - name: "pre-release against same pre-release should not update", - currentVersion: "v0.4.0-alpha", - releases: []string{"v0.2.0", "v0.3.0", "v0.4.0-alpha"}, - expectedResult: nil, // means no update - }, { - name: "pre-release against newer pre-release separated by stable releases should update to latest stable release", - currentVersion: "v0.2.0-alpha", - releases: []string{"v0.2.0-alpha", "v0.2.0", "v0.3.0-alpha", "v0.3.0", "v0.3.1", "v0.4.0-alpha"}, - expectedResult: toSemVer(t, "0.3.1"), - }, { - name: "pre-release against newer development pre-release should not update", - currentVersion: "v0.4.0-alpha", - releases: []string{"v0.2.0", "v0.3.0", "v0.4.0-alpha+dev"}, - expectedResult: nil, // means no update - }, { - name: "development pre-release against non-development pre-release should update to non-development pre-release", - currentVersion: "v0.4.0-alpha+dev", - releases: []string{"v0.2.0", "v0.3.0", "v0.4.0-alpha"}, - expectedResult: toSemVer(t, "0.4.0-alpha"), - }, { - name: "development pre-release against newer pre-release should update to latest pre-release", - currentVersion: "v0.4.0-alpha+dev", - releases: []string{"v0.2.0", "v0.3.0", "v0.4.0-alpha", "v0.4.0-beta"}, - expectedResult: toSemVer(t, "0.4.0-beta"), - }, - } - - for _, tc := range tcs { - t.Run(tc.name, func(tt *testing.T) { - // given - releasesGetter := func() ([]string, error) { - return tc.releases, nil - } - - // when - newerVersion, err := version.Check(releasesGetter, tc.currentVersion) - - // then - require.NoError(tt, err) - assert.Equal(tt, tc.expectedResult, newerVersion) - }) - } -} - -func testVerifyingUnreleasedVersionSucceeds(t *testing.T) { - tcs := []struct { - name string - version string - isUnreleased bool - }{ - { - name: "stable version is not unreleased", - version: "0.1.0", - isUnreleased: false, - }, { - name: "pre-release version is not unreleased", - version: "0.1.0-pre", - isUnreleased: false, - }, { - name: "development build on stable version is unreleased", - version: "0.1.0+dev", - isUnreleased: true, - }, { - name: "development pre-release version is unreleased", - version: "0.1.0-alpha+dev", - isUnreleased: true, - }, { - name: "annotated build on pre-release version is released", - version: "0.1.0-alpha+12345", - isUnreleased: false, - }, { - name: "non-semver version is unreleased", - version: "test", - isUnreleased: true, - }, - } - - for _, tc := range tcs { - t.Run(tc.name, func(tt *testing.T) { - version.Version = tc.version - - // when - isUnreleased := version.IsUnreleased() - - // then - assert.Equal(tt, tc.isUnreleased, isUnreleased) - }) - } -} - -func toSemVer(t *testing.T, s string) *semver.Version { - t.Helper() - expectVersion, err := semver.New(s) - if err != nil { - t.Fatalf("couldn't parse the semver: %v", err) - } - return expectVersion -}