From fc457973a0e19aea13efbeb2ac54fe9628f00d79 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 2 Sep 2024 12:17:04 +0800 Subject: [PATCH] Allow performing migration for others --- pallet/deposit/src/lib.rs | 7 ++++--- precompile/deposit/src/lib.rs | 6 +++--- runtime/crab/src/migration.rs | 4 ++-- runtime/darwinia/src/migration.rs | 4 ++-- runtime/koi/src/migration.rs | 25 +------------------------ 5 files changed, 12 insertions(+), 34 deletions(-) diff --git a/pallet/deposit/src/lib.rs b/pallet/deposit/src/lib.rs index 9278475df..006542232 100644 --- a/pallet/deposit/src/lib.rs +++ b/pallet/deposit/src/lib.rs @@ -312,11 +312,12 @@ pub mod pallet { Ok(()) } - /// Migration data to deposit contract. + /// Migrate the specified account's data to deposit contract. #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::migrate())] - pub fn migrate(origin: OriginFor) -> DispatchResult { - let who = ensure_signed(origin)?; + pub fn migrate(origin: OriginFor, who: T::AccountId) -> DispatchResult { + ensure_signed(origin)?; + let Some(ds) = >::take(&who) else { return Ok(()) }; let now = Self::now(); let mut ds = ds.into_iter(); diff --git a/precompile/deposit/src/lib.rs b/precompile/deposit/src/lib.rs index 8906e0837..09135936d 100644 --- a/precompile/deposit/src/lib.rs +++ b/precompile/deposit/src/lib.rs @@ -89,13 +89,13 @@ where Ok(true) } - #[precompile::public("migrate()")] - fn migrate(handle: &mut impl PrecompileHandle) -> EvmResult { + #[precompile::public("migrate(address)")] + fn migrate(handle: &mut impl PrecompileHandle, who: Address) -> EvmResult { let origin: AccountIdOf = handle.context().caller.into(); RuntimeHelper::::try_dispatch( handle, Some(origin).into(), - darwinia_deposit::Call::::migrate {}, + darwinia_deposit::Call::::migrate { who: who.into() }, )?; Ok(true) } diff --git a/runtime/crab/src/migration.rs b/runtime/crab/src/migration.rs index 34335bb0e..1f126308e 100644 --- a/runtime/crab/src/migration.rs +++ b/runtime/crab/src/migration.rs @@ -56,7 +56,7 @@ fn migrate() -> frame_support::weights::Weight { } if let Ok(dao) = - array_bytes::hex_n_into::<_, AccountId, 20>("0x7FAcDaFB282028E4B3264fB08cd633A9142514df") + array_bytes::hex_n_into::<_, AccountId, 20>("0x08837De0Ae21C270383D9F2de4DB03c7b1314632") { let _ = >::transfer_ownership( RuntimeOrigin::signed(ROOT), @@ -65,7 +65,7 @@ fn migrate() -> frame_support::weights::Weight { ); if let Ok(deposit) = array_bytes::hex_n_into::<_, AccountId, 20>( - "0x08837De0Ae21C270383D9F2de4DB03c7b1314632", + "0x7FAcDaFB282028E4B3264fB08cd633A9142514df", ) { let _ = >::set_team( RuntimeOrigin::signed(dao), diff --git a/runtime/darwinia/src/migration.rs b/runtime/darwinia/src/migration.rs index 0bda7b7cc..853e497cb 100644 --- a/runtime/darwinia/src/migration.rs +++ b/runtime/darwinia/src/migration.rs @@ -64,7 +64,7 @@ fn migrate() -> frame_support::weights::Weight { } if let Ok(dao) = - array_bytes::hex_n_into::<_, AccountId, 20>("0x7FAcDaFB282028E4B3264fB08cd633A9142514df") + array_bytes::hex_n_into::<_, AccountId, 20>("0x08837De0Ae21C270383D9F2de4DB03c7b1314632") { let _ = >::transfer_ownership( RuntimeOrigin::signed(ROOT), @@ -73,7 +73,7 @@ fn migrate() -> frame_support::weights::Weight { ); if let Ok(deposit) = array_bytes::hex_n_into::<_, AccountId, 20>( - "0x08837De0Ae21C270383D9F2de4DB03c7b1314632", + "0x7FAcDaFB282028E4B3264fB08cd633A9142514df", ) { let _ = >::set_team( RuntimeOrigin::signed(dao), diff --git a/runtime/koi/src/migration.rs b/runtime/koi/src/migration.rs index 15e9e442f..d6045cb0e 100644 --- a/runtime/koi/src/migration.rs +++ b/runtime/koi/src/migration.rs @@ -45,28 +45,5 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - if let Ok(dao) = - array_bytes::hex_n_into::<_, AccountId, 20>("0x7FAcDaFB282028E4B3264fB08cd633A9142514df") - { - let _ = >::transfer_ownership( - RuntimeOrigin::signed(ROOT), - codec::Compact(AssetIds::KKton as AssetId), - dao, - ); - - if let Ok(deposit) = array_bytes::hex_n_into::<_, AccountId, 20>( - "0x08837De0Ae21C270383D9F2de4DB03c7b1314632", - ) { - let _ = >::set_team( - RuntimeOrigin::signed(dao), - codec::Compact(AssetIds::KKton as AssetId), - deposit, - deposit, - dao, - ); - } - } - - // frame_support::weights::Weight::zero() - ::DbWeight::get().reads_writes(5, 5) + frame_support::weights::Weight::zero() }