This repository has been archived by the owner on Jun 4, 2018. It is now read-only.
forked from btcsuite/Paymetheus
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check RPC server version during client connect.
Fixes #42.
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2016 The btcsuite developers | ||
// Licensed under the ISC license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
|
||
namespace Paymetheus.Rpc | ||
{ | ||
public struct SemanticVersion | ||
{ | ||
public SemanticVersion(uint major, uint minor, uint patch) | ||
{ | ||
Major = major; | ||
Minor = minor; | ||
Patch = patch; | ||
} | ||
|
||
public uint Major { get; } | ||
public uint Minor { get; } | ||
public uint Patch { get; } | ||
|
||
public override string ToString() => $"{Major}.{Minor}.{Patch}"; | ||
|
||
public static void AssertCompatible(SemanticVersion required, SemanticVersion actual) | ||
{ | ||
if (required.Major != actual.Major) | ||
throw IncompatibleVersionException.Major(required, actual); | ||
if (required.Minor > actual.Minor) | ||
throw IncompatibleVersionException.Minor(required, actual); | ||
if (required.Minor == actual.Minor && required.Patch > actual.Patch) | ||
throw IncompatibleVersionException.Patch(required, actual); | ||
} | ||
} | ||
|
||
public class IncompatibleVersionException : Exception | ||
{ | ||
private IncompatibleVersionException(string whatVersion, SemanticVersion required, SemanticVersion actual) | ||
: base($"Incompatible {whatVersion} versions: required={required} actual={actual}") | ||
{ } | ||
|
||
public static IncompatibleVersionException Major(SemanticVersion required, SemanticVersion actual) => | ||
new IncompatibleVersionException("major", required, actual); | ||
|
||
public static IncompatibleVersionException Minor(SemanticVersion required, SemanticVersion actual) => | ||
new IncompatibleVersionException("minor", required, actual); | ||
|
||
public static IncompatibleVersionException Patch(SemanticVersion required, SemanticVersion actual) => | ||
new IncompatibleVersionException("patch", required, actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters