Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
change username func
Browse files Browse the repository at this point in the history
  • Loading branch information
stojanov-igor committed Feb 28, 2022
1 parent 0e2f499 commit 0e8f1ef
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions profile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ pub mod pallet {

/// Dispatchable call that ensures user can update existing personal profile in storage.
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
pub fn update_profile(origin: OriginFor<T>, interests: Vec<u8>) -> DispatchResult {
pub fn update_profile(origin: OriginFor<T>, username: Vec<u8>, interests: Vec<u8>) -> DispatchResult {

// Check that the extrinsic was signed and get the signer.
let account = ensure_signed(origin)?;

// Since Each account can have one profile, we call into generate profile again
let _profile_id = Self::change_profile(&account, interests)?;
let _profile_id = Self::change_profile(&account, username, interests)?;

// Emit an event.
Self::deposit_event(Event::ProfileUpdated{ who: account });
Expand Down Expand Up @@ -227,14 +227,16 @@ pub mod pallet {
}

// Changes existing profile
pub fn change_profile(owner: &T::AccountId, new_interests: Vec<u8>) -> Result<T::Hash, Error<T>> {
pub fn change_profile(owner: &T::AccountId, new_username: Vec<u8>, new_interests: Vec<u8>) -> Result<T::Hash, Error<T>> {

// Ensure that only owner can update profile
let mut profile = Self::profiles(owner).ok_or(<Error<T>>::NoUpdateAuthority)?;

// Change interests of owner
profile.change_interests(new_interests);

profile.change_username(new_username);

// Get hash of profile
let profile_id = T::Hashing::hash_of(&profile);

Expand Down Expand Up @@ -299,6 +301,10 @@ pub mod pallet {
pub fn change_interests(&mut self, new_interests: Vec<u8>) {
self.interests = new_interests;
}

pub fn change_username(&mut self, new_username: Vec<u8>) {
self.name = new_username;
}
}

}

0 comments on commit 0e8f1ef

Please sign in to comment.