Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Oct 30, 2024
1 parent f34d4bf commit 3ccf6c5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 39 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions pallet/account-migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ scale-info = { workspace = true }

# darwinia
darwinia-deposit = { workspace = true }
darwinia-staking = { workspace = true }
dc-primitives = { workspace = true }

# polkadot-sdk
Expand Down Expand Up @@ -43,7 +42,6 @@ std = [

# darwinia
"darwinia-deposit/std",
"darwinia-staking/std",
"dc-primitives/std",

# polkadot-sdk
Expand All @@ -62,7 +60,6 @@ std = [
runtime-benchmarks = [
# darwinia
"darwinia-deposit/runtime-benchmarks",
"darwinia-staking/runtime-benchmarks",

# polkadot-sdk
"frame-benchmarking/runtime-benchmarks",
Expand All @@ -76,7 +73,6 @@ runtime-benchmarks = [
try-runtime = [
# darwinia
"darwinia-deposit/try-runtime",
"darwinia-staking/try-runtime",

# polkadot-sdk
"frame-support/try-runtime",
Expand Down
43 changes: 22 additions & 21 deletions pallet/account-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! These two algorithm are not compatible.
//! Thus, an account migration is required.
//!
//! ## Technical detail
//! ## Technical Detail
//!
//! Users must send an extrinsic themselves to migrate their account(s).
//! This extrinsic should be unsigned, the reason is the same as `pallet-claims`.
Expand Down Expand Up @@ -56,7 +56,6 @@ pub use weights::WeightInfo;

// darwinia
use darwinia_deposit::{Deposit, DepositId};
use darwinia_staking::Ledger;
use dc_primitives::{AccountId as AccountId20, AssetId, Balance, BlockNumber, Nonce};
// polkadot-sdk
use frame_support::{
Expand Down Expand Up @@ -95,9 +94,6 @@ pub mod pallet {
/// The account is not a member of the multisig.
pub(crate) const E_NOT_MULTISIG_MEMBER: u8 = 4;

#[pallet::pallet]
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config:
frame_system::Config<
Expand All @@ -108,12 +104,11 @@ pub mod pallet {
> + pallet_assets::Config<Balance = Balance, AssetId = AssetId>
+ pallet_balances::Config<Balance = Balance>
+ darwinia_deposit::Config
+ darwinia_staking::Config
{
/// Override the [`frame_system::Config::RuntimeEvent`].
type RuntimeEvent: From<Event> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

/// Weight information for extrinsics in this pallet.
/// Weight information for extrinsic in this pallet.
type WeightInfo: WeightInfo;
}

Expand Down Expand Up @@ -158,7 +153,7 @@ pub mod pallet {
#[pallet::getter(fn deposit_of)]
pub type Deposits<T: Config> = StorageMap<_, Blake2_128Concat, AccountId32, Vec<Deposit>>;

/// [`darwinia_staking::migration::v2::OldLedger`] data.
/// Old ledger data.
#[pallet::storage]
#[pallet::getter(fn ledger_of)]
pub type Ledgers<T: Config> = StorageMap<_, Blake2_128Concat, AccountId32, OldLedger>;
Expand All @@ -169,6 +164,14 @@ pub mod pallet {
#[pallet::getter(fn multisig_of)]
pub type Multisigs<T: Config> = StorageMap<_, Identity, AccountId32, MultisigMigrationDetail>;

#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::hooks]
impl <T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_idle(_: BlockNumberFor<T>, mut remaining_weight: Weight) -> Weight {
remaining_weight
}
}
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Migrate all the account data under the `from` to `to`.
Expand Down Expand Up @@ -417,19 +420,17 @@ pub mod pallet {
asset_details,
);
}
if let Some(l) = <Ledgers<T>>::take(from) {
if let Some(ds) = <Deposits<T>>::take(from) {
<pallet_balances::Pallet<T> as Currency<_>>::transfer(
to,
&darwinia_deposit::account_id(),
ds.iter().map(|d| d.value).sum(),
AllowDeath,
)?;
<darwinia_deposit::Deposits<T>>::insert(
to,
BoundedVec::try_from(ds).map_err(|_| <Error<T>>::ExceedMaxDeposits)?,
);
}
if let Some(ds) = <Deposits<T>>::take(from) {
<pallet_balances::Pallet<T> as Currency<_>>::transfer(
to,
&darwinia_deposit::account_id(),
ds.iter().map(|d| d.value).sum(),
AllowDeath,
)?;
<darwinia_deposit::Deposits<T>>::insert(
to,
BoundedVec::try_from(ds).map_err(|_| <Error<T>>::ExceedMaxDeposits)?,
);
}
}

Expand Down
12 changes: 0 additions & 12 deletions pallet/account-migration/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,6 @@ impl darwinia_deposit::Config for Runtime {
type WeightInfo = ();
}

impl darwinia_staking::Config for Runtime {
type Currency = Balances;
type IssuingManager = ();
type KtonStaking = ();
type RingStaking = ();
type RuntimeEvent = RuntimeEvent;
type Treasury = ();
type UnixTime = Timestamp;
type WeightInfo = ();
}

impl crate::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
Expand All @@ -129,7 +118,6 @@ frame_support::construct_runtime! {
Balances: pallet_balances,
Assets: pallet_assets,
Deposit: darwinia_deposit,
Staking: darwinia_staking,
AccountMigration: crate,
}
}
Expand Down
2 changes: 1 addition & 1 deletion pallet/account-migration/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn migrate_multisig_should_work() {
signature: signature.0,
new_multisig_params: None
}),
TransactionValidityError::Invalid(InvalidTransaction::Custom(E_DUPLICATIVE_SUBMISSION))
TransactionValidityError::Invalid(InvalidTransaction::Custom(E_DUPLICATED_SUBMISSION))
);

assert!(<Multisigs<Runtime>>::get(&multisig).is_some());
Expand Down

0 comments on commit 3ccf6c5

Please sign in to comment.