3个版本 (破坏性更新)
0.3.0 | 2024年7月26日 |
---|---|
0.2.0 | 2024年6月17日 |
0.1.0 | 2024年6月17日 |
#288 在 网络编程
每月149次下载
在 pop-cli 中使用
205KB
5.5K SLoC
pop-parachains
用于生成、构建和运行 parachains 和 pallets 的 crate。由 pop-cli
使用。
用法
生成新的 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);
构建 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).unwrap();
生成一个纯链规范文件,并使用特定的 parachain 值对其进行自定义
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).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);
// 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();
生成一个原始链规范文件,并导出 WASM 和创世状态文件
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).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);
// 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();
运行 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;
}
})
生成新的 Pallet
use pop_parachains::{create_pallet_template, TemplatePalletConfig};
let path = "./".to_string();
let pallet_config = TemplatePalletConfig {
name: "MyPallet".to_string(),
authors: "R0GUE".to_string(),
description: "Template pallet".to_string()
};
create_pallet_template(Some(path),pallet_config);
致谢
pop-parachains
的实现离不开出色的 crate:zombienet-sdk。
依赖项
~111MB
~2M SLoC