1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#![cfg_attr(not(feature = "std"), no_std)]
use codec::{Decode, Encode};
use frame_support::{decl_module, decl_storage};
use sp_runtime::RuntimeDebug;
use sp_std::prelude::Vec;
use frame_system::{self as system};
use pallet_utils::WhoAndWhen;
use pallet_profiles::{Profile, ProfileUpdate, AfterProfileUpdated};
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug)]
pub struct ProfileHistoryRecord<T: Trait> {
pub edited: WhoAndWhen<T>,
pub old_data: ProfileUpdate,
}
pub trait Trait: system::Trait
+ pallet_utils::Trait
+ pallet_profiles::Trait
{}
decl_storage! {
trait Store for Module<T: Trait> as ProfileHistoryModule {
pub EditHistory get(fn edit_history):
map hasher(blake2_128_concat) T::AccountId => Vec<ProfileHistoryRecord<T>>;
}
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
}
impl<T: Trait> ProfileHistoryRecord<T> {
fn new(updated_by: T::AccountId, old_data: ProfileUpdate) -> Self {
ProfileHistoryRecord {
edited: WhoAndWhen::<T>::new(updated_by),
old_data
}
}
}
impl<T: Trait> AfterProfileUpdated<T> for Module<T> {
fn after_profile_updated(sender: T::AccountId, _profile: &Profile<T>, old_data: ProfileUpdate) {
<EditHistory<T>>::mutate(sender.clone(), |ids|
ids.push(ProfileHistoryRecord::<T>::new(sender, old_data)));
}
}