chain: remove utils module
A catch-all utils module can really easily slip into being a place to stash miscellaneous functions that don't really belong anywhere in particular.
This commit is contained in:
parent
4bbefeb68e
commit
0d1f56ad2f
|
@ -333,9 +333,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
|||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.13"
|
||||
version = "0.4.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6"
|
||||
checksum = "942f72db697d8767c22d46a598e01f2d3b475501ea43d0db4f16d90259182d0b"
|
||||
dependencies = [
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
|
@ -345,9 +345,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "2.33.2"
|
||||
version = "2.33.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10040cdf04294b565d9e0319955430099ec3813a64c952b86a41200ad714ae48"
|
||||
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
|
||||
dependencies = [
|
||||
"ansi_term 0.11.0",
|
||||
"atty",
|
||||
|
@ -600,7 +600,7 @@ version = "0.9.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
|
||||
dependencies = [
|
||||
"generic-array 0.14.3",
|
||||
"generic-array 0.14.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -668,25 +668,11 @@ dependencies = [
|
|||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ed25519-zebra"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a045d3ca7d15222d578515dc6b54fea6c3591763b8fe2f67a45bbd56d5f1989b"
|
||||
dependencies = [
|
||||
"curve25519-dalek",
|
||||
"hex",
|
||||
"rand_core 0.5.1",
|
||||
"serde",
|
||||
"sha2",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.5.3"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
|
||||
checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f"
|
||||
|
||||
[[package]]
|
||||
name = "equihash"
|
||||
|
@ -888,9 +874,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.3"
|
||||
version = "0.14.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60fb4bb6bba52f78a471264d9a3b7d026cc0af47b22cd2cffbc0b787ca003e63"
|
||||
checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
|
@ -954,9 +940,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.8.1"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb"
|
||||
checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
@ -1526,7 +1512,7 @@ dependencies = [
|
|||
"cloudabi 0.0.3",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec 1.4.1",
|
||||
"smallvec 1.4.2",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
|
@ -1541,7 +1527,7 @@ dependencies = [
|
|||
"instant",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec 1.4.1",
|
||||
"smallvec 1.4.2",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
|
@ -1897,9 +1883,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rgb"
|
||||
version = "0.8.20"
|
||||
version = "0.8.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90ef54b45ae131327a88597e2463fee4098ad6c88ba7b6af4b3987db8aad4098"
|
||||
checksum = "552cbc6167bf0a06c79f8c2a92fdb91cfb5257966c02c2c8f462cb1433e92f15"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
@ -2145,9 +2131,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.4.1"
|
||||
version = "1.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f"
|
||||
checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
|
@ -2708,7 +2694,7 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_json",
|
||||
"sharded-slab",
|
||||
"smallvec 1.4.1",
|
||||
"smallvec 1.4.2",
|
||||
"thread_local",
|
||||
"tracing-core",
|
||||
"tracing-log",
|
||||
|
@ -2729,9 +2715,9 @@ checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
|
|||
|
||||
[[package]]
|
||||
name = "uint"
|
||||
version = "0.8.4"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "429ffcad8c8c15f874578c7337d156a3727eb4a1c2374c0ae937ad9a9b748c80"
|
||||
checksum = "9db035e67dfaf7edd9aebfe8676afcd63eed53c8a4044fed514c8cccf1835177"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"crunchy",
|
||||
|
|
|
@ -27,7 +27,6 @@ pub mod serialization;
|
|||
pub mod transaction;
|
||||
pub mod treestate;
|
||||
pub mod types;
|
||||
pub mod utils;
|
||||
|
||||
pub use ed25519_zebra;
|
||||
pub use redjubjub;
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
//! Utility functions for chain data.
|
||||
|
||||
/// Returns the hexadecimal-encoded string `s` in byte-reversed order.
|
||||
pub fn byte_reverse_hex(s: &str) -> String {
|
||||
String::from_utf8(
|
||||
s.as_bytes()
|
||||
.chunks(2)
|
||||
.rev()
|
||||
.map(|c| c.iter())
|
||||
.flatten()
|
||||
.cloned()
|
||||
.collect::<Vec<u8>>(),
|
||||
)
|
||||
.expect("input should be ascii")
|
||||
}
|
|
@ -25,6 +25,20 @@ use std::os::unix::process::ExitStatusExt;
|
|||
|
||||
mod args;
|
||||
|
||||
/// Returns the hexadecimal-encoded string `s` in byte-reversed order.
|
||||
pub fn byte_reverse_hex(s: &str) -> String {
|
||||
String::from_utf8(
|
||||
s.as_bytes()
|
||||
.chunks(2)
|
||||
.rev()
|
||||
.map(|c| c.iter())
|
||||
.flatten()
|
||||
.cloned()
|
||||
.collect::<Vec<u8>>(),
|
||||
)
|
||||
.expect("input should be ascii")
|
||||
}
|
||||
|
||||
/// We limit the memory usage for each checkpoint, based on the cumulative size of
|
||||
/// the serialized blocks in the chain. Deserialized blocks are larger, because
|
||||
/// they contain pointers and non-compact integers. But they should be within a
|
||||
|
@ -126,11 +140,7 @@ fn main() -> Result<()> {
|
|||
let v: Value = serde_json::from_str(&output)?;
|
||||
|
||||
// get the values we are interested in
|
||||
let hash: BlockHeaderHash = v["hash"]
|
||||
.as_str()
|
||||
.map(zebra_chain::utils::byte_reverse_hex)
|
||||
.unwrap()
|
||||
.parse()?;
|
||||
let hash: BlockHeaderHash = v["hash"].as_str().map(byte_reverse_hex).unwrap().parse()?;
|
||||
let height = BlockHeight(v["height"].as_u64().unwrap() as u32);
|
||||
assert!(height <= BlockHeight::MAX);
|
||||
assert_eq!(x, height.0);
|
||||
|
|
|
@ -5,6 +5,20 @@
|
|||
use abscissa_core::{Command, Options, Runnable};
|
||||
use std::io::stdin;
|
||||
|
||||
/// Returns the hexadecimal-encoded string `s` in byte-reversed order.
|
||||
pub fn byte_reverse_hex(s: &str) -> String {
|
||||
String::from_utf8(
|
||||
s.as_bytes()
|
||||
.chunks(2)
|
||||
.rev()
|
||||
.map(|c| c.iter())
|
||||
.flatten()
|
||||
.cloned()
|
||||
.collect::<Vec<u8>>(),
|
||||
)
|
||||
.expect("input should be ascii")
|
||||
}
|
||||
|
||||
/// `revhex` subcommand
|
||||
#[derive(Command, Debug, Default, Options)]
|
||||
pub struct RevhexCmd {
|
||||
|
@ -26,10 +40,10 @@ impl Runnable for RevhexCmd {
|
|||
// We can distinguish EOF from an empty line, because the newline is
|
||||
// included in the buffer, so empty lines return Ok(1).
|
||||
while stdin().read_line(&mut input).unwrap_or(0) > 0 {
|
||||
println!("{}", zebra_chain::utils::byte_reverse_hex(&input.trim()));
|
||||
println!("{}", byte_reverse_hex(&input.trim()));
|
||||
}
|
||||
} else {
|
||||
println!("{}", zebra_chain::utils::byte_reverse_hex(&self.input));
|
||||
println!("{}", byte_reverse_hex(&self.input));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue