Skip to content

Commit 2052ec1

Browse files
committed
Merge #199: hrp: small improvement in hrp parsing
3322ca4 hrp: small improvement in hrp parsing (Thomas Coratger) Pull request description: In the HRP parsing function, we first test the following conditions with potential error outputs: ```rust if hrp.is_empty() { return Err(Empty); } if hrp.len() > MAX_HRP_LEN { return Err(TooLong(hrp.len())); } ``` So we don't need to directly declare the `new` variable in case an error is thrown and this declaration becoming useless. We can wait for the checks to be ok before declaring this (very small improvement). ACKs for top commit: tcharding: ACK 3322ca4 apoelstra: ACK 3322ca4 successfully ran local tests clarkmoody: ACK 3322ca4 Tree-SHA512: 92da994c5c504cf34e443646548a567076edb57fcbb88e08bada8d1e60ffaeaced50e5665b22dfded5c31107671d3ca7f49dc6eaaeb732a43ac424a3425fa145
2 parents e35cdda + 3322ca4 commit 2052ec1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/primitives/hrp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ impl Hrp {
7878
pub fn parse(hrp: &str) -> Result<Self, Error> {
7979
use Error::*;
8080

81-
let mut new = Hrp { buf: [0_u8; MAX_HRP_LEN], size: 0 };
82-
8381
if hrp.is_empty() {
8482
return Err(Empty);
8583
}
8684
if hrp.len() > MAX_HRP_LEN {
8785
return Err(TooLong(hrp.len()));
8886
}
8987

88+
let mut new = Hrp { buf: [0_u8; MAX_HRP_LEN], size: 0 };
89+
9090
let mut has_lower: bool = false;
9191
let mut has_upper: bool = false;
9292
for (i, c) in hrp.chars().enumerate() {

0 commit comments

Comments
 (0)