Skip to content

Commit

Permalink
Merge pull request #95 from renlabs-dev/main
Browse files Browse the repository at this point in the history
fix: curator application consistency
  • Loading branch information
functor-flow authored Oct 17, 2024
2 parents eb4e572 + ef959bd commit b1ad491
Showing 3 changed files with 13 additions and 105 deletions.
33 changes: 13 additions & 20 deletions pallets/governance/src/dao.rs
Original file line number Diff line number Diff line change
@@ -36,46 +36,37 @@ impl<T: Config> Pallet<T> {

#[must_use]
fn can_add_application_status_based(key: &T::AccountId) -> bool {
// check if there's an application with the given key
CuratorApplications::<T>::iter().find(|(_, app)| app.user_id == *key).map_or(
true,
|(_, app)| {
// if the application exists, check its status
!matches!(
app.status,
ApplicationStatus::Pending | ApplicationStatus::Accepted
)
},
)
!CuratorApplications::<T>::iter().any(|(_, app)| app.user_id == *key)
}

pub fn add_application(
key: T::AccountId,
application_key: T::AccountId,
data: Vec<u8>,
) -> DispatchResult {
// make sure application isnt already whitelisted
ensure!(
!Self::is_in_legit_whitelist(&application_key),
Error::<T>::AlreadyWhitelisted
);

// make sure application does not already exist
ensure!(
Self::can_add_application_status_based(&application_key),
Error::<T>::ApplicationKeyAlreadyUsed
);

// check if the key has enough funds to file the application
let application_cost = GeneralSubnetApplicationCost::<T>::get();
ensure!(
PalletSubspace::<T>::has_enough_balance(&key, application_cost),
Error::<T>::NotEnoughBalanceToApply
);

// 1. a remove the balance from the account
let Some(removed_balance_as_currency) =
PalletSubspace::<T>::u64_to_balance(application_cost)
else {
return Err(Error::<T>::InvalidCurrencyConversionValue.into());
};

// add the application
let application_id = Self::get_next_application_id();
let current_block = PalletSubspace::<T>::get_current_block_number();

@@ -89,6 +80,7 @@ impl<T: Config> Pallet<T> {
block_number: current_block,
};

// 1. b remove the balance from the account
PalletSubspace::<T>::remove_balance_from_account(&key, removed_balance_as_currency)?;

CuratorApplications::<T>::insert(application_id, application);
@@ -163,6 +155,12 @@ impl<T: Config> Pallet<T> {
let key = ensure_signed(origin)?;
ensure!(Curator::<T>::get() == key, Error::<T>::NotCurator);

// make sure application isnt already whitelisted
ensure!(
!Self::is_in_legit_whitelist(&module_key),
Error::<T>::AlreadyWhitelisted
);

let application = CuratorApplications::<T>::iter_values()
.find(|app| app.user_id == module_key)
.ok_or(Error::<T>::ApplicationNotFound)?;
@@ -172,11 +170,6 @@ impl<T: Config> Pallet<T> {
Error::<T>::ApplicationNotPending
);

ensure!(
!Self::is_in_legit_whitelist(&module_key),
Error::<T>::AlreadyWhitelisted
);

LegitWhitelist::<T>::insert(&module_key, ());

T::execute_application(&module_key)?;
6 changes: 0 additions & 6 deletions pallets/subnet_emission/src/lib.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ use sp_std::collections::btree_map::BTreeMap;

pub mod distribute_emission;
pub mod migrations;
pub mod post_runtime;
pub mod subnet_pricing {
pub mod demo;
pub mod root;
@@ -109,11 +108,6 @@ pub mod pallet {
}
Weight::zero()
}

fn on_idle(_n: BlockNumberFor<T>, remaining: Weight) -> Weight {
log::info!("on_idle: {remaining:?}");
Self::deregister_excess_modules(remaining)
}
}

#[pallet::event]
79 changes: 0 additions & 79 deletions pallets/subnet_emission/src/post_runtime.rs

This file was deleted.

0 comments on commit b1ad491

Please sign in to comment.