enforce proper range for rent burn_percent (#7217)

* enforce proper range for burn_percent
This commit is contained in:
Parth
2019-12-04 00:54:01 +05:30
committed by GitHub
parent d5c8b26a45
commit ba688cf629
5 changed files with 28 additions and 4 deletions

View File

@ -97,3 +97,24 @@ pub fn is_port(port: String) -> Result<(), String> {
.map(|_| ())
.map_err(|e| format!("{:?}", e))
}
pub fn is_valid_percentage(percentage: String) -> Result<(), String> {
percentage
.parse::<u8>()
.map_err(|e| {
format!(
"Unable to parse input percentage, provided: {}, err: {:?}",
percentage, e
)
})
.and_then(|v| {
if v > 100 {
Err(format!(
"Percentage must be in range of 0 to 100, provided: {}",
v
))
} else {
Ok(())
}
})
}