From 31d874007d24b6e598b79f1f08d2a8defbceebf2 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 21 Jan 2025 16:50:56 +0100 Subject: [PATCH] feat: :sparkles: add genesis builder dummy development preset --- Cargo.lock | 4 ++++ runtime/common/Cargo.toml | 1 + runtime/common/src/apis.rs | 20 ++++++++++++++++++-- runtime/moonbase/Cargo.toml | 1 + runtime/moonbeam/Cargo.toml | 1 + runtime/moonriver/Cargo.toml | 1 + 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1645e4030..a13536f44a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6308,6 +6308,7 @@ dependencies = [ "rlp", "scale-info", "serde", + "serde_json", "session-keys-primitives", "sha3", "smallvec", @@ -6821,6 +6822,7 @@ dependencies = [ "rlp", "scale-info", "serde", + "serde_json", "session-keys-primitives", "sha3", "smallvec", @@ -6913,6 +6915,7 @@ dependencies = [ "parity-scale-codec", "precompile-utils", "scale-info", + "serde_json", "sp-api", "sp-consensus-slots", "sp-core", @@ -7251,6 +7254,7 @@ dependencies = [ "rlp", "scale-info", "serde", + "serde_json", "session-keys-primitives", "sha3", "smallvec", diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index d3c3027be3..19f46062b1 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -11,6 +11,7 @@ version = "0.8.0-dev" hex-literal = "0.3.4" impl-trait-for-tuples = "0.2.1" log = "0.4" +serde_json = { version = "1.0.114", default-features = false } # Moonbeam moonbeam-core-primitives = { workspace = true } diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index 144a82f966..8768edd419 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -43,6 +43,12 @@ macro_rules! impl_runtime_apis_plus_common { } } + fn testnet_genesis() -> serde_json::Value { + let config = RuntimeGenesisConfig::default(); + + serde_json::to_value(config).expect("Could not build genesis config.") + } + impl_runtime_apis! { $($custom)* @@ -121,11 +127,21 @@ macro_rules! impl_runtime_apis_plus_common { } fn get_preset(id: &Option) -> Option> { - frame_support::genesis_builder_helper::get_preset::(id, |_| None) + frame_support::genesis_builder_helper::get_preset::(id, |id| { + let patch = match id.try_into() { + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => testnet_genesis(), + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) + }) } fn preset_names() -> Vec { - vec![] + vec![sp_genesis_builder::PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] } } diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 8d334d43ad..3763413aba 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -14,6 +14,7 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } +serde_json = { version = "1.0.114", default-features = false } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } diff --git a/runtime/moonbeam/Cargo.toml b/runtime/moonbeam/Cargo.toml index 1f87feabe2..249c4f3310 100644 --- a/runtime/moonbeam/Cargo.toml +++ b/runtime/moonbeam/Cargo.toml @@ -14,6 +14,7 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } +serde_json = { version = "1.0.114", default-features = false } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true } diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index 7ac5e41d7d..10faba487d 100644 --- a/runtime/moonriver/Cargo.toml +++ b/runtime/moonriver/Cargo.toml @@ -14,6 +14,7 @@ log = { workspace = true } num_enum = { workspace = true } rlp = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } +serde_json = { version = "1.0.114", default-features = false } sha3 = { workspace = true, optional = true } smallvec = { workspace = true } strum = { workspace = true }