Skip to content

Commit

Permalink
shared-storage link
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Nov 28, 2024
1 parent fb3b6d9 commit 0377f28
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

11 changes: 6 additions & 5 deletions custom-pallets/profile-validation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ scale-info = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-std = { workspace = true}
sp-std = { workspace = true }
pallet-timestamp = { workspace = true }
pallet-balances = { workspace = true }
pallet-balances = { workspace = true }
pallet-support = { workspace = true }
pallet-schelling-game-shared = { workspace = true }
pallet-sortition-sum-game = { workspace = true}
trait-schelling-game-shared= { workspace = true }

pallet-sortition-sum-game = { workspace = true }
trait-schelling-game-shared = { workspace = true }
pallet-shared-storage = { workspace = true }
trait-shared-storage = { workspace = true }


[dev-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions custom-pallets/profile-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use pallet_schelling_game_shared::types::{
use pallet_sortition_sum_game::types::SumTreeName;
use pallet_support::{new_who_and_when, Content, WhoAndWhenOf};
use trait_schelling_game_shared::SchellingGameSharedLink;
use trait_shared_storage::SharedStorageLink;
pub use types::{CitizenDetailsPost, FIRST_CHALLENGE_POST_ID, FIRST_CITIZEN_ID};
type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
type BalanceOf<T> = <<T as Config>::Currency as Currency<AccountIdOf<T>>>::Balance;
Expand Down Expand Up @@ -92,6 +93,8 @@ pub mod pallet {
PhaseData = PhaseData<Self>,
>;

type SharedStorageSource: SharedStorageLink<AccountId = AccountIdOf<Self>>;

type Currency: ReservableCurrency<Self::AccountId>;
/// Handler for the unbalanced increment when rewarding (minting rewards)
type Reward: OnUnbalanced<PositiveImbalanceOf<Self>>;
Expand Down
15 changes: 15 additions & 0 deletions custom-pallets/shared-storage/src/extras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use trait_shared_storage::SharedStorageLink;
impl<T: Config> SharedStorageLink for Pallet<T> {
type AccountId = AccountIdOf<T>;

fn add_approved_citizen_address(new_member: Self::AccountId) -> DispatchResult {
Self::add_approved_citizen_address(new_member)
}
fn check_citizen_is_approved_link(address: Self::AccountId) -> DispatchResult {
Self::check_citizen_is_approved(address)
}
Expand Down Expand Up @@ -41,6 +44,18 @@ impl<T: Config> SharedStorageLink for Pallet<T> {
}

impl<T: Config> Pallet<T> {
pub(super) fn add_approved_citizen_address(new_member: T::AccountId) -> DispatchResult {
let mut members = ApprovedCitizenAddress::<T>::get();

match members.binary_search(&new_member) {
Ok(_) => Err(Error::<T>::AlreadyMember.into()),
Err(index) => {
members.insert(index, new_member.clone());
ApprovedCitizenAddress::<T>::put(members);
Ok(())
},
}
}
pub(super) fn check_citizen_is_approved(address: T::AccountId) -> DispatchResult {
let members = ApprovedCitizenAddress::<T>::get();

Expand Down
7 changes: 7 additions & 0 deletions custom-pallets/shared-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use types::ReputationScore;

type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
type Score = i64;
type DepartmentId = u64;

#[frame_support::pallet]
pub mod pallet {
Expand All @@ -41,6 +42,11 @@ pub mod pallet {
#[pallet::getter(fn approved_citizen_address)]
pub type ApprovedCitizenAddress<T: Config> = StorageValue<_, Vec<T::AccountId>, ValueQuery>; // Its set, add element through binary_search

#[pallet::storage]
#[pallet::getter(fn approved_citizen_address_by_department)]
pub type ApprovedCitizenAddressByDepartment<T: Config> =
StorageMap<_, Blake2_128Concat, DepartmentId, Vec<T::AccountId>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn positive_externality_score)]
pub type PositiveExternalityScore<T: Config> =
Expand Down Expand Up @@ -89,5 +95,6 @@ pub mod pallet {
/// Errors should have helpful documentation associated with them.
StorageOverflow,
CitizenNotApproved,
AlreadyMember,
}
}
1 change: 1 addition & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ impl pallet_profile_validation::Config for Runtime {
type WeightInfo = pallet_profile_validation::weights::SubstrateWeight<Runtime>;
type Currency = Balances;
type SchellingGameSharedSource = SchellingGameShared;
type SharedStorageSource = SharedStorage;
type Slash = ();
type Reward = ();
}
Expand Down
2 changes: 2 additions & 0 deletions traits/trait-shared-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use sp_std::vec::Vec;
pub trait SharedStorageLink {
type AccountId;

fn add_approved_citizen_address(new_member: Self::AccountId) -> DispatchResult;

fn check_citizen_is_approved_link(address: Self::AccountId) -> DispatchResult;

fn get_approved_citizen_count_link() -> u64;
Expand Down

0 comments on commit 0377f28

Please sign in to comment.