Skip to content

Commit

Permalink
Update v0.0.21
Browse files Browse the repository at this point in the history
  • Loading branch information
george012 committed May 17, 2024
1 parent a82c581 commit 2804e2b
Show file tree
Hide file tree
Showing 10 changed files with 388 additions and 6 deletions.
56 changes: 56 additions & 0 deletions .chglog/CHANGELOG.tpl.md
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 -}}
28 changes: 28 additions & 0 deletions .chglog/config.yml
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rs_box"
version = "0.0.20"
version = "0.0.21"
description = "rust develop box"
edition = "2021"
readme = "README.md"
Expand Down
16 changes: 11 additions & 5 deletions git_tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,24 @@ function git_handle_push() {
&& git tag -d v$pre_del_version_no
}

handle_input(){
function generate_changelog() {
git-chglog -o CHANGELOG.md
git add CHANGELOG.md
git commit -m "Update changelog for ${NEXT_VERSION}"
}

handle_input() {
if [[ $1 == "-get_pre_del_tag_name" ]]; then
pre_tag=$(get_pre_del_version_no "${CURRENT_VERSION}")
echo "Pre Del Tag With " "$pre_tag"
echo $pre_tag
elif [ -z "$1" ] || [ "$1" == "auto" ]; then

if to_run "$1"; then
git_handle_ready
generate_changelog
git_handle_push
echo "Complated"
echo "Completed"
else
echo "Invalid argument normal"
echo "Invalid argument"
fi
else
echo "Invalid argument"
Expand Down
108 changes: 108 additions & 0 deletions src/block_chain/coin_flags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
use std::collections::HashMap;
use std::fmt;

Check warning on line 2 in src/block_chain/coin_flags.rs

View workflow job for this annotation

GitHub Actions / Build

unused import: `std::fmt`

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CoinFlag {
CoinFlagNone,

Check warning on line 6 in src/block_chain/coin_flags.rs

View workflow job for this annotation

GitHub Actions / Build

multiple variants are never constructed
CoinFlagBTC,
CoinFlagLTC,
CoinFlagDOGE,
CoinFlagETC,
CoinFlagETHW,
CoinFlagZIL,
CoinFlagOCTA,
CoinFlagMETA,
CoinFlagCAU,
}

impl CoinFlag {
fn coin_name(&self) -> &str {

Check warning on line 19 in src/block_chain/coin_flags.rs

View workflow job for this annotation

GitHub Actions / Build

methods `coin_name`, `coin_full_name`, `get_block_node_binary_name`, and `get_block_node_binary_systemd_service_name` are never used
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 {

Check warning on line 74 in src/block_chain/coin_flags.rs

View workflow job for this annotation

GitHub Actions / Build

function `get_coin_flag_by_coin_name` is never used
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 {

Check warning on line 89 in src/block_chain/coin_flags.rs

View workflow job for this annotation

GitHub Actions / Build

function `is_coin_supported` is never used
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)
}


19 changes: 19 additions & 0 deletions src/block_chain/coin_flags_test.rs
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);
}
}
119 changes: 119 additions & 0 deletions src/block_chain/hash_rate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
use std::fmt;
use std::str::FromStr;

Check warning on line 2 in src/block_chain/hash_rate.rs

View workflow job for this annotation

GitHub Actions / Build

unused import: `std::str::FromStr`

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum HashRateUnitFormat {
Hs, // H/s 默认值

Check warning on line 6 in src/block_chain/hash_rate.rs

View workflow job for this annotation

GitHub Actions / Build

multiple variants are never constructed
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 {

Check warning on line 33 in src/block_chain/hash_rate.rs

View workflow job for this annotation

GitHub Actions / Build

struct `GTHashRate` is never constructed
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()),

Check warning on line 73 in src/block_chain/hash_rate.rs

View workflow job for this annotation

GitHub Actions / Build

unreachable pattern
};

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)
}
Loading

0 comments on commit 2804e2b

Please sign in to comment.