Skip to content

Commit 8e332ea

Browse files
committed
Added address-converter tool
1 parent d21bca1 commit 8e332ea

5 files changed

Lines changed: 43 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["app/*", "contracts/*", "packages/*"]
2+
members = ["app/*", "contracts/*", "packages/*", "tools/address-converter"]
33
exclude = ["tools/proto-compiler"]
44
resolver = "2"
55

@@ -67,6 +67,8 @@ cosmos-sdk-proto = { version = "0.18.0", default-features = false, features = ["
6767
cw-orch-core = { version = "1"}
6868
abstract-cw-multi-test = { version = "1", default-features = false }
6969

70+
alloy-primitives = { version = "0.8.2", default-features = false }
71+
7072
[profile.release]
7173
# temporary to speed up testing
7274
# lto = true

packages/std/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,4 @@ bytes = { workspace = true }
2121
hex = { workspace = true }
2222
chrono = { version = "0.4.19", default-features = false, features = ["std"] }
2323
derivative = "2.2.0"
24-
25-
# TODO: move this up to top level Cargo if it works out
26-
alloy-primitives = { version = "0.8.2", default-features = false }
24+
alloy-primitives = { workspace = true }

tools/address-converter/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "address-converter"
3+
edition.workspace = true
4+
version.workspace = true
5+
license.workspace = true
6+
exclude.workspace = true
7+
8+
[dependencies]
9+
bech32 = { version = "0.11" }
10+
alloy-primitives = { workspace = true }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use std::env;
2+
3+
use alloy_primitives::Address;
4+
5+
// Usage: cargo run slay3r1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmvk3r3j
6+
7+
fn main() {
8+
let args: Vec<_> = env::args().collect();
9+
if args.len() < 2 {
10+
println!("Usage: address-converter <bech32addr> ...");
11+
return;
12+
}
13+
for addr in &args[1..] {
14+
let (_, data) = bech32::decode(addr).unwrap();
15+
if data.len() != 20 {
16+
println!("{} isn't 20 bytes long", addr);
17+
}
18+
let addr = Address(data.as_slice().try_into().unwrap());
19+
println!("{}", addr);
20+
}
21+
}

0 commit comments

Comments
 (0)