-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #203 from uma-universal-money-address/feat/versioning
Update to use the NWC versioning system.
- Loading branch information
Showing
4 changed files
with
186 additions
and
9 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
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,34 @@ | ||
from dataclasses import dataclass | ||
from functools import total_ordering | ||
from typing import List | ||
|
||
|
||
NWC_VERSIONS_SUPPORTED: List[str] = ["0.0", "1.0"] | ||
|
||
|
||
@total_ordering | ||
@dataclass | ||
class ParsedVersion: | ||
major: int | ||
minor: int | ||
|
||
@classmethod | ||
def load(cls, version: str) -> "ParsedVersion": | ||
[major, minor] = version.split(".") | ||
return ParsedVersion(major=int(major), minor=int(minor)) | ||
|
||
def __str__(self) -> str: | ||
return f"{self.major}.{self.minor}" | ||
|
||
def __lt__(self, other: "ParsedVersion") -> bool: | ||
return self.major < other.major or ( | ||
self.major == other.major and self.minor < other.minor | ||
) | ||
|
||
|
||
def is_version_supported(version: ParsedVersion) -> bool: | ||
for version_str in NWC_VERSIONS_SUPPORTED: | ||
supported_version = ParsedVersion.load(version_str) | ||
if version.major == supported_version.major: | ||
return version.minor <= supported_version.minor | ||
return False |