// SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2023 Snowfork //! Governance API for controlling the Ethereum side of the bridge use super::*; use frame_support::traits::OnRuntimeUpgrade; use log; #[cfg(feature = "try-runtime")] use sp_runtime::TryRuntimeError; pub mod v0 { use frame_support::{pallet_prelude::*, weights::Weight}; use super::*; const LOG_TARGET: &str = "ethereum_system::migration"; pub struct InitializeOnUpgrade( sp_std::marker::PhantomData<(T, BridgeHubParaId, AssetHubParaId)>, ); impl OnRuntimeUpgrade for InitializeOnUpgrade where T: Config, BridgeHubParaId: Get, AssetHubParaId: Get, { fn on_runtime_upgrade() -> Weight { if !Pallet::::is_initialized() { Pallet::::initialize( BridgeHubParaId::get().into(), AssetHubParaId::get().into(), ) .expect("infallible; qed"); log::info!( target: LOG_TARGET, "Ethereum system initialized." ); T::DbWeight::get().reads_writes(2, 5) } else { log::info!( target: LOG_TARGET, "Ethereum system already initialized. Skipping." ); T::DbWeight::get().reads(2) } } #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, TryRuntimeError> { if !Pallet::::is_initialized() { log::info!( target: LOG_TARGET, "Agents and channels not initialized. Initialization will run." ); } else { log::info!( target: LOG_TARGET, "Agents and channels are initialized. Initialization will not run." ); } Ok(vec![]) } #[cfg(feature = "try-runtime")] fn post_upgrade(_: Vec) -> Result<(), TryRuntimeError> { frame_support::ensure!( Pallet::::is_initialized(), "Agents and channels were not initialized." ); Ok(()) } } }