Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow performing migration for others #1588

Merged
merged 7 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() },
AurevoirXavier marked this conversation as resolved.
Show resolved Hide resolved
)?;
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()
}
Loading