Skip to content

Commit 4126954

Browse files
gabriele-0201rphmeier
authored andcommitted
fix read_namespace
1 parent c098b7b commit 4126954

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

sugondat-shim/src/cmd/query/submit.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,16 @@ fn read_blob(path: &str) -> anyhow::Result<Vec<u8>> {
4646
///
4747
/// The integer is interpreted as little-endian.
4848
fn read_namespace(namespace: &str) -> anyhow::Result<sugondat_nmt::Namespace> {
49-
if namespace.starts_with("0x") {
50-
let namespace = namespace.trim_start_matches("0x");
51-
let namespace = hex::decode(namespace)?;
49+
if let Some(hex) = namespace.strip_prefix("0x") {
50+
let namespace = hex::decode(hex)?;
5251
let namespace: [u8; 4] = namespace.try_into().map_err(|e: Vec<u8>| {
5352
anyhow::anyhow!("namespace must be 4 bytes long, but was {}", e.len())
5453
})?;
55-
Ok(sugondat_nmt::Namespace::from_raw_bytes(namespace))
56-
} else {
57-
let namespace_id = namespace
58-
.parse::<u32>()
59-
.with_context(|| format!("cannot parse namespace id '{}'", namespace))?;
60-
Ok(sugondat_nmt::Namespace::with_namespace_id(namespace_id))
54+
return Ok(sugondat_nmt::Namespace::from_raw_bytes(namespace));
6155
}
56+
57+
let namespace_id = namespace
58+
.parse::<u32>()
59+
.with_context(|| format!("cannot parse namespace id '{}'", namespace))?;
60+
Ok(sugondat_nmt::Namespace::with_namespace_id(namespace_id))
6261
}

0 commit comments

Comments
 (0)