-
Notifications
You must be signed in to change notification settings - Fork 172
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
Ban direct indexing #369
Ban direct indexing #369
Changes from all commits
447e0a3
f6018b3
261b980
4c7c0a5
82aef26
2ecdb76
2d340e7
9032f95
16bbbdb
fdc4732
d509dd8
f61f92e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,17 +12,20 @@ pub use pallet::*; | |
pub use types::*; | ||
pub use weights::WeightInfo; | ||
|
||
use frame_support::traits::Currency; | ||
use frame_support::traits::tokens::{ | ||
fungible::{self, MutateHold as _}, | ||
Precision, | ||
}; | ||
use sp_runtime::traits::Zero; | ||
use sp_std::boxed::Box; | ||
|
||
type BalanceOf<T> = | ||
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance; | ||
<<T as Config>::Currency as fungible::Inspect<<T as frame_system::Config>::AccountId>>::Balance; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use super::*; | ||
use frame_support::{pallet_prelude::*, traits::ReservableCurrency}; | ||
use frame_support::{pallet_prelude::*, traits::tokens::fungible}; | ||
use frame_system::pallet_prelude::*; | ||
|
||
#[pallet::pallet] | ||
|
@@ -36,7 +39,8 @@ pub mod pallet { | |
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
|
||
// Currency type that will be used to place deposits on neurons | ||
type Currency: ReservableCurrency<Self::AccountId> + Send + Sync; | ||
type Currency: fungible::Mutate<Self::AccountId> | ||
+ fungible::MutateHold<Self::AccountId, Reason = Self::RuntimeHoldReason>; | ||
|
||
// Weight information for extrinsics in this pallet. | ||
type WeightInfo: WeightInfo; | ||
|
@@ -56,6 +60,9 @@ pub mod pallet { | |
/// The amount held on deposit per additional field for a registered identity. | ||
#[pallet::constant] | ||
type FieldDeposit: Get<BalanceOf<Self>>; | ||
|
||
/// Reasons for putting funds on hold. | ||
type RuntimeHoldReason: From<HoldReason>; | ||
} | ||
|
||
#[pallet::event] | ||
|
@@ -75,6 +82,11 @@ pub mod pallet { | |
NotRegistered, | ||
} | ||
|
||
#[pallet::composite_enum] | ||
pub enum HoldReason { | ||
RegistryIdentity, | ||
} | ||
|
||
/// Identity data by account | ||
#[pallet::storage] | ||
#[pallet::getter(fn identity_of)] | ||
|
@@ -125,11 +137,21 @@ pub mod pallet { | |
let old_deposit = id.deposit; | ||
id.deposit = T::InitialDeposit::get() + fd; | ||
if id.deposit > old_deposit { | ||
T::Currency::reserve(&who, id.deposit - old_deposit)?; | ||
T::Currency::hold( | ||
&HoldReason::RegistryIdentity.into(), | ||
&who, | ||
id.deposit - old_deposit, | ||
)?; | ||
Comment on lines
-128
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to do the currency -> fungible migration here? Seems unrelated to direct indexing and I think you need a migration? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should have gone into the 1.0 branch, but I forgot to commit it and now i'm rolling into this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gregzaitsev is this what you were referring to a while back ? I remember we had some conversation about it. #353 |
||
} | ||
if old_deposit > id.deposit { | ||
let err_amount = T::Currency::unreserve(&who, old_deposit - id.deposit); | ||
debug_assert!(err_amount.is_zero()); | ||
let release_res = T::Currency::release( | ||
&HoldReason::RegistryIdentity.into(), | ||
&who, | ||
old_deposit - id.deposit, | ||
Precision::BestEffort, | ||
); | ||
debug_assert!(release_res | ||
.is_ok_and(|released_amount| released_amount == (old_deposit - id.deposit))); | ||
} | ||
|
||
<IdentityOf<T>>::insert(&identified, id); | ||
|
@@ -153,8 +175,13 @@ pub mod pallet { | |
let id = <IdentityOf<T>>::take(&identified).ok_or(Error::<T>::NotRegistered)?; | ||
let deposit = id.total_deposit(); | ||
|
||
let err_amount = T::Currency::unreserve(&who, deposit); | ||
debug_assert!(err_amount.is_zero()); | ||
let release_res = T::Currency::release( | ||
&HoldReason::RegistryIdentity.into(), | ||
&who, | ||
deposit, | ||
Precision::BestEffort, | ||
); | ||
debug_assert!(release_res.is_ok_and(|released_amount| released_amount == deposit)); | ||
|
||
Self::deposit_event(Event::IdentityDissolved { who: identified }); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, nice to allow this in tests, benchmarks, and some node stuff like this