Skip to content

Commit

Permalink
Add AllowConnectionToDifferentVersions flag to kaspactl
Browse files Browse the repository at this point in the history
  • Loading branch information
someone235 committed Feb 6, 2022
1 parent 1cd712a commit f15fb7e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
11 changes: 6 additions & 5 deletions cmd/kaspactl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
22 changes: 12 additions & 10 deletions cmd/kaspactl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const validCharacters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs
const (
appMajor uint = 0
appMinor uint = 11
appPatch uint = 11
appPatch uint = 12
)

// appBuild is defined as a variable so it can be overridden during the build
Expand Down

0 comments on commit f15fb7e

Please sign in to comment.