From 2496b63d62e51af0fb42b80dad61adef6f1c8811 Mon Sep 17 00:00:00 2001 From: green Date: Fri, 20 Jan 2023 13:08:21 +0000 Subject: [PATCH] Return back the "Output Bech32Address for initial accounts" change. https://github.com/FuelLabs/fuel-core/pull/594 This change was done at teh same time with moving of this file into another place, so during conflicts resolving we missed it. --- Cargo.lock | 9 ++++++++- crates/chain-config/Cargo.toml | 1 + crates/chain-config/src/config/chain.rs | 26 ++++++++++++++++++------- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 505612b0cb0..75bc8494dd7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -559,6 +559,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" @@ -992,7 +998,7 @@ checksum = "c94090a6663f224feae66ab01e41a2555a8296ee07b5f20dab8888bdefc9f617" dependencies = [ "base58check", "base64 0.12.3", - "bech32", + "bech32 0.7.3", "blake2", "digest 0.10.6", "generic-array 0.14.6", @@ -2278,6 +2284,7 @@ name = "fuel-core-chain-config" version = "0.15.1" dependencies = [ "anyhow", + "bech32 0.9.1", "bincode", "fuel-core-poa", "fuel-core-storage", diff --git a/crates/chain-config/Cargo.toml b/crates/chain-config/Cargo.toml index 20721cd595d..4878f8c6302 100644 --- a/crates/chain-config/Cargo.toml +++ b/crates/chain-config/Cargo.toml @@ -12,6 +12,7 @@ description = "Fuel Chain config types" [dependencies] anyhow = "1.0" +bech32 = "0.9.0" bincode = "1.3" fuel-core-poa = { path = "../services/consensus_module/poa", version = "0.15.1" } fuel-core-storage = { path = "../storage", version = "0.15.1" } diff --git a/crates/chain-config/src/config/chain.rs b/crates/chain-config/src/config/chain.rs index 3a7c01972c0..8a5b292a12e 100644 --- a/crates/chain-config/src/config/chain.rs +++ b/crates/chain-config/src/config/chain.rs @@ -1,3 +1,7 @@ +use bech32::{ + ToBase32, + Variant::Bech32m, +}; use fuel_core_storage::MerkleRoot; use fuel_core_types::{ fuel_crypto::Hasher, @@ -5,6 +9,7 @@ use fuel_core_types::{ fuel_types::{ Address, AssetId, + Bytes32, }, }; use itertools::Itertools; @@ -17,20 +22,22 @@ use serde::{ Serialize, }; use serde_with::skip_serializing_none; - use std::{ io::ErrorKind, path::PathBuf, str::FromStr, }; -use crate::GenesisCommitment; - -use super::{ - coin::CoinConfig, - state::StateConfig, +use crate::{ + config::{ + coin::CoinConfig, + state::StateConfig, + }, + genesis::GenesisCommitment, }; +// Fuel Network human-readable part for bech32 encoding +pub const FUEL_BECH32_HRP: &str = "fuel"; pub const LOCAL_TESTNET: &str = "local_testnet"; pub const TESTNET_INITIAL_BALANCE: u64 = 10_000_000; @@ -72,10 +79,15 @@ impl ChainConfig { .map(|_| { let secret = fuel_core_types::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({:#x} [bech32: {}]), Balance({})", secret, address, + bech32_encoding, TESTNET_INITIAL_BALANCE ); CoinConfig {