From b597ccc4fdb2e4e0d86159571189ecff8b2fb314 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 15 Dec 2023 10:29:00 +0100 Subject: [PATCH] doc fixed --- .../support/src/genesis_builder_helper.rs | 6 +- .../primitives/genesis-builder/src/lib.rs | 73 +++++++++++-------- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/substrate/frame/support/src/genesis_builder_helper.rs b/substrate/frame/support/src/genesis_builder_helper.rs index 750e41565f4..5cc279d48e0 100644 --- a/substrate/frame/support/src/genesis_builder_helper.rs +++ b/substrate/frame/support/src/genesis_builder_helper.rs @@ -43,8 +43,10 @@ pub fn build_state<GC: BuildGenesisConfig>(json: sp_std::vec::Vec<u8>) -> BuildR Ok(()) } -/// Returns a JSON blob representation of the builtin `GenesisConfig` identified by `id`. -/// For more info refer to [`sp_genesis_builder::GenesisBuilder::get_preset`]. +/// Get the default `GenesisConfig` as a JSON blob if `id` is None. +/// +/// No named presets are supported. For more info refer to +/// [`sp_genesis_builder::GenesisBuilder::get_preset`]. pub fn get_preset<GC>(id: Option<sp_std::vec::Vec<u8>>) -> Option<sp_std::vec::Vec<u8>> where GC: BuildGenesisConfig + Default, diff --git a/substrate/primitives/genesis-builder/src/lib.rs b/substrate/primitives/genesis-builder/src/lib.rs index 85ad81458e5..85a5d875cf1 100644 --- a/substrate/primitives/genesis-builder/src/lib.rs +++ b/substrate/primitives/genesis-builder/src/lib.rs @@ -19,59 +19,68 @@ //! Substrate genesis config builder //! -//! The runtime may provide a number of partial `GenesisConfig` configurations in form of patches -//! which shall be applied on top of the default GenesisConfig. This presets are sometimes refered -//! to as patches. This allows the runtime to provide a number of predefined configuration (e.g. for -//! different testnets) without leaking the runtime types outside the runtime. +//! The runtime may provide a number of partial `RuntimeGenesisConfig` configurations in form of +//! patches which shall be applied on top of the default `RuntimeGenesisConfig`. Thus presets are +//! sometimes refered to as patches. This allows the runtime to provide a number of predefined +//! configuration (e.g. for different testnets) without leaking the runtime types outside the +//! runtime. //! -//! This Runtime API allows to construct `GenesisConfig`, in particular: -//! - serialize the runtime default `GenesisConfig` struct into json format, -//! - put the GenesisConfig struct into the storage. Internally this operation calls -//! `GenesisBuild::build` function for all runtime pallets, which is typically provided by -//! pallet's author. -//! - deserialize the `GenesisConfig` from given json blob and put `GenesisConfig` into the state -//! storage. Allows to build customized configuration. -//! - provide a named, built-in, predefined preset of `GenesisConfig`, -//! - provide the list of preset names, +//! This Runtime API allows to interact with `RuntimeGenesisConfig`, in particular: +//! - provide the list of available preset names, +//! - provide a number of named, built-in, presets of `RuntimeGenesisConfig`, +//! - serialize the default `RuntimeGenesisConfig` struct into json format, +//! - deserialize the `RuntimeGenesisConfig` from given json blob and put the resulting +//! `RuntimeGenesisConfig` into the state storage creating the initial runtime's state. Allows to +//! build customized genesis. This operation internally calls `GenesisBuild::build` function for +//! all runtime pallets. //! -//! Providing externalities with empty storage and putting `GenesisConfig` into storage allows to -//! catch and build the raw storage of `GenesisConfig` which is the foundation for genesis block. +//! Providing externalities with empty storage and putting `RuntimeGenesisConfig` into storage +//! allows to catch and build the raw storage of `RuntimeGenesisConfig` which is the foundation for +//! genesis block. /// The result type alias, used in build methods. `Err` contains formatted error message. pub type Result = core::result::Result<(), sp_runtime::RuntimeString>; sp_api::decl_runtime_apis! { - /// API to interact with GenesisConfig for the runtime + /// API to interact with RuntimeGenesisConfig for the runtime #[api_version(2)] pub trait GenesisBuilder { - /// Creates the default `GenesisConfig` and returns it as a JSON blob. + /// Creates the default `RuntimeGenesisConfig` and returns it as a JSON blob. /// - /// This function instantiates the default `GenesisConfig` struct for the runtime and serializes it into a JSON - /// blob. It returns a `Vec<u8>` containing the JSON representation of the default `GenesisConfig`. + /// This function instantiates the default `RuntimeGenesisConfig` struct for the runtime and + /// serializes it into a JSON blob. It returns a `Vec<u8>` containing the JSON + /// representation of the default `RuntimeGenesisConfig`. fn create_default_config() -> sp_std::vec::Vec<u8>; - /// Build `GenesisConfig` from a JSON blob not using any defaults and store it in the storage. + /// Build `RuntimeGenesisConfig` from a JSON blob not using any defaults and store it in the + /// storage. /// - /// This function deserializes the full `GenesisConfig` from the given JSON blob and puts it into the storage. - /// If the provided JSON blob is incorrect or incomplete or the deserialization fails, an error is returned. - /// It is recommended to log any errors encountered during the process. + /// This function deserializes the full `RuntimeGenesisConfig` from the given JSON blob and + /// puts it into the storage. If the provided JSON blob is incorrect or incomplete or the + /// deserialization fails, an error is returned. /// - /// Please note that provided json blob must contain all `GenesisConfig` fields, no defaults will be used. + /// Please note that provided json blob must contain all `RuntimeGenesisConfig` fields, no + /// defaults will be used. #[renamed("build_config", 2)] fn build_state(json: sp_std::vec::Vec<u8>) -> Result; - /// Returns a JSON blob representation of the builtin `GenesisConfig` identified by `id`. + /// Returns a JSON blob representation of the built-in `RuntimeGenesisConfig` identified by + /// `id`. /// - /// If `id` is `None` the function instantiates the default `GenesisConfig` struct for the runtime and serializes it into a JSON - /// blob. It returns a `Vec<u8>` containing the JSON representation of the default `GenesisConfig`. - /// Otherwise returns a JSON representation of the built-in, named, pre-configured `GenesisConfig` value. + /// If `id` is `None` the function returns JSON blob representation of the default + /// `RuntimeGenesisConfig` struct of the runtime. Implementation must provide default + /// `RuntimeGenesisConfig`. + /// + /// Otherwise function returns a JSON representation of the built-in, named + /// `RuntimeGenesisConfig` preset identified by `id`, or `None` if such preset does not + /// exists. Returned `Vec<u8>` contains bytes of JSON blob. #[api_version(2)] - fn get_preset(id: Option<sp_std::vec::Vec<u8>>) -> Option<sp_std::vec::Vec<u8>>; + fn get_preset(id: Option<sp_runtime::RuntimeString>) -> Option<sp_std::vec::Vec<u8>>; - /// Returns a list of available builtin `GenesisConfig` presets. + /// Returns a list of names for available builtin `RuntimeGenesisConfig` presets. /// - /// The presets from the list can be queried with [`GenesisBuilder::get_preset`] method. If no named presets are - /// provided by the runtime the list is empty. + /// The presets from the list can be queried with [`GenesisBuilder::get_preset`] method. If + /// no named presets are provided by the runtime the list is empty. #[api_version(2)] fn preset_names() -> sp_std::vec::Vec<sp_runtime::RuntimeString>; } -- GitLab