Expand description
§pop-parachains
A crate for generating, building and running parachains and pallets. Used by
pop-cli.
§Usage
Generate a new parachain:
use pop_parachains::{instantiate_template_dir, Config, Parachain};
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(&Parachain::Standard, &destination_path, tag_version, config);Build a Parachain:
use pop_common::Profile;
use pop_parachains::build_parachain;
use std::path::Path;
let path = Path::new("./");
let package = None; // The optional package to be built.
let binary_path = build_parachain(&path, package, &Profile::Release, None, vec![]).unwrap();Build a Parachain with runtime-benchmarks feature:
let binary_path = build_parachain(&path, package, &Profile::Release, None, vec!["runtime-benchmarks"]).unwrap();Generate a plain chain specification file and customize it with your specific parachain values:
use pop_common::Profile;
use pop_parachains::{build_parachain, export_wasm_file, generate_plain_chain_spec, generate_raw_chain_spec, generate_genesis_state_file, ChainSpec};
use std::path::Path;
let path = Path::new("./"); // Location of the parachain project.
let package = None; // The optional package to be built.
// The path to the node binary executable.
let binary_path = build_parachain(&path, package, &Profile::Release, None, vec![]).unwrap();;
// Generate a plain chain specification file of a parachain
let plain_chain_spec_path = path.join("plain-parachain-chainspec.json");
generate_plain_chain_spec(&binary_path, &plain_chain_spec_path, true, "dev");
// 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_parachains::{build_parachain, export_wasm_file, generate_plain_chain_spec, generate_raw_chain_spec, generate_genesis_state_file};
use std::path::Path;
let path = Path::new("./"); // Location of the parachain project.
let package = None; // The optional package to be built.
// The path to the node binary executable.
let binary_path = build_parachain(&path, package, &Profile::Release, None, vec![]).unwrap();;
// Generate a plain chain specification file of a parachain
let plain_chain_spec_path = path.join("plain-parachain-chainspec.json");
generate_plain_chain_spec(&binary_path, &plain_chain_spec_path, true, "dev");
// Generate a raw chain specification file of a parachain
let chain_spec = generate_raw_chain_spec(&binary_path, &plain_chain_spec_path, "raw-parachain-chainspec.json").unwrap();
// Export the WebAssembly runtime for the parachain.
let wasm_file = export_wasm_file(&binary_path, &chain_spec, "para-2000-wasm").unwrap();
// Generate the parachain genesis state.
let genesis_state_file = generate_genesis_state_file(&binary_path, &chain_spec, "para-2000-genesis-state").unwrap();Run a Parachain:
use pop_parachains::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 = "network.toml"; // 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_parachains::{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-parachains would not be possible without the awesome
crate: zombienet-sdk.
Re-exports§
pub use bench::generate_binary_benchmarks;pub use bench::generate_omni_bencher_benchmarks;pub use bench::generate_pallet_benchmarks;pub use bench::get_preset_names;pub use bench::get_runtime_path;pub use bench::load_pallet_extrinsics;pub use bench::BenchmarkingCliCommand;pub use bench::GenesisBuilderPolicy;pub use bench::PalletExtrinsicsRegistry;pub use bench::GENESIS_BUILDER_DEV_PRESET;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 try_runtime::TryRuntimeCliCommand;pub use bench::binary::*;pub use try_runtime::binary::*;pub use try_runtime::shared_parameters::*;
Modules§
- bench
- Provides functionality for benchmarking.
- runtime
- Build the deterministic runtime.
- try_
runtime - Provides functionality for testing runtime upgrades.
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.
- 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.
- 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
- Zombienet
- Configuration to launch a local network.
Enums§
- Action
- Enum representing various predefined actions supported.
- Container
Engine - Represents the container engine being used.
- Deployment
Provider - Supported deployment providers.
- Error
- Represents the various errors that can occur in the crate.
- Parachain
- Templates supported.
- 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_
parachain - Build the parachain 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 - Export the WebAssembly runtime for the parachain.
- find_
dispatchable_ 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 - Generate the parachain genesis state.
- generate_
plain_ chain_ spec - Generates the plain text chain specification for a parachain.
- generate_
raw_ chain_ spec - Generates a raw chain specification file for a parachain.
- instantiate_
template_ dir - Create a new parachain.
- is_
initial_ endowment_ valid - Check if the initial endowment input by the user is a valid balance.
- is_
supported - Determines whether the manifest at the supplied path is a supported parachain 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.
- 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 Aliases§
- Dynamic
Payload - The type of a payload typically used for dynamic transaction payloads.