Add field names to pallet Event variants (#9993)

* convert pallet-assets events to struct types

* updated events of a couple pallets

* updated pallet event field names

* update pallet event field names

* updated events in test files

* cargo fmt

* minorfixes

* fix assertion error

* minor fix

* formatting fix

* fmt
This commit is contained in:
David Salami
2021-11-16 02:56:00 +01:00
committed by GitHub
parent fb3c7326c2
commit 120894fdb7
48 changed files with 1181 additions and 681 deletions
+46 -31
View File
@@ -279,27 +279,31 @@ pub mod pallet {
pub enum Event<T: Config<I>, I: 'static = ()> {
/// A motion (given hash) has been proposed (by given account) with a threshold (given
/// `MemberCount`).
/// \[account, proposal_index, proposal_hash, threshold\]
Proposed(T::AccountId, ProposalIndex, T::Hash, MemberCount),
Proposed {
account: T::AccountId,
proposal_index: ProposalIndex,
proposal_hash: T::Hash,
threshold: MemberCount,
},
/// A motion (given hash) has been voted on by given account, leaving
/// a tally (yes votes and no votes given respectively as `MemberCount`).
/// \[account, proposal_hash, voted, yes, no\]
Voted(T::AccountId, T::Hash, bool, MemberCount, MemberCount),
Voted {
account: T::AccountId,
proposal_hash: T::Hash,
voted: bool,
yes: MemberCount,
no: MemberCount,
},
/// A motion was approved by the required threshold.
/// \[proposal_hash\]
Approved(T::Hash),
Approved { proposal_hash: T::Hash },
/// A motion was not approved by the required threshold.
/// \[proposal_hash\]
Disapproved(T::Hash),
Disapproved { proposal_hash: T::Hash },
/// A motion was executed; result will be `Ok` if it returned without error.
/// \[proposal_hash, result\]
Executed(T::Hash, DispatchResult),
Executed { proposal_hash: T::Hash, result: DispatchResult },
/// A single member did some action; result will be `Ok` if it returned without error.
/// \[proposal_hash, result\]
MemberExecuted(T::Hash, DispatchResult),
MemberExecuted { proposal_hash: T::Hash, result: DispatchResult },
/// A proposal was closed because its threshold was reached or after its duration was up.
/// \[proposal_hash, yes, no\]
Closed(T::Hash, MemberCount, MemberCount),
Closed { proposal_hash: T::Hash, yes: MemberCount, no: MemberCount },
}
/// Old name generated by `decl_event`.
@@ -442,10 +446,10 @@ pub mod pallet {
let proposal_hash = T::Hashing::hash_of(&proposal);
let result = proposal.dispatch(RawOrigin::Member(who).into());
Self::deposit_event(Event::MemberExecuted(
Self::deposit_event(Event::MemberExecuted {
proposal_hash,
result.map(|_| ()).map_err(|e| e.error),
));
result: result.map(|_| ()).map_err(|e| e.error),
});
Ok(get_result_weight(result)
.map(|w| {
@@ -521,10 +525,10 @@ pub mod pallet {
if threshold < 2 {
let seats = Self::members().len() as MemberCount;
let result = proposal.dispatch(RawOrigin::Members(1, seats).into());
Self::deposit_event(Event::Executed(
Self::deposit_event(Event::Executed {
proposal_hash,
result.map(|_| ()).map_err(|e| e.error),
));
result: result.map(|_| ()).map_err(|e| e.error),
});
Ok(get_result_weight(result)
.map(|w| {
@@ -552,7 +556,12 @@ pub mod pallet {
};
<Voting<T, I>>::insert(proposal_hash, votes);
Self::deposit_event(Event::Proposed(who, index, proposal_hash, threshold));
Self::deposit_event(Event::Proposed {
account: who,
proposal_index: index,
proposal_hash,
threshold,
});
Ok(Some(T::WeightInfo::propose_proposed(
proposal_len as u32, // B
@@ -620,7 +629,13 @@ pub mod pallet {
let yes_votes = voting.ayes.len() as MemberCount;
let no_votes = voting.nays.len() as MemberCount;
Self::deposit_event(Event::Voted(who, proposal, approve, yes_votes, no_votes));
Self::deposit_event(Event::Voted {
account: who,
proposal_hash: proposal,
voted: approve,
yes: yes_votes,
no: no_votes,
});
Voting::<T, I>::insert(&proposal, voting);
@@ -701,7 +716,7 @@ pub mod pallet {
length_bound,
proposal_weight_bound,
)?;
Self::deposit_event(Event::Closed(proposal_hash, yes_votes, no_votes));
Self::deposit_event(Event::Closed { proposal_hash, yes: yes_votes, no: no_votes });
let (proposal_weight, proposal_count) =
Self::do_approve_proposal(seats, yes_votes, proposal_hash, proposal);
return Ok((
@@ -713,7 +728,7 @@ pub mod pallet {
)
.into())
} else if disapproved {
Self::deposit_event(Event::Closed(proposal_hash, yes_votes, no_votes));
Self::deposit_event(Event::Closed { proposal_hash, yes: yes_votes, no: no_votes });
let proposal_count = Self::do_disapprove_proposal(proposal_hash);
return Ok((
Some(T::WeightInfo::close_early_disapproved(seats, proposal_count)),
@@ -746,7 +761,7 @@ pub mod pallet {
length_bound,
proposal_weight_bound,
)?;
Self::deposit_event(Event::Closed(proposal_hash, yes_votes, no_votes));
Self::deposit_event(Event::Closed { proposal_hash, yes: yes_votes, no: no_votes });
let (proposal_weight, proposal_count) =
Self::do_approve_proposal(seats, yes_votes, proposal_hash, proposal);
Ok((
@@ -758,7 +773,7 @@ pub mod pallet {
)
.into())
} else {
Self::deposit_event(Event::Closed(proposal_hash, yes_votes, no_votes));
Self::deposit_event(Event::Closed { proposal_hash, yes: yes_votes, no: no_votes });
let proposal_count = Self::do_disapprove_proposal(proposal_hash);
Ok((Some(T::WeightInfo::close_disapproved(seats, proposal_count)), Pays::No).into())
}
@@ -848,15 +863,15 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
proposal_hash: T::Hash,
proposal: <T as Config<I>>::Proposal,
) -> (Weight, u32) {
Self::deposit_event(Event::Approved(proposal_hash));
Self::deposit_event(Event::Approved { proposal_hash });
let dispatch_weight = proposal.get_dispatch_info().weight;
let origin = RawOrigin::Members(yes_votes, seats).into();
let result = proposal.dispatch(origin);
Self::deposit_event(Event::Executed(
Self::deposit_event(Event::Executed {
proposal_hash,
result.map(|_| ()).map_err(|e| e.error),
));
result: result.map(|_| ()).map_err(|e| e.error),
});
// default to the dispatch info weight for safety
let proposal_weight = get_result_weight(result).unwrap_or(dispatch_weight); // P1
@@ -866,7 +881,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
fn do_disapprove_proposal(proposal_hash: T::Hash) -> u32 {
// disapproved
Self::deposit_event(Event::Disapproved(proposal_hash));
Self::deposit_event(Event::Disapproved { proposal_hash });
Self::remove_proposal(proposal_hash)
}