Change type of extra fields in ConfigAndPreset (#2913)
## Issue Addressed #2900 ## Proposed Changes Change type of extra_fields in ConfigAndPreset so it can contain non string values (inside serde_json::Value)
This commit is contained in:
parent
d06f87486a
commit
0116c8d464
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -6495,6 +6495,7 @@ dependencies = [
|
||||
"safe_arith",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"serde_yaml",
|
||||
"slog",
|
||||
"state_processing",
|
||||
|
@ -44,6 +44,7 @@ lazy_static = "1.4.0"
|
||||
parking_lot = "0.11.1"
|
||||
itertools = "0.10.0"
|
||||
superstruct = "0.4.0"
|
||||
serde_json = "1.0.74"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3.3"
|
||||
|
@ -1,5 +1,6 @@
|
||||
use crate::{AltairPreset, BasePreset, BellatrixPreset, ChainSpec, Config, EthSpec};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Fusion of a runtime-config with the compile-time preset values.
|
||||
@ -19,7 +20,7 @@ pub struct ConfigAndPreset {
|
||||
// pub bellatrix_preset: BellatrixPreset,
|
||||
/// The `extra_fields` map allows us to gracefully decode fields intended for future hard forks.
|
||||
#[serde(flatten)]
|
||||
pub extra_fields: HashMap<String, String>,
|
||||
pub extra_fields: HashMap<String, Value>,
|
||||
}
|
||||
|
||||
impl ConfigAndPreset {
|
||||
@ -83,7 +84,7 @@ impl ConfigAndPreset {
|
||||
),
|
||||
];
|
||||
for (key, value) in fields {
|
||||
self.extra_fields.insert(key.to_uppercase(), value);
|
||||
self.extra_fields.insert(key.to_uppercase(), value.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -107,8 +108,13 @@ mod test {
|
||||
let mut yamlconfig = ConfigAndPreset::from_chain_spec::<MainnetEthSpec>(&mainnet_spec);
|
||||
let (k1, v1) = ("SAMPLE_HARDFORK_KEY1", "123456789");
|
||||
let (k2, v2) = ("SAMPLE_HARDFORK_KEY2", "987654321");
|
||||
let (k3, v3) = ("SAMPLE_HARDFORK_KEY3", 32);
|
||||
let (k4, v4) = ("SAMPLE_HARDFORK_KEY4", Value::Null);
|
||||
yamlconfig.extra_fields.insert(k1.into(), v1.into());
|
||||
yamlconfig.extra_fields.insert(k2.into(), v2.into());
|
||||
yamlconfig.extra_fields.insert(k3.into(), v3.into());
|
||||
yamlconfig.extra_fields.insert(k4.into(), v4);
|
||||
|
||||
serde_yaml::to_writer(writer, &yamlconfig).expect("failed to write or serialize");
|
||||
|
||||
let reader = OpenOptions::new()
|
||||
|
Loading…
Reference in New Issue
Block a user