hash_tool/
main.rs

1use structopt::StructOpt;
2
3#[derive(StructOpt)]
4enum Arg {
5    Ledger {
6        #[structopt(long)]
7        hash: String,
8    },
9    State {
10        #[structopt(long)]
11        hash: String,
12    },
13    PendingCoinbase {
14        #[structopt(long)]
15        hash: String,
16    },
17}
18
19fn main() {
20    let arg = Arg::from_args();
21    let (version, hash) = match arg {
22        Arg::Ledger { hash } => (5, hash),
23        Arg::State { hash } => (16, hash),
24        Arg::PendingCoinbase { hash } => (12, hash),
25    };
26    let x = if let Ok(mut bytes) = hex::decode(format!("{hash}01")) {
27        bytes.reverse();
28        bs58::encode(bytes)
29            .with_check_version(version)
30            .into_string()
31    } else {
32        let mut bytes = bs58::decode(hash)
33            .with_check(Some(version))
34            .into_vec()
35            .unwrap();
36        bytes.reverse();
37        hex::encode(&bytes[..(bytes.len() - 2)])
38    };
39    println!("{x}");
40}
41// jwrPvAMUNo3EKT2puUk5Fxz6B7apRAoKNTGpAA49t3TRSfzvdrL
42// 636f5b2d67278e17bc4343c7c23fb4991f8cf0bbbfd8558615b124d5d62548