From 1e23a6ae30ce0589c851b65214664fd730ea6257 Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Sun, 6 Feb 2022 13:00:54 +0200 Subject: [PATCH] Add AllowConnectionToDifferentVersions flag to kaspactl --- cmd/kaspactl/config.go | 11 ++++++----- cmd/kaspactl/main.go | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/cmd/kaspactl/config.go b/cmd/kaspactl/config.go index 7053d4573f..c37f8874b6 100644 --- a/cmd/kaspactl/config.go +++ b/cmd/kaspactl/config.go @@ -12,11 +12,12 @@ var ( ) type configFlags struct { - RPCServer string `short:"s" long:"rpcserver" description:"RPC server to connect to"` - Timeout uint64 `short:"t" long:"timeout" description:"Timeout for the request (in seconds)"` - RequestJSON string `short:"j" long:"json" description:"The request in JSON format"` - ListCommands bool `short:"l" long:"list-commands" description:"List all commands and exit"` - CommandAndParameters []string + RPCServer string `short:"s" long:"rpcserver" description:"RPC server to connect to"` + Timeout uint64 `short:"t" long:"timeout" description:"Timeout for the request (in seconds)"` + RequestJSON string `short:"j" long:"json" description:"The request in JSON format"` + ListCommands bool `short:"l" long:"list-commands" description:"List all commands and exit"` + AllowConnectionToDifferentVersions bool `short:"a" long:"allow-connection-to-different-versions" description:"Allow connections to versions different than kaspactl's version'"` + CommandAndParameters []string config.NetworkFlags } diff --git a/cmd/kaspactl/main.go b/cmd/kaspactl/main.go index c69db51bca..df01b794da 100644 --- a/cmd/kaspactl/main.go +++ b/cmd/kaspactl/main.go @@ -34,16 +34,18 @@ func main() { } defer client.Disconnect() - kaspadMessage, err := client.Post(&protowire.KaspadMessage{Payload: &protowire.KaspadMessage_GetInfoRequest{GetInfoRequest: &protowire.GetInfoRequestMessage{}}}) - if err != nil { - printErrorAndExit(fmt.Sprintf("Cannot post GetInfo message: %s", err)) - } - - localVersion := version.Version() - remoteVersion := kaspadMessage.GetGetInfoResponse().ServerVersion - - if localVersion != remoteVersion { - printErrorAndExit(fmt.Sprintf("Server version mismatch, expect: %s, got: %s", localVersion, remoteVersion)) + if !cfg.AllowConnectionToDifferentVersions { + kaspadMessage, err := client.Post(&protowire.KaspadMessage{Payload: &protowire.KaspadMessage_GetInfoRequest{GetInfoRequest: &protowire.GetInfoRequestMessage{}}}) + if err != nil { + printErrorAndExit(fmt.Sprintf("Cannot post GetInfo message: %s", err)) + } + + localVersion := version.Version() + remoteVersion := kaspadMessage.GetGetInfoResponse().ServerVersion + + if localVersion != remoteVersion { + printErrorAndExit(fmt.Sprintf("Server version mismatch, expect: %s, got: %s", localVersion, remoteVersion)) + } } responseChan := make(chan string)