Skip to content

Commit 8903dc5

Browse files
authored
add may be subscribe pools & fix wrap clean account_status issue (#1245)
* add may be subscribe pools * fix account_status cleaned issue * cargo fmt * cargo fmt
1 parent 7c019bb commit 8903dc5

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

pallets/phala/src/compute/vault.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ pub mod pallet {
266266
pool_info.basepool.pid,
267267
)?;
268268
pool_info.owner_shares -= shares;
269+
wrapped_balances::Pallet::<T>::maybe_subscribe_to_pool(
270+
&who,
271+
vault_pid,
272+
pool_info.basepool.cid,
273+
)?;
269274
base_pool::pallet::Pools::<T>::insert(vault_pid, PoolProxy::Vault(pool_info));
270275
Self::deposit_event(Event::<T>::OwnerSharesClaimed {
271276
pid: vault_pid,

pallets/phala/src/compute/wrapped_balances.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,15 @@ pub mod pallet {
198198
KeepAlive,
199199
)?;
200200
Self::mint_into(&user, amount)?;
201-
StakerAccounts::<T>::insert(
202-
&user,
203-
FinanceAccount::<BalanceOf<T>> {
204-
invest_pools: vec![],
205-
locked: Zero::zero(),
206-
},
207-
);
201+
if !StakerAccounts::<T>::contains_key(&user) {
202+
StakerAccounts::<T>::insert(
203+
&user,
204+
FinanceAccount::<BalanceOf<T>> {
205+
invest_pools: vec![],
206+
locked: Zero::zero(),
207+
},
208+
);
209+
}
208210
Self::deposit_event(Event::<T>::Wrapped { user, amount });
209211
Ok(())
210212
}
@@ -340,8 +342,26 @@ pub mod pallet {
340342

341343
Ok(())
342344
}
343-
}
344345

346+
#[pallet::call_index(5)]
347+
#[pallet::weight(0)]
348+
#[frame_support::transactional]
349+
pub fn backfill_vote_lock(origin: OriginFor<T>) -> DispatchResult {
350+
let who = ensure_signed(origin)?;
351+
base_pool::Pallet::<T>::ensure_migration_root(who)?;
352+
let mut iter = VoteAccountMap::<T>::iter();
353+
for (_, account_id, (aye_amount, nay_amount)) in iter.by_ref() {
354+
let mut account_status = StakerAccounts::<T>::get(&account_id)
355+
.expect("account_status should be found when it already voted; qed.");
356+
let total_amount = aye_amount + nay_amount;
357+
if account_status.locked < total_amount {
358+
account_status.locked = total_amount;
359+
StakerAccounts::<T>::insert(account_id, account_status);
360+
}
361+
}
362+
Ok(())
363+
}
364+
}
345365
impl<T: Config> Pallet<T>
346366
where
347367
BalanceOf<T>: sp_runtime::traits::AtLeast32BitUnsigned + Copy + FixedPointConvert + Display,

0 commit comments

Comments
 (0)