Skip to content

Commit

Permalink
chain-config features
Browse files Browse the repository at this point in the history
  • Loading branch information
bvrooman committed Oct 13, 2023
1 parent eeb02a1 commit 79ad7f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 8 additions & 6 deletions crates/chain-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,25 @@ description = "Fuel Chain config types"

[dependencies]
anyhow = { workspace = true }
bech32 = "0.9.0"
bech32 = { version = "0.9.0", optional = true }
fuel-core-storage = { workspace = true }
fuel-core-types = { workspace = true, default-features = false, features = ["serde"] }
hex = { version = "0.4", features = ["serde"] }
itertools = { workspace = true }
itertools = { workspace = true, optional = true }
postcard = { version = "1.0", features = ["use-std"] }
rand = { workspace = true }
rand = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive", "rc"] }
serde_json = { version = "1.0", features = ["raw_value"], optional = true }
serde_with = "1.11"
tracing = "0.1"
tracing = { version = "0.1", optional = true }

[dev-dependencies]
insta = { workspace = true }
serde_json = { version = "1.0", features = ["raw_value"] }

[features]
default = ["random", "std"]
random = ["fuel-core-types/random"]
default = ["local"]
local = ["dep:bech32", "dep:itertools", "random", "std", "tracing"]
random = ["dep:rand", "fuel-core-types/random"]
std = ["dep:serde_json", "fuel-core-types/std", "anyhow/std"]
tracing = ["dep:tracing"]
11 changes: 7 additions & 4 deletions crates/chain-config/src/config/chain.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "local")]
use bech32::{
ToBase32,
Variant::Bech32m,
Expand All @@ -14,11 +15,12 @@ use fuel_core_types::{
fuel_types::{
Address,
AssetId,
Bytes32,
},
fuel_vm::SecretKey,
};
#[cfg(feature = "local")]
use itertools::Itertools;
#[cfg(feature = "random")]
use rand::{
rngs::StdRng,
SeedableRng,
Expand Down Expand Up @@ -81,7 +83,7 @@ impl Default for ChainConfig {
impl ChainConfig {
pub const BASE_ASSET: AssetId = AssetId::zeroed();

#[cfg(feature = "random")]
#[cfg(feature = "local")]
pub fn local_testnet() -> Self {
// endow some preset accounts with an initial balance
tracing::info!("Initial Accounts");
Expand All @@ -90,7 +92,8 @@ impl ChainConfig {
.map(|_| {
let secret = SecretKey::random(&mut rng);
let address = Address::from(*secret.public_key().hash());
let bech32_data = Bytes32::new(*address).to_base32();
let bech32_data =
fuel_core_types::fuel_types::Bytes32::new(*address).to_base32();
let bech32_encoding =
bech32::encode(FUEL_BECH32_HRP, bech32_data, Bech32m).unwrap();
tracing::info!(
Expand Down Expand Up @@ -140,7 +143,7 @@ impl FromStr for ChainConfig {

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
#[cfg(feature = "random")]
#[cfg(feature = "local")]
LOCAL_TESTNET => Ok(Self::local_testnet()),
s => {
// Attempt to load chain config from path
Expand Down

0 comments on commit 79ad7f4

Please sign in to comment.