mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-04 19:50:19 +00:00
pretty print for hash
This commit is contained in:
parent
8773271e73
commit
6596a255a8
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -7,6 +7,7 @@ dependencies = [
|
||||
"boolinator 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"exitfailure 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hex-slice 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-wasm 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pwasm-utils 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -436,6 +437,11 @@ name = "hex"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "hex-slice"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.2.0"
|
||||
@ -1107,6 +1113,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum ghost 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2a36606a68532b5640dc86bb1f33c64b45c4682aad4c50f3937b317ea387f3d6"
|
||||
"checksum gimli 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)" = "81dd6190aad0f05ddbbf3245c54ed14ca4aa6dd32f22312b70d8f168c3e3e633"
|
||||
"checksum hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
|
||||
"checksum hex-slice 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5491a308e0214554f07a81d8944abe45f552871c12e3c3c6e7e5d354039a6c4c"
|
||||
"checksum indexmap 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a61202fbe46c4a951e9404a720a0180bcf3212c750d735cb5c4ba4dc551299f3"
|
||||
"checksum inventory 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "82d3f4b90287725c97b17478c60dda0c6324e7c84ee1ed72fb9179d0fdf13956"
|
||||
"checksum inventory-impl 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9092a4fefc9d503e9287ef137f03180a6e7d1b04c419563171ee14947c5e80ec"
|
||||
|
@ -30,6 +30,7 @@ exitfailure = "0.5.1"
|
||||
boolinator = "2.4.0"
|
||||
parity-wasm = "0.41.0"
|
||||
pwasm-utils = "0.12.0"
|
||||
hex-slice = "0.1.4"
|
||||
|
||||
[profile.release]
|
||||
opt-level = 3
|
||||
|
@ -24,6 +24,7 @@
|
||||
)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
mod vm;
|
||||
mod misc;
|
||||
|
||||
pub use vm::config::Config;
|
||||
pub use vm::frank::Frank;
|
||||
|
@ -26,10 +26,12 @@
|
||||
|
||||
/// Command-line tool intended to test Frank VM.
|
||||
mod vm;
|
||||
mod misc;
|
||||
|
||||
use crate::vm::config::Config;
|
||||
use crate::vm::frank::Frank;
|
||||
use crate::vm::service::FrankService;
|
||||
use crate::misc::SlicePrettyPrinter;
|
||||
|
||||
use exitfailure::ExitFailure;
|
||||
use std::fs;
|
||||
@ -90,7 +92,7 @@ fn main() -> Result<(), ExitFailure> {
|
||||
}
|
||||
"hash" => {
|
||||
let hash = frank.compute_state_hash();
|
||||
println!("vm state hash is {:?}", hash);
|
||||
println!("vm state hash is {:2x}", SlicePrettyPrinter(hash.as_slice()));
|
||||
}
|
||||
"help" => {
|
||||
println!(
|
||||
|
19
src/misc/mod.rs
Normal file
19
src/misc/mod.rs
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2020 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
mod slice_pretty_printer;
|
||||
|
||||
pub use slice_pretty_printer::SlicePrettyPrinter;
|
37
src/misc/slice_pretty_printer.rs
Normal file
37
src/misc/slice_pretty_printer.rs
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2020 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
pub struct SlicePrettyPrinter<'a>(pub &'a [u8]);
|
||||
|
||||
impl<'a> std::fmt::LowerHex for SlicePrettyPrinter<'a> {
|
||||
fn fmt(&self, fmtr: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
fmtr.write_fmt(format_args!("0x"))?;
|
||||
for byte in self.0 {
|
||||
fmtr.write_fmt(format_args!("{:02x}", byte))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> std::fmt::UpperHex for SlicePrettyPrinter<'a> {
|
||||
fn fmt(&self, fmtr: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
fmtr.write_fmt(format_args!("0x"))?;
|
||||
for byte in self.0 {
|
||||
fmtr.write_fmt(format_args!("{:02X}", byte))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user