Skip to main content

Crate pop_chains

Crate pop_chains 

Source
Expand description

§pop-chains

A crate for generating, building and running chains and pallets. Used by pop-cli.

§Usage

Generate a new chain:

use pop_chains::{instantiate_template_dir, Config, ChainTemplate};
use std::path::Path;

let destination_path = Path::new("./");
let tag_version = None; // Latest
let config = Config {
    symbol: "UNIT".to_string(),
    decimals: 12,
    initial_endowment: "1u64 << 60".to_string()
};
let tag = instantiate_template_dir(&ChainTemplate::Standard, &destination_path, tag_version, config);

Build a chain:

use pop_common::Profile;
use pop_chains::ChainSpecBuilder;
use std::path::Path;

let path = Path::new("./");
let builder = ChainSpecBuilder::Node { node_path: path.join("node"), default_bootnode: false, profile: Profile::Release };
let binary_path = builder.build(&[], false).unwrap();

Build a chain with runtime-benchmarks feature:

let binary_path = builder.build(&["runtime-benchmarks".to_string()], false).unwrap();

Generate a plain chain specification file and customize it with your specific chain values:

use pop_common::Profile;
use pop_chains::{ChainSpecBuilder, ChainSpec};
use std::path::Path;

let path = Path::new("./"); // Location of the parachain project.
let builder = ChainSpecBuilder::Node { node_path: path.join("node"), default_bootnode: false, profile: Profile::Release };
let spec_name = "MySpec";
let spec_id = "my_spec";
// Build the node binary first
builder.build(&[], false).unwrap();
// Generate a plain chain specification file of a parachain
let plain_chain_spec_path = path.join("plain-parachain-chainspec.json");
builder.generate_plain_chain_spec("dev", &plain_chain_spec_path, Some(spec_name), Some(spec_id)).unwrap();
// Customize your chain specification
let mut chain_spec = ChainSpec::from(&plain_chain_spec_path).unwrap();
chain_spec.replace_para_id(2002);
chain_spec.replace_relay_chain("paseo-local");
chain_spec.replace_chain_type("Development");
chain_spec.replace_protocol_id("my-protocol");
// Writes the chain specification to a file
chain_spec.to_file(&plain_chain_spec_path).unwrap();

Generate a raw chain specification file and export the WASM and genesis state files:

use pop_common::Profile;
use pop_chains::{ChainSpecBuilder, generate_genesis_state_file_with_node};
use std::path::Path;

let path = Path::new("./"); // Location of the parachain project.
let builder = ChainSpecBuilder::Node { node_path: path.join("node"), default_bootnode: false, profile: Profile::Release };
let spec_name = "MySpec";
let spec_id = "my_spec";
// Build the node binary first
let binary_path = builder.build(&[], false).unwrap();
// Generate a plain chain specification file of a parachain
let plain_chain_spec_path = path.join("plain-parachain-chainspec.json");
builder.generate_plain_chain_spec("dev", &plain_chain_spec_path, Some(spec_name), Some(spec_id)).unwrap();
// Generate a raw chain specification file of a parachain
let chain_spec = builder.generate_raw_chain_spec(&plain_chain_spec_path, "raw-parachain-chainspec.json").unwrap();
// Export the WebAssembly runtime for the parachain.
let wasm_file = builder.export_wasm_file(&chain_spec, "para-2000-wasm").unwrap();
// Generate the parachain genesis state.
let genesis_state_file = generate_genesis_state_file_with_node(&binary_path, &chain_spec, "para-2000-genesis-state").unwrap();

Run a chain:

use pop_chains::up::Zombienet;
use std::path::Path;
use tokio_test;

tokio_test::block_on(async {
    let cache = Path::new("./cache"); // The cache location, used for caching binaries.
    let network_config = Path::new("network.toml").try_into().unwrap(); // The configuration file to be used to launch a network.
    let relay_chain_version = None; // Latest
    let relay_chain_runtime_version = None; // Latest
    let system_parachain_version = None; // Latest
    let system_parachain_runtime_version = None; // Latest
    let parachains = None; // The parachain(s) specified.

    let mut zombienet = Zombienet::new(
        &cache,
        network_config,
        relay_chain_version,
        relay_chain_runtime_version,
        system_parachain_version,
        system_parachain_runtime_version,
        parachains,
    ).await.unwrap();

    zombienet.spawn().await;

    //To download the missing binaries before starting the network:
    let release = true; // Whether the binary should be built using the release profile.
    let status = {}; // Mechanism to observe status updates
    let verbose = false; // Whether verbose output is required
    let missing = zombienet.binaries();
    for binary in missing {
        binary.source(release, &status, verbose).await;
    }
})

Generate a new Pallet:

use pop_chains::{create_pallet_template, TemplatePalletConfig};
use std::path::PathBuf;

let path = "./";
let pallet_config = TemplatePalletConfig {
    authors: "R0GUE".to_string(),
    description: "Template pallet".to_string(),
    pallet_in_workspace: false,
    pallet_advanced_mode: true,
    pallet_default_config: true,
    pallet_common_types: Vec::new(),
    pallet_storage: Vec::new(),
    pallet_genesis: false,
    pallet_custom_origin: false,
};

create_pallet_template(PathBuf::from(path),pallet_config);

§Acknowledgements

pop-chains would not be possible without the awesome crate: zombienet-sdk.

Re-exports§

pub use bench::BenchmarkingCliCommand;
pub use bench::GENESIS_BUILDER_DEV_PRESET;
pub use bench::GenesisBuilderPolicy;
pub use bench::PalletExtrinsicsRegistry;
pub use bench::generate_binary_benchmarks;
pub use bench::generate_omni_bencher_benchmarks;
pub use bench::generate_pallet_benchmarks;
pub use bench::get_runtime_path;
pub use bench::load_pallet_extrinsics;
pub use try_runtime::TryRuntimeCliCommand;
pub use try_runtime::parse;
pub use try_runtime::parse_try_state_string;
pub use try_runtime::run_try_runtime;
pub use try_runtime::state;
pub use try_runtime::try_state_details;
pub use try_runtime::try_state_label;
pub use try_runtime::upgrade_checks_details;
pub use utils::helpers::get_preset_names;
pub use utils::helpers::is_initial_endowment_valid;
pub use bench::binary::*;
pub use try_runtime::binary::*;
pub use try_runtime::shared_parameters::*;

Modules§

bench
Provides functionality for benchmarking.
omni_node
Provides functionality for running runtime-only parachains.
registry
A registry of parachains.
runtime
Build the deterministic runtime.
try_runtime
Provides functionality for testing runtime upgrades.
up
Provides functionality for launching a local network.
utils
General utility functions and helpers.

Structs§

CallData
This struct implements the Payload trait and is used to submit pre-encoded SCALE call data directly, without the dynamic construction of transactions.
ChainSpec
A chain specification.
Config
Configurable settings for parachain generation.
Constant
Represents a runtime constant.
DeterministicBuilder
Builds and executes the command for running a deterministic runtime build process using srtool.
ExtrinsicEvents
The events associated with a given extrinsic.
Function
Represents a dispatchable function.
IndexSet
A hash set where the iteration order of the values is independent of their hash values.
NetworkNode
Information about the Node. External export from Zombienet-SDK.
OnlineClient
A client that can be used to perform API calls (that is, either those requiring an OfflineClientT or those requiring an OnlineClientT).
Pallet
Represents a pallet in the blockchain, including its dispatchable functions.
Param
Describes a parameter of a dispatchable function.
Reserved
A event emitted when an id has been registered.
Storage
Represents a storage item.
TemplatePalletConfig
Metadata for the Template Pallet.
TemplatePalletConfigCommonTypesIter
An iterator over the variants of TemplatePalletConfigCommonTypes
TemplatePalletOptionsIter
An iterator over the variants of TemplatePalletOptions
TemplatePalletStorageTypesIter
An iterator over the variants of TemplatePalletStorageTypes

Enums§

Action
Enum representing various predefined actions supported.
CallItem
Represents different types of callable items that can be interacted with in the runtime.
ChainSpecBuilder
A builder for generating chain specifications.
ChainTemplate
Templates supported.
DeploymentProvider
Supported deployment providers.
Error
Represents the various errors that can occur in the crate.
Provider
Supported template providers.
RelayChain
A supported relay chain.
SubstrateConfig
Default set of commonly used types by Substrate runtimes.
SupportedChains
Supported chains with its public RPC endpoints.
TemplatePalletConfigCommonTypes
This enum is used to register from the CLI which types that are kind of usual in config traits are included in the pallet
TemplatePalletOptions
This enum is used to register from the CLI which options are selected by the user to be included in the pallet.
TemplatePalletStorageTypes
This enum is used to determine which storage shape has a storage item in the pallet

Traits§

Payload
This represents a transaction payload that can be submitted to a node.

Functions§

binary_path
Constructs the node binary path based on the target path and the node directory path.
build_chain
Build the chain and returns the path to the binary.
build_project
Build the Rust project.
clear_dmpq
Clears the DMPQ state for the given parachain IDs.
construct_extrinsic
Constructs a dynamic extrinsic payload for a specified dispatchable function.
construct_proxy_extrinsic
Constructs a Proxy call extrinsic.
construct_sudo_extrinsic
Constructs a Sudo extrinsic.
create_pallet_template
Create a new pallet from a template.
decode_call_data
Decodes a hex-encoded string into a vector of bytes representing the call data.
encode_call_data
Encodes the call data for a given extrinsic into a hexadecimal string.
export_wasm_file_with_node
Export the WebAssembly runtime for the chain.
field_to_param
Transforms a metadata field into its Param representation.
find_callable_by_name
Finds a specific dispatchable function by name and retrieves its details from metadata.
find_pallet_by_name
Finds a specific pallet by name and retrieves its details from metadata.
generate_genesis_state_file_with_node
Generate the chain genesis state.
generate_plain_chain_spec_with_node
Generates the plain text chain specification for a chain with its own node.
generate_raw_chain_spec_with_node
Generates a raw chain specification file for a chain.
instantiate_template_dir
Create a new chain.
is_supported
Determines whether the manifest at the supplied path is a supported chain project.
parse_and_format_events
Parses and formats the events from the extrinsic result.
parse_chain_metadata
Parses the chain metadata to extract information about pallets and their dispatchable functions.
parse_dispatchable_arguments
Parses and processes raw string parameter values for a dispatchable function, mapping them to Value types.
raw_value_to_string
Converts a raw SCALE value to a human-readable string representation.
render_storage_key_values
Renders storage key-value pairs into a human-readable string format.
runtime_binary_path
Constructs the runtime binary path based on the target path and the directory path.
set_up_client
Sets up an OnlineClient instance for connecting to a blockchain.
sign_and_submit_extrinsic
Signs and submits a given extrinsic.
submit_signed_extrinsic
Submits a signed extrinsic.
supported_actions
Fetch the list of supported actions based on available pallets.
type_to_param
Converts a type’s metadata into a Param representation.

Type Aliases§

DynamicPayload
The type of a payload typically used for dynamic transaction payloads.