Skip to content

Commit

Permalink
ubi
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Mar 27, 2023
1 parent 9968f64 commit 749e972
Show file tree
Hide file tree
Showing 16 changed files with 3,233 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"pallets/posts",
"pallets/reaction",
"pallets/support",
"pallets/ubi",
"runtime",
]
[profile.release]
Expand Down
1 change: 1 addition & 0 deletions pallets/profile-validation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ schelling-game-shared-link = {default-features = false, path = "../../traits/sch
sortition-sum-game = {default-features = false, path="../sortition-sum-game"}
sp-io = {default-features = false, version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18"}
sp-runtime = {default-features = false, version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18"}
profile-validation-link = {default-features=false, path="../../traits/profile-validation-link"}

[dev-dependencies]
frame-support-test = {default-features = false, version = "3.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18"}
Expand Down
23 changes: 23 additions & 0 deletions pallets/profile-validation/src/extras.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
use crate::*;

use profile_validation_link::ProfileValidationLink;

impl<T: Config> ProfileValidationLink for Pallet<T> {
type AccountId = AccountIdOf<T>;

fn account_is_validated_link(address: Self::AccountId) -> DispatchResult {
Self::get_approved_citizen(address)
}
}

impl<T: Config> Pallet<T> {

pub(super) fn get_approved_citizen(address: T::AccountId) -> DispatchResult {

let members = ApprovedCitizenAddress::<T>::get();

match members.binary_search(&address) {
Ok(_index) => {
Ok(())
}
Err(_) => Err(Error::<T>::CitizenNotApproved.into()),
}

}
pub(super) fn get_citizen_accountid(citizenid: u128) -> Result<T::AccountId, DispatchError> {
let profile = Self::citizen_profile(citizenid).ok_or(Error::<T>::CitizenDoNotExists)?;
Ok(profile.accountid)
Expand Down
1 change: 1 addition & 0 deletions pallets/profile-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pub mod pallet {
ChallengerFundInfoExists,
NotProfileUser,
NotEvidencePeriod,
CitizenNotApproved,
}

// Dispatchable functions allows users to interact with the pallet and invoke state changes.
Expand Down
15 changes: 15 additions & 0 deletions pallets/profile-validation/src/permissions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::*;

impl<T: Config> Pallet<T> {
pub(super) fn permission_user_is_citizen(account_id: T::AccountId) -> DispatchResult {
let approved_citizens = <ApprovedCitizenAddress<T>>::get();

match approved_citizens.binary_search(&account_id) {
Ok(_index) => {
Ok(())
}
Err(_) => Err(Error::<T>::CitizenDoNotExists.into()),
}

}
}
21 changes: 21 additions & 0 deletions pallets/profile-validation/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,28 @@ fn it_works_for_default_value() {
accountid: 1,
};
assert_eq!(TemplateModule::citizen_profile(0), Some(citizen_profile));
});
}

#[test]
fn check_update_profile_works(){
new_test_ext().execute_with(|| {
assert_ok!(TemplateModule::add_citizen(Origin::signed(1), "hashcode".as_bytes().to_vec()));
assert_eq!(TemplateModule::citizen_count(), 1);
let citizen_profile = CitizenDetails {
profile_hash: "hashcode".as_bytes().to_vec(),
citizenid: 0,
accountid: 1,
};
assert_eq!(TemplateModule::citizen_profile(0), Some(citizen_profile));
assert_ok!(TemplateModule::update_profile(Origin::signed(1), 0, "hashcode2".as_bytes().to_vec()));
let citizen_profile = CitizenDetails {
profile_hash: "hashcode2".as_bytes().to_vec(),
citizenid: 0,
accountid: 1,
};
assert_eq!(TemplateModule::citizen_profile(0), Some(citizen_profile));


});
}
Expand Down
Loading

0 comments on commit 749e972

Please sign in to comment.