显示此包…

1 个稳定版本

2.0.0 2021 年 4 月 5 日
0.0.0 2021 年 3 月 4 日

#25 in #tetcoin

Download history 23/week @ 2024-03-15 28/week @ 2024-03-22 64/week @ 2024-03-29 20/week @ 2024-04-05 19/week @ 2024-04-12 23/week @ 2024-04-19 19/week @ 2024-04-26 19/week @ 2024-05-03 22/week @ 2024-05-10 20/week @ 2024-05-17 20/week @ 2024-05-24 20/week @ 2024-05-31 17/week @ 2024-06-07 19/week @ 2024-06-14 18/week @ 2024-06-21 10/week @ 2024-06-28

66 每月下载次数
用于 25 个包 (6 直接)

GPL-3.0-or-later…

2MB
40K SLoC

Tetcore 链配置。

此包包含用于声明特定运行时配置文件(即链规范)的结构和实用工具。

包含所有必需参数的基本链规范类型是 ChainSpec。它可以扩展为包含特定于您的链的配置选项。通常,扩展将是 Tetcore 核心模块公开的类型组合。为了允许核心模块从您的扩展中检索其配置,您应使用此包公开的 ChainSpecExtension 宏。

use std::collections::HashMap;
use tc_chain_spec::{GenericChainSpec, ChainSpecExtension};

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecExtension)]
pub struct MyExtension {
		pub known_blocks: HashMap<u64, String>,
}

pub type MyChainSpec<G> = GenericChainSpec<G, MyExtension>;

某些参数可能需要根据当前区块链高度(即分叉)具有不同的值。您可以使用 ChainSpecGroup 宏和提供的 Forks 结构将此类参数放入您的链规范中。这将允许从特定块号开始覆盖单个参数。

use tc_chain_spec::{Forks, ChainSpecGroup, ChainSpecExtension, GenericChainSpec};

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecGroup)]
pub struct ClientParams {
		max_block_size: usize,
		max_extrinsic_size: usize,
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecGroup)]
pub struct PoolParams {
		max_transaction_size: usize,
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecGroup, ChainSpecExtension)]
pub struct Extension {
		pub client: ClientParams,
		pub pool: PoolParams,
}

pub type BlockNumber = u64;

/// A chain spec supporting forkable `ClientParams`.
pub type MyChainSpec1<G> = GenericChainSpec<G, Forks<BlockNumber, ClientParams>>;

/// A chain spec supporting forkable `Extension`.
pub type MyChainSpec2<G> = GenericChainSpec<G, Forks<BlockNumber, Extension>>;

还可以有一组可以随块号更改的参数(即可分叉),以及另一组不受更改的参数。这也可以通过声明一个包含 Forks 的扩展来实现。

use serde::{Serialize, Deserialize};
use tc_chain_spec::{Forks, GenericChainSpec, ChainSpecGroup, ChainSpecExtension};

#[derive(Clone, Debug, Serialize, Deserialize, ChainSpecGroup)]
pub struct ClientParams {
		max_block_size: usize,
		max_extrinsic_size: usize,
}

#[derive(Clone, Debug, Serialize, Deserialize, ChainSpecGroup)]
pub struct PoolParams {
		max_transaction_size: usize,
}

#[derive(Clone, Debug, Serialize, Deserialize, ChainSpecExtension)]
pub struct Extension {
		pub client: ClientParams,
		#[forks]
		pub pool: Forks<u64, PoolParams>,
}

pub type MyChainSpec<G> = GenericChainSpec<G, Extension>;

许可协议:GPL-3.0-or-later WITH Classpath-exception-2.0

依赖项

~34–50MB
~879K SLoC