code.vegaprotocol.io/vega@v0.79.0/cmd/vegawallet/commands/software_compatibility.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package cmd 17 18 import ( 19 "fmt" 20 "io" 21 22 "code.vegaprotocol.io/vega/cmd/vegawallet/commands/cli" 23 "code.vegaprotocol.io/vega/cmd/vegawallet/commands/flags" 24 "code.vegaprotocol.io/vega/cmd/vegawallet/commands/printer" 25 "code.vegaprotocol.io/vega/paths" 26 netv1 "code.vegaprotocol.io/vega/wallet/network/store/v1" 27 wversion "code.vegaprotocol.io/vega/wallet/version" 28 29 "github.com/spf13/cobra" 30 ) 31 32 var ( 33 softwareCompatibilityLong = `Check the compatibility between this software and all the registered networks. 34 35 # What are these incompatibilities? 36 37 Breaking changes may be introduced between software versions deployed on the networks. 38 And, because the wallet software is deeply tied to the network APIs, when it is run 39 against a different version of the network, some requests may fail. 40 41 Currently there's no guarantee of backward or forward compatibility, but that will 42 change when the network is officially defined as stable. 43 44 # My software is said to be incompatible, what can I do when m? 45 46 The best option is to: 47 48 1. Download the version of the wallet software matching the version running on the network at: 49 https://github.com/vegaprotocol/vega/releases 50 Example: If the network is running 0.57.1, download the wallet software with the version 0.57.1. 51 52 2. Then, switch to the wallet software matching the network version. 53 54 # Will I have to do that forever? 55 56 No. This will not be a problem once the network is officially defined as stable. 57 ` 58 59 softwareCompatibilityExample = cli.Examples(` 60 # Check the software compatibility against all registered networks 61 {{.Software}} software compatibility 62 `) 63 ) 64 65 type CheckSoftwareCompatibilityHandler func() (*wversion.CheckSoftwareCompatibilityResponse, error) 66 67 func NewCmdSoftwareCompatibility(w io.Writer, rf *RootFlags) *cobra.Command { 68 h := func() (*wversion.CheckSoftwareCompatibilityResponse, error) { 69 s, err := netv1.InitialiseStore(paths.New(rf.Home)) 70 if err != nil { 71 return nil, fmt.Errorf("couldn't initialise network store: %w", err) 72 } 73 74 return wversion.CheckSoftwareCompatibility(s, wversion.GetNetworkVersionThroughGRPC) 75 } 76 77 return BuildCmdCheckSoftwareCompatibility(w, h, rf) 78 } 79 80 func BuildCmdCheckSoftwareCompatibility(w io.Writer, handler CheckSoftwareCompatibilityHandler, rf *RootFlags) *cobra.Command { 81 cmd := &cobra.Command{ 82 Use: "compatibility", 83 Short: "Check the compatibility between this software and all the registered networks", 84 Long: softwareCompatibilityLong, 85 Example: softwareCompatibilityExample, 86 RunE: func(_ *cobra.Command, _ []string) error { 87 resp, err := handler() 88 if err != nil { 89 return err 90 } 91 92 switch rf.Output { 93 case flags.InteractiveOutput: 94 PrintCheckSoftwareIncompatibilityResponse(w, resp) 95 case flags.JSONOutput: 96 return printer.FprintJSON(w, resp) 97 } 98 99 return nil 100 }, 101 } 102 103 return cmd 104 } 105 106 func PrintCheckSoftwareIncompatibilityResponse(w io.Writer, resp *wversion.CheckSoftwareCompatibilityResponse) { 107 p := printer.NewInteractivePrinter(w) 108 109 str := p.String() 110 defer p.Print(str) 111 112 hasIncompatibilities := false 113 114 for _, networkCompatibility := range resp.NetworksCompatibility { 115 str.Text("- ").Bold(networkCompatibility.Network).Text(":").NextLine() 116 if networkCompatibility.Error != nil { 117 str.Pad().WarningText("Unable to determine this network version:").NextLine() 118 str.Pad().WarningText(networkCompatibility.Error.Error()) 119 } else { 120 str.Pad().Text("This network is running the version ").InfoText(networkCompatibility.RetrievedVersion).NextLine() 121 if !networkCompatibility.IsCompatible { 122 hasIncompatibilities = true 123 str.Pad().DangerBold("Incompatible.") 124 } else { 125 str.Pad().SuccessBold("Compatible.") 126 } 127 } 128 str.NextLine() 129 } 130 str.NextLine() 131 132 if len(resp.NetworksCompatibility) > 0 && hasIncompatibilities { 133 str.BlueArrow().InfoText("What are these incompatibilities?").NextLine() 134 str.Text("Breaking changes may be introduced between software versions deployed on the networks. And, because the wallet software is deeply tied to the network APIs, when it is run against a different version of the network, some requests may fail.").NextLine() 135 str.Text("Currently there's no guarantee of backward or forward compatibility, but that will change when the network is officially defined as stable.").NextSection() 136 137 str.BlueArrow().InfoText("What can I do then?").NextLine() 138 str.Text("The best option is to:").NextLine() 139 str.Text("1. Download the version of the wallet software matching the version running on the network at:").NextLine() 140 str.Text(" ").Underline("https://github.com/vegaprotocol/vega/releases").NextLine() 141 str.Text(" Example: If the network is running 0.57.1, download the wallet software with the version 0.57.1.").NextLine() 142 str.Text("2. Then, switch to the wallet software matching the network version.").NextSection() 143 144 str.BlueArrow().InfoText("Will I have to do that forever?").NextLine() 145 str.Text("No. This will not be a problem once the network is officially defined as stable.").NextSection() 146 } 147 }