From f96bcb6a9e7f4a89a9708fc976468c623b59aa41 Mon Sep 17 00:00:00 2001 From: Kaya Gokalp Date: Sun, 4 Sep 2022 20:38:59 -0700 Subject: [PATCH 1/2] Output Bech32Address for initial accounts --- Cargo.lock | 10 ++++++++-- fuel-core/Cargo.toml | 1 + fuel-core/src/chain_config.rs | 12 ++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ebce38d3c3..e7943865cba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -638,6 +638,12 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dabbe35f96fb9507f7330793dc490461b2962659ac5d427181e451a623751d1" +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + [[package]] name = "bincode" version = "1.3.3" @@ -1046,7 +1052,7 @@ checksum = "c94090a6663f224feae66ab01e41a2555a8296ee07b5f20dab8888bdefc9f617" dependencies = [ "base58check", "base64 0.12.3", - "bech32", + "bech32 0.7.3", "blake2", "digest 0.10.3", "generic-array 0.14.5", @@ -2105,6 +2111,7 @@ dependencies = [ "async-graphql", "async-trait", "axum", + "bech32 0.9.1", "bincode", "byteorder", "chrono", @@ -2130,7 +2137,6 @@ dependencies = [ "insta", "itertools", "lazy_static", - "prometheus", "rand 0.8.5", "rocksdb", "serde", diff --git a/fuel-core/Cargo.toml b/fuel-core/Cargo.toml index 1144042ad92..6c681010619 100644 --- a/fuel-core/Cargo.toml +++ b/fuel-core/Cargo.toml @@ -26,6 +26,7 @@ async-graphql = { version = "4.0", features = [ ] } async-trait = "0.1" axum = { version = "0.4" } +bech32 = "0.9.0" bincode = "1.3" byteorder = "1.4.3" chrono = { version = "0.4", features = ["serde"] } diff --git a/fuel-core/src/chain_config.rs b/fuel-core/src/chain_config.rs index ff333f3034b..2813e1a3042 100644 --- a/fuel-core/src/chain_config.rs +++ b/fuel-core/src/chain_config.rs @@ -1,4 +1,5 @@ use crate::{database::Database, model::BlockHeight}; +use bech32::{ToBase32, Variant::Bech32m}; use fuel_core_interfaces::{ common::{ fuel_tx::ConsensusParameters, @@ -14,6 +15,9 @@ use serde_with::{serde_as, skip_serializing_none}; use serialization::{HexNumber, HexType}; use std::{io::ErrorKind, path::PathBuf, str::FromStr}; +// Fuel Network human-readable part for bech32 encoding +pub const FUEL_BECH32_HRP: &str = "fuel"; + pub mod serialization; pub const LOCAL_TESTNET: &str = "local_testnet"; @@ -49,10 +53,14 @@ impl ChainConfig { .map(|_| { let secret = fuel_core_interfaces::common::fuel_crypto::SecretKey::random(&mut rng); let address = Address::from(*secret.public_key().hash()); + let bech32_data = Bytes32::new(*address).to_base32(); + let bech32_encoding = + bech32::encode(FUEL_BECH32_HRP, &bech32_data, Bech32m).unwrap(); + tracing::info!( - "PrivateKey({:#x}), Address({:#x}), Balance({})", + "PrivateKey({:#x}), Address({}), Balance({})", secret, - address, + bech32_encoding, TESTNET_INITIAL_BALANCE ); CoinConfig { From f1ee2cd33625150bf1667941dd6847c99ed6cb16 Mon Sep 17 00:00:00 2001 From: Kaya Gokalp Date: Fri, 16 Sep 2022 12:07:12 +0300 Subject: [PATCH 2/2] print both versions for address --- fuel-core/src/chain_config.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fuel-core/src/chain_config.rs b/fuel-core/src/chain_config.rs index 33bb1a098ac..e5b769e3ec2 100644 --- a/fuel-core/src/chain_config.rs +++ b/fuel-core/src/chain_config.rs @@ -92,8 +92,9 @@ impl ChainConfig { bech32::encode(FUEL_BECH32_HRP, &bech32_data, Bech32m).unwrap(); tracing::info!( - "PrivateKey({:#x}), Address({}), Balance({})", + "PrivateKey({:#x}), Address({:#x} [bech32: {}]), Balance({})", secret, + address, bech32_encoding, TESTNET_INITIAL_BALANCE );