Crate pop_parachains

Source
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§

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.
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.
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
Zombienet
Configuration to launch a local network.

Enums§

Action
Enum representing various predefined actions supported.
ContainerEngine
Represents the container engine being used.
DeploymentProvider
Supported deployment providers.
Error
Represents the various errors that can occur in the crate.
Parachain
Templates supported.
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_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§

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