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/// Checked Ethereum transaction primitives.
27pub mod ethereum_checked;
28
29/// EVM primitives.
30pub mod evm;
31
32/// Precompiles
33pub mod precompiles;
34
35/// dApp staking & inflation primitives.
36pub mod dapp_staking;
37
38/// Useful primitives for testing.
39pub mod testing;
40
41/// Governance primitives.
42pub mod governance;
43
44/// Genesis generation helpers & primitives.
45pub mod genesis;
46
47/// Parachain related constants.
48pub mod parachain;
49
50/// Benchmark primitives
51#[cfg(feature = "runtime-benchmarks")]
52pub mod benchmarks;
53
54use frame_support::migrations::{FailedMigrationHandler, FailedMigrationHandling};
55use sp_runtime::{
56    generic,
57    traits::{BlakeTwo256, IdentifyAccount, Verify},
58};
59
60/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
61pub type Signature = sp_runtime::MultiSignature;
62/// Some way of identifying an account on the chain. We intentionally make it equivalent
63/// to the public key of our transaction signing scheme.
64pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
65/// The address format for describing accounts.
66pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
67
68/// Block header type as expected by this runtime.
69pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
70/// Balance of an account.
71pub type Balance = u128;
72/// An index to a block.
73pub type BlockNumber = u32;
74/// A hash of some data used by the chain.
75pub type Hash = sp_core::H256;
76/// Id used for identifying assets.
77///
78/// AssetId allocation:
79/// [1; 2^32-1]     Custom user assets (permissionless)
80/// [2^32; 2^64-1]  Statemine assets (simple map)
81/// [2^64; 2^128-1] Ecosystem assets
82/// 2^128-1         Relay chain token (KSM)
83pub type AssetId = u128;
84/// Block type.
85pub type Block = sp_runtime::generic::Block<Header, sp_runtime::OpaqueExtrinsic>;
86/// Index of a transaction in the chain.
87pub type Nonce = u32;
88
89/// Unfreeze chain on failed migration and continue with extrinsic execution.
90/// Migration must be tested and make sure it doesn't fail. If it happens, we don't have other
91/// choices but unfreeze chain and continue with extrinsic execution.
92pub struct UnfreezeChainOnFailedMigration;
93impl FailedMigrationHandler for UnfreezeChainOnFailedMigration {
94    fn failed(migration: Option<u32>) -> FailedMigrationHandling {
95        log::error!(target: "mbm", "Migration failed at cursor: {migration:?}");
96        FailedMigrationHandling::ForceUnstuck
97    }
98}