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

Rococo Identity Migration Part 2 + Bug Fix #2946

Merged
merged 7 commits into from
Jan 18, 2024
Merged
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
Prev Previous commit
Next Next commit
tidy
  • Loading branch information
joepetrowski committed Jan 17, 2024
commit 7eddcf338131829f148e2320511e7064f002041f
48 changes: 19 additions & 29 deletions substrate/frame/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,35 +1377,25 @@ impl<T: Config> Pallet<T> {
target: &T::AccountId,
) -> Result<(BalanceOf<T>, BalanceOf<T>), DispatchError> {
// Identity Deposit
let has_identity = IdentityOf::<T>::contains_key(&target);
// This should really always be true, but don't insert random storage on the off chance it's
// not.
let new_id_deposit = if has_identity {
IdentityOf::<T>::try_mutate(
&target,
|identity_of| -> Result<BalanceOf<T>, DispatchError> {
let (reg, _) = identity_of.as_mut().ok_or(Error::<T>::NoIdentity)?;
// Calculate what deposit should be
let encoded_byte_size = reg.info.encoded_size() as u32;
let byte_deposit = T::ByteDeposit::get()
.saturating_mul(<BalanceOf<T>>::from(encoded_byte_size));
let new_id_deposit = T::BasicDeposit::get().saturating_add(byte_deposit);

// Update account
Self::rejig_deposit(&target, reg.deposit, new_id_deposit)?;

reg.deposit = new_id_deposit;
Ok(new_id_deposit)
},
)?
} else {
// If the item doesn't exist, there is no "old" deposit, and the new one is zero, so no
// need to call rejig, it'd just be zero -> zero.
Zero::zero()
};

let has_subs = SubsOf::<T>::contains_key(&target);
let new_subs_deposit = if has_subs {
let new_id_deposit = IdentityOf::<T>::try_mutate(
&target,
|identity_of| -> Result<BalanceOf<T>, DispatchError> {
let (reg, _) = identity_of.as_mut().ok_or(Error::<T>::NoIdentity)?;
// Calculate what deposit should be
let encoded_byte_size = reg.info.encoded_size() as u32;
let byte_deposit =
T::ByteDeposit::get().saturating_mul(<BalanceOf<T>>::from(encoded_byte_size));
let new_id_deposit = T::BasicDeposit::get().saturating_add(byte_deposit);

// Update account
Self::rejig_deposit(&target, reg.deposit, new_id_deposit)?;

reg.deposit = new_id_deposit;
Ok(new_id_deposit)
},
)?;

let new_subs_deposit = if SubsOf::<T>::contains_key(&target) {
SubsOf::<T>::try_mutate(
&target,
|(current_subs_deposit, subs_of)| -> Result<BalanceOf<T>, DispatchError> {
Expand Down