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§
- Call
Data - This struct implements the
Payloadtrait and is used to submit pre-encoded SCALE call data directly, without the dynamic construction of transactions. - Chain
Spec - A chain specification.
- Config
- Configurable settings for parachain generation.
- Constant
- Represents a runtime constant.
- Deterministic
Builder - Builds and executes the command for running a deterministic runtime build process using srtool.
- Extrinsic
Events - The events associated with a given extrinsic.
- Function
- Represents a dispatchable function.
- Index
Set - A hash set where the iteration order of the values is independent of their hash values.
- Network
Node - Information about the Node. External export from Zombienet-SDK.
- Online
Client - A client that can be used to perform API calls (that is, either those
requiring an
OfflineClientTor those requiring anOnlineClientT). - 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.
- Template
Pallet Config - Metadata for the Template Pallet.
- Template
Pallet Config Common Types Iter - An iterator over the variants of TemplatePalletConfigCommonTypes
- Template
Pallet Options Iter - An iterator over the variants of TemplatePalletOptions
- Template
Pallet Storage Types Iter - An iterator over the variants of TemplatePalletStorageTypes
Enums§
- Action
- Enum representing various predefined actions supported.
- Call
Item - Represents different types of callable items that can be interacted with in the runtime.
- Chain
Spec Builder - A builder for generating chain specifications.
- Chain
Template - Templates supported.
- Deployment
Provider - Supported deployment providers.
- Error
- Represents the various errors that can occur in the crate.
- Provider
- Supported template providers.
- Relay
Chain - A supported relay chain.
- Substrate
Config - Default set of commonly used types by Substrate runtimes.
- Supported
Chains - Supported chains with its public RPC endpoints.
- Template
Pallet Config Common Types - This enum is used to register from the CLI which types that are kind of usual in config traits are included in the pallet
- Template
Pallet Options - This enum is used to register from the CLI which options are selected by the user to be included in the pallet.
- Template
Pallet Storage Types - 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
Paramrepresentation. - 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
Valuetypes. - 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
Paramrepresentation.
Type Aliases§
- Dynamic
Payload - The type of a payload typically used for dynamic transaction payloads.