-
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.
- Loading branch information
Showing
10 changed files
with
388 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{{ if .Versions -}} | ||
<a name="unreleased"></a> | ||
## [Unreleased] | ||
|
||
{{ if .Unreleased.CommitGroups -}} | ||
{{ range .Unreleased.CommitGroups -}} | ||
### {{ .Title }} | ||
{{ range .Commits -}} | ||
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} | ||
{{ end }} | ||
{{ end -}} | ||
{{ end -}} | ||
{{ end -}} | ||
|
||
{{ range .Versions }} | ||
<a name="{{ .Tag.Name }}"></a> | ||
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }} | ||
{{ range .CommitGroups -}} | ||
### {{ .Title }} | ||
{{ range .Commits -}} | ||
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} | ||
{{ end }} | ||
{{ end -}} | ||
|
||
{{- if .RevertCommits -}} | ||
### Reverts | ||
{{ range .RevertCommits -}} | ||
- {{ .Revert.Header }} | ||
{{ end }} | ||
{{ end -}} | ||
|
||
{{- if .MergeCommits -}} | ||
### Pull Requests | ||
{{ range .MergeCommits -}} | ||
- {{ .Header }} | ||
{{ end }} | ||
{{ end -}} | ||
|
||
{{- if .NoteGroups -}} | ||
{{ range .NoteGroups -}} | ||
### {{ .Title }} | ||
{{ range .Notes }} | ||
{{ .Body }} | ||
{{ end }} | ||
{{ end -}} | ||
{{ end -}} | ||
{{ end -}} | ||
|
||
{{- if .Versions }} | ||
[Unreleased]: {{ .Info.RepositoryURL }}/compare/{{ $latest := index .Versions 0 }}{{ $latest.Tag.Name }}...HEAD | ||
{{ range .Versions -}} | ||
{{ if .Tag.Previous -}} | ||
[{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }} | ||
{{ end -}} | ||
{{ end -}} | ||
{{ end -}} |
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,28 @@ | ||
style: github | ||
template: CHANGELOG.tpl.md | ||
info: | ||
title: CHANGELOG | ||
repository_url: https://github.com/george012/rs_box | ||
options: | ||
commits: | ||
# filters: | ||
# Type: | ||
# - feat | ||
# - fix | ||
# - perf | ||
# - refactor | ||
commit_groups: | ||
# title_maps: | ||
# feat: Features | ||
# fix: Bug Fixes | ||
# perf: Performance Improvements | ||
# refactor: Code Refactoring | ||
header: | ||
pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$" | ||
pattern_maps: | ||
- Type | ||
- Scope | ||
- Subject | ||
notes: | ||
keywords: | ||
- BREAKING CHANGE |
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,108 @@ | ||
use std::collections::HashMap; | ||
use std::fmt; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub enum CoinFlag { | ||
CoinFlagNone, | ||
CoinFlagBTC, | ||
CoinFlagLTC, | ||
CoinFlagDOGE, | ||
CoinFlagETC, | ||
CoinFlagETHW, | ||
CoinFlagZIL, | ||
CoinFlagOCTA, | ||
CoinFlagMETA, | ||
CoinFlagCAU, | ||
} | ||
|
||
impl CoinFlag { | ||
fn coin_name(&self) -> &str { | ||
match self { | ||
CoinFlag::CoinFlagBTC => "BTC", | ||
CoinFlag::CoinFlagLTC => "LTC", | ||
CoinFlag::CoinFlagDOGE => "DOGE", | ||
CoinFlag::CoinFlagETC => "ETC", | ||
CoinFlag::CoinFlagETHW => "ETHW", | ||
CoinFlag::CoinFlagZIL => "ZIL", | ||
CoinFlag::CoinFlagOCTA => "OCTA", | ||
CoinFlag::CoinFlagMETA => "META", | ||
CoinFlag::CoinFlagCAU => "CAU", | ||
CoinFlag::CoinFlagNone => "none", | ||
} | ||
} | ||
|
||
pub fn coin_full_name(&self) -> &str { | ||
match self { | ||
CoinFlag::CoinFlagBTC => "Bitcoin", | ||
CoinFlag::CoinFlagLTC => "Litecoin", | ||
CoinFlag::CoinFlagDOGE => "Dogecoin", | ||
CoinFlag::CoinFlagETC => "EthereumClassic", | ||
CoinFlag::CoinFlagETHW => "EthereumPoW", | ||
CoinFlag::CoinFlagZIL => "Zilliqa", | ||
CoinFlag::CoinFlagOCTA => "OctaSpace", | ||
CoinFlag::CoinFlagMETA => "MetaChain", | ||
CoinFlag::CoinFlagCAU => "Canxium", | ||
CoinFlag::CoinFlagNone => "none", | ||
} | ||
} | ||
|
||
pub fn get_block_node_binary_name(&self) -> &str { | ||
match self { | ||
CoinFlag::CoinFlagBTC => "btcd", | ||
CoinFlag::CoinFlagLTC => "litecoind", | ||
CoinFlag::CoinFlagDOGE => "dogecoind", | ||
CoinFlag::CoinFlagETC => "geth", | ||
CoinFlag::CoinFlagETHW => "geth", | ||
CoinFlag::CoinFlagZIL => "zilliqa", | ||
CoinFlag::CoinFlagOCTA => "geth", | ||
CoinFlag::CoinFlagMETA => "geth", | ||
CoinFlag::CoinFlagCAU => "canxium", | ||
CoinFlag::CoinFlagNone => "none", | ||
} | ||
} | ||
|
||
pub fn get_block_node_binary_systemd_service_name(&self) -> String { | ||
let service_name = format!("{}-{}", self.coin_name().to_lowercase(), self.get_block_node_binary_name()); | ||
if *self == CoinFlag::CoinFlagETC { | ||
format!("core-{}", self.get_block_node_binary_name()) | ||
} else { | ||
service_name | ||
} | ||
} | ||
} | ||
|
||
pub fn get_coin_flag_by_coin_name(name: &str) -> CoinFlag { | ||
match name { | ||
"BTC" | "BitCoin" | "Bitcoin" => CoinFlag::CoinFlagBTC, | ||
"LTC" | "LiteCoin" | "Litecoin" => CoinFlag::CoinFlagLTC, | ||
"DOGE" | "DogeCoin" | "Dogecoin" => CoinFlag::CoinFlagDOGE, | ||
"ETC" | "Ethereum Classic" | "EthereumClassic" => CoinFlag::CoinFlagETC, | ||
"ETHW" | "EthereumPoW" => CoinFlag::CoinFlagETHW, | ||
"ZIL" | "Zilliqa" => CoinFlag::CoinFlagZIL, | ||
"OCTA" | "OctaSpace" => CoinFlag::CoinFlagOCTA, | ||
"META" | "MetaChain" => CoinFlag::CoinFlagMETA, | ||
"CAU" | "Canxium" => CoinFlag::CoinFlagCAU, | ||
_ => CoinFlag::CoinFlagNone, | ||
} | ||
} | ||
|
||
pub fn is_coin_supported(coin_name: &str) -> bool { | ||
let supported_coins: HashMap<&str, CoinFlag> = [ | ||
("BTC", CoinFlag::CoinFlagBTC), | ||
("ETC", CoinFlag::CoinFlagETC), | ||
("ETHW", CoinFlag::CoinFlagETHW), | ||
("ZIL", CoinFlag::CoinFlagZIL), | ||
("OCTA", CoinFlag::CoinFlagOCTA), | ||
("LTC", CoinFlag::CoinFlagLTC), | ||
("DOGE", CoinFlag::CoinFlagDOGE), | ||
("META", CoinFlag::CoinFlagMETA), | ||
("CAU", CoinFlag::CoinFlagCAU), | ||
] | ||
.iter() | ||
.cloned() | ||
.collect(); | ||
|
||
supported_coins.contains_key(coin_name) | ||
} | ||
|
||
|
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,19 @@ | ||
#[cfg(test)] | ||
use super::coin_flags; | ||
|
||
#[test] | ||
fn test_simple_used_with_coin_flags() { | ||
let coin = "BTC"; | ||
|
||
if coin_flags::is_coin_supported(coin) { | ||
let flag = coin_flags::get_coin_flag_by_coin_name(coin); | ||
println!("Coin: {}\nFull Name: {}\nblock chain node Binary Name: {}\nSystemd Service Name: {}\n", | ||
coin, | ||
flag.coin_full_name(), | ||
flag.get_block_node_binary_name(), | ||
flag.get_block_node_binary_systemd_service_name() | ||
); | ||
} else { | ||
println!("Coin {} is not supported.", coin); | ||
} | ||
} |
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,119 @@ | ||
use std::fmt; | ||
use std::str::FromStr; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq)] | ||
pub enum HashRateUnitFormat { | ||
Hs, // H/s 默认值 | ||
KHs, // KH/s | ||
MHs, // MH/s | ||
GHs, // GH/s | ||
THs, // TH/s | ||
PHs, // PH/s | ||
EHs, // EH/s | ||
ZHs, // ZH/s | ||
YHs, // YH/s | ||
} | ||
|
||
impl fmt::Display for HashRateUnitFormat { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
HashRateUnitFormat::Hs => write!(f, "H/s"), | ||
HashRateUnitFormat::KHs => write!(f, "KH/s"), | ||
HashRateUnitFormat::MHs => write!(f, "MH/s"), | ||
HashRateUnitFormat::GHs => write!(f, "GH/s"), | ||
HashRateUnitFormat::THs => write!(f, "TH/s"), | ||
HashRateUnitFormat::PHs => write!(f, "PH/s"), | ||
HashRateUnitFormat::EHs => write!(f, "EH/s"), | ||
HashRateUnitFormat::ZHs => write!(f, "ZH/s"), | ||
HashRateUnitFormat::YHs => write!(f, "YH/s"), | ||
} | ||
} | ||
} | ||
|
||
pub struct GTHashRate { | ||
pub value: String, | ||
pub unit_str: String, | ||
pub unit_flag: HashRateUnitFormat, | ||
} | ||
|
||
impl GTHashRate { | ||
fn new(value: String, unit_str: String, unit_flag: HashRateUnitFormat) -> Self { | ||
Self { | ||
value, | ||
unit_str, | ||
unit_flag, | ||
} | ||
} | ||
} | ||
|
||
/// 算力单位自动格式化 深度定制 | ||
/// base_hash_rate 以H/s 传入的 基础数值 | ||
/// to_format 想要转换成的单位类型 | ||
/// f_sed 小数点后保留位数 | ||
/// return--->GTHashRate 返回 GTHashRate 结构体 | ||
pub fn hash_rate_to_format(base_hash_rate: f64, to_format: HashRateUnitFormat, f_sed: usize) -> GTHashRate { | ||
let k = 1_000.0; | ||
let m = k * k; | ||
let g = m * k; | ||
let t = g * k; | ||
let p = t * k; | ||
let e = p * k; | ||
let z = e * k; | ||
let y = z * k; | ||
|
||
let (cm_hs, cmp_unit, cmp_unit_str) = match to_format { | ||
HashRateUnitFormat::YHs => (base_hash_rate / y, HashRateUnitFormat::YHs, HashRateUnitFormat::YHs.to_string()), | ||
HashRateUnitFormat::ZHs => (base_hash_rate / z, HashRateUnitFormat::ZHs, HashRateUnitFormat::ZHs.to_string()), | ||
HashRateUnitFormat::EHs => (base_hash_rate / e, HashRateUnitFormat::EHs, HashRateUnitFormat::EHs.to_string()), | ||
HashRateUnitFormat::PHs => (base_hash_rate / p, HashRateUnitFormat::PHs, HashRateUnitFormat::PHs.to_string()), | ||
HashRateUnitFormat::THs => (base_hash_rate / t, HashRateUnitFormat::THs, HashRateUnitFormat::THs.to_string()), | ||
HashRateUnitFormat::GHs => (base_hash_rate / g, HashRateUnitFormat::GHs, HashRateUnitFormat::GHs.to_string()), | ||
HashRateUnitFormat::MHs => (base_hash_rate / m, HashRateUnitFormat::MHs, HashRateUnitFormat::MHs.to_string()), | ||
HashRateUnitFormat::KHs => (base_hash_rate / k, HashRateUnitFormat::KHs, HashRateUnitFormat::KHs.to_string()), | ||
HashRateUnitFormat::Hs | _ => (base_hash_rate, HashRateUnitFormat::Hs, HashRateUnitFormat::Hs.to_string()), | ||
}; | ||
|
||
GTHashRate::new(format!("{:.*}", f_sed, cm_hs), cmp_unit_str, cmp_unit) | ||
} | ||
|
||
/// 算力单位自动格式化 | ||
/// hs 以H/s 传入的 基础数值 | ||
/// f_sed 小数点后保留位数 | ||
pub fn hash_rate_format_with_sed(hs: f64, f_sed: usize) -> String { | ||
let k = 1_000.0; | ||
let m = k * k; | ||
let g = m * k; | ||
let t = g * k; | ||
let p = t * k; | ||
let e = p * k; | ||
let z = e * k; | ||
let y = z * k; | ||
|
||
let hsr = if hs >= y { | ||
hash_rate_to_format(hs, HashRateUnitFormat::YHs, f_sed) | ||
} else if hs >= z { | ||
hash_rate_to_format(hs, HashRateUnitFormat::ZHs, f_sed) | ||
} else if hs >= e { | ||
hash_rate_to_format(hs, HashRateUnitFormat::EHs, f_sed) | ||
} else if hs >= p { | ||
hash_rate_to_format(hs, HashRateUnitFormat::PHs, f_sed) | ||
} else if hs >= t { | ||
hash_rate_to_format(hs, HashRateUnitFormat::THs, f_sed) | ||
} else if hs >= g { | ||
hash_rate_to_format(hs, HashRateUnitFormat::GHs, f_sed) | ||
} else if hs >= m { | ||
hash_rate_to_format(hs, HashRateUnitFormat::MHs, f_sed) | ||
} else if hs >= k { | ||
hash_rate_to_format(hs, HashRateUnitFormat::KHs, f_sed) | ||
} else { | ||
hash_rate_to_format(hs, HashRateUnitFormat::Hs, f_sed) | ||
}; | ||
|
||
format!("{} {}", hsr.value, hsr.unit_str) | ||
} | ||
|
||
/// 算力单位自动格式化 一键式 | ||
/// hs 以H/s 传入的 基础数值, 默认小数点后暴力3位 | ||
pub fn hash_rate_format(hs: f64) -> String { | ||
hash_rate_format_with_sed(hs,3) | ||
} |
Oops, something went wrong.