astar_primitives/
lib.rs

1// This file is part of Astar.
2
3// Copyright (C) Stake Technologies Pte.Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later
5
6// Astar is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// Astar is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with Astar. If not, see <http://www.gnu.org/licenses/>.
18
19#![cfg_attr(not(feature = "std"), no_std)]
20
21//! Core Astar types.
22//!
23//! These core Astar types are used by the Shiden, Shibuya and Astar runtimes.
24pub mod xcm;
25
26/// EVM primitives.
27pub mod evm;
28
29/// Precompiles
30pub mod precompiles;
31
32/// dApp staking & inflation primitives.
33pub mod dapp_staking;
34
35/// Useful primitives for testing.
36pub mod testing;
37
38/// Governance primitives.
39pub mod governance;
40
41/// Genesis generation helpers & primitives.
42pub mod genesis;
43
44/// Parachain related constants.
45pub mod parachain;
46
47/// Benchmark primitives
48#[cfg(feature = "runtime-benchmarks")]
49pub mod benchmarks;
50
51use frame_support::migrations::{FailedMigrationHandler, FailedMigrationHandling};
52use sp_runtime::{
53    generic,
54    traits::{BlakeTwo256, IdentifyAccount, Verify},
55};
56
57/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
58pub type Signature = sp_runtime::MultiSignature;
59/// Some way of identifying an account on the chain. We intentionally make it equivalent
60/// to the public key of our transaction signing scheme.
61pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
62/// The address format for describing accounts.
63pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
64
65/// Block header type as expected by this runtime.
66pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
67/// Balance of an account.
68pub type Balance = u128;
69/// An index to a block.
70pub type BlockNumber = u32;
71/// A hash of some data used by the chain.
72pub type Hash = sp_core::H256;
73/// Id used for identifying assets.
74///
75/// AssetId allocation:
76/// [1; 2^32-1]     Custom user assets (permissionless)
77/// [2^32; 2^64-1]  Statemine assets (simple map)
78/// [2^64; 2^128-1] Ecosystem assets
79/// 2^128-1         Relay chain token (KSM)
80pub type AssetId = u128;
81/// Block type.
82pub type Block = sp_runtime::generic::Block<Header, sp_runtime::OpaqueExtrinsic>;
83/// Index of a transaction in the chain.
84pub type Nonce = u32;
85
86/// Unfreeze chain on failed migration and continue with extrinsic execution.
87/// Migration must be tested and make sure it doesn't fail. If it happens, we don't have other
88/// choices but unfreeze chain and continue with extrinsic execution.
89pub struct UnfreezeChainOnFailedMigration;
90impl FailedMigrationHandler for UnfreezeChainOnFailedMigration {
91    fn failed(migration: Option<u32>) -> FailedMigrationHandling {
92        log::error!(target: "mbm", "Migration failed at cursor: {migration:?}");
93        FailedMigrationHandling::ForceUnstuck
94    }
95}