|
| 1 | +// KILT Blockchain – https://botlabs.org |
| 2 | +// Copyright (C) 2019-2024 BOTLabs GmbH |
| 3 | + |
| 4 | +// The KILT Blockchain is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | + |
| 9 | +// The KILT Blockchain is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | + |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +// If you feel like getting in touch with us, you can do so at [email protected] |
| 18 | + |
| 19 | +use frame_support::traits::{Hooks, OffchainWorker, OnFinalize, OnIdle, OnInitialize, OnRuntimeUpgrade, TryState}; |
| 20 | +use runtime_common::BlockNumber; |
| 21 | + |
| 22 | +use crate::{AllPalletsWithSystem, Runtime}; |
| 23 | + |
| 24 | +pub struct AllPalletsWithSystemAndRuntimeHooks; |
| 25 | + |
| 26 | +impl OnRuntimeUpgrade for AllPalletsWithSystemAndRuntimeHooks { |
| 27 | + fn on_runtime_upgrade() -> xcm::prelude::Weight { |
| 28 | + AllPalletsWithSystem::on_runtime_upgrade() |
| 29 | + } |
| 30 | + |
| 31 | + #[cfg(feature = "try-runtime")] |
| 32 | + fn try_on_runtime_upgrade(checks: bool) -> Result<sp_weights::Weight, sp_runtime::TryRuntimeError> { |
| 33 | + AllPalletsWithSystem::try_on_runtime_upgrade(checks) |
| 34 | + } |
| 35 | + |
| 36 | + #[cfg(feature = "try-runtime")] |
| 37 | + fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::TryRuntimeError> { |
| 38 | + AllPalletsWithSystem::pre_upgrade() |
| 39 | + } |
| 40 | + |
| 41 | + #[cfg(feature = "try-runtime")] |
| 42 | + fn post_upgrade(state: sp_std::vec::Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> { |
| 43 | + AllPalletsWithSystem::post_upgrade(state) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +impl OnInitialize<BlockNumber> for AllPalletsWithSystemAndRuntimeHooks { |
| 48 | + fn on_initialize(n: BlockNumber) -> xcm::prelude::Weight { |
| 49 | + AllPalletsWithSystem::on_initialize(n) |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +impl OnIdle<BlockNumber> for AllPalletsWithSystemAndRuntimeHooks { |
| 54 | + fn on_idle(n: BlockNumber, remaining_weight: xcm::prelude::Weight) -> xcm::prelude::Weight { |
| 55 | + AllPalletsWithSystem::on_idle(n, remaining_weight) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +impl OnFinalize<BlockNumber> for AllPalletsWithSystemAndRuntimeHooks { |
| 60 | + fn on_finalize(n: BlockNumber) { |
| 61 | + AllPalletsWithSystem::on_finalize(n) |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +impl OffchainWorker<BlockNumber> for AllPalletsWithSystemAndRuntimeHooks { |
| 66 | + fn offchain_worker(n: BlockNumber) { |
| 67 | + AllPalletsWithSystem::offchain_worker(n) |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +impl TryState<BlockNumber> for AllPalletsWithSystemAndRuntimeHooks { |
| 72 | + fn try_state(n: BlockNumber, s: frame_try_runtime::TryStateSelect) -> Result<(), sp_runtime::TryRuntimeError> { |
| 73 | + log::trace!(target: "try_runtime::peregrine", "AAAAA"); |
| 74 | + AllPalletsWithSystem::try_state(n, s)?; |
| 75 | + log::trace!(target: "try_runtime::peregrine", "BBBBB"); |
| 76 | + <Runtime as Hooks<BlockNumber>>::try_state(n) |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +impl Hooks<BlockNumber> for Runtime { |
| 81 | + #[cfg(feature = "try-runtime")] |
| 82 | + fn try_state(n: BlockNumber) -> Result<(), sp_runtime::TryRuntimeError> { |
| 83 | + log::trace!( |
| 84 | + target: "try_runtime::peregrine", |
| 85 | + "Trying state for Peregrine runtime at block {n}" |
| 86 | + ); |
| 87 | + Ok(()) |
| 88 | + } |
| 89 | +} |
0 commit comments