Skip to content

Commit

Permalink
feat: ✨ add genesis builder dummy development preset
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmauro committed Jan 21, 2025
1 parent 1c4e1d0 commit 31d8740
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
20 changes: 18 additions & 2 deletions runtime/common/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*

Expand Down Expand Up @@ -121,11 +127,21 @@ macro_rules! impl_runtime_apis_plus_common {
}

fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
frame_support::genesis_builder_helper::get_preset::<RuntimeGenesisConfig>(id, |_| None)
frame_support::genesis_builder_helper::get_preset::<RuntimeGenesisConfig>(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<sp_genesis_builder::PresetId> {
vec![]
vec![sp_genesis_builder::PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)]
}
}

Expand Down
1 change: 1 addition & 0 deletions runtime/moonbase/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions runtime/moonbeam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions runtime/moonriver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 31d8740

Please sign in to comment.