Skip to content

Commit

Permalink
Merge #199: hrp: small improvement in hrp parsing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
apoelstra committed Sep 10, 2024
2 parents e35cdda + 3322ca4 commit 2052ec1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/primitives/hrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ impl Hrp {
pub fn parse(hrp: &str) -> Result<Self, Error> {
use Error::*;

let mut new = Hrp { buf: [0_u8; MAX_HRP_LEN], size: 0 };

if hrp.is_empty() {
return Err(Empty);
}
if hrp.len() > MAX_HRP_LEN {
return Err(TooLong(hrp.len()));
}

let mut new = Hrp { buf: [0_u8; MAX_HRP_LEN], size: 0 };

let mut has_lower: bool = false;
let mut has_upper: bool = false;
for (i, c) in hrp.chars().enumerate() {
Expand Down

0 comments on commit 2052ec1

Please sign in to comment.