Skip to content

Commit

Permalink
Allow performing migration for others
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Sep 2, 2024
1 parent bdcfc09 commit fc45797
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 34 deletions.
7 changes: 4 additions & 3 deletions pallet/deposit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(<T as Config>::WeightInfo::migrate())]
pub fn migrate(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
pub fn migrate(origin: OriginFor<T>, who: T::AccountId) -> DispatchResult {
ensure_signed(origin)?;

let Some(ds) = <Deposits<T>>::take(&who) else { return Ok(()) };
let now = Self::now();
let mut ds = ds.into_iter();
Expand Down
6 changes: 3 additions & 3 deletions precompile/deposit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ where
Ok(true)
}

#[precompile::public("migrate()")]
fn migrate(handle: &mut impl PrecompileHandle) -> EvmResult<bool> {
#[precompile::public("migrate(address)")]
fn migrate(handle: &mut impl PrecompileHandle, who: Address) -> EvmResult<bool> {
let origin: AccountIdOf<Runtime> = handle.context().caller.into();
RuntimeHelper::<Runtime>::try_dispatch(
handle,
Some(origin).into(),
darwinia_deposit::Call::<Runtime>::migrate {},
darwinia_deposit::Call::<Runtime>::migrate { who: who.into() },
)?;
Ok(true)
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/crab/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ = <pallet_assets::Pallet<Runtime>>::transfer_ownership(
RuntimeOrigin::signed(ROOT),
Expand All @@ -65,7 +65,7 @@ fn migrate() -> frame_support::weights::Weight {
);

if let Ok(deposit) = array_bytes::hex_n_into::<_, AccountId, 20>(
"0x08837De0Ae21C270383D9F2de4DB03c7b1314632",
"0x7FAcDaFB282028E4B3264fB08cd633A9142514df",
) {
let _ = <pallet_assets::Pallet<Runtime>>::set_team(
RuntimeOrigin::signed(dao),
Expand Down
4 changes: 2 additions & 2 deletions runtime/darwinia/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ = <pallet_assets::Pallet<Runtime>>::transfer_ownership(
RuntimeOrigin::signed(ROOT),
Expand All @@ -73,7 +73,7 @@ fn migrate() -> frame_support::weights::Weight {
);

if let Ok(deposit) = array_bytes::hex_n_into::<_, AccountId, 20>(
"0x08837De0Ae21C270383D9F2de4DB03c7b1314632",
"0x7FAcDaFB282028E4B3264fB08cd633A9142514df",
) {
let _ = <pallet_assets::Pallet<Runtime>>::set_team(
RuntimeOrigin::signed(dao),
Expand Down
25 changes: 1 addition & 24 deletions runtime/koi/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ = <pallet_assets::Pallet<Runtime>>::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 _ = <pallet_assets::Pallet<Runtime>>::set_team(
RuntimeOrigin::signed(dao),
codec::Compact(AssetIds::KKton as AssetId),
deposit,
deposit,
dao,
);
}
}

// frame_support::weights::Weight::zero()
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(5, 5)
frame_support::weights::Weight::zero()
}

0 comments on commit fc45797

Please sign in to comment.