mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 23:51:05 +00:00
Generalised proxies (#6156)
* Initial work * It should work * Fix node * Fix tests * Initial test * Tests * Expunge proxy functionality from democracy and elections * Allow different proxy types * Repotted * Build * Build * Making a start on weights * Undo breaking change * Line widths. * Fix * fix tests * finish benchmarks? * Storage name! * Utility -> Proxy * proxy weight * add proxy weight * remove weights * Update transfer constraint * Again, fix constraints * Fix negation * Update frame/proxy/Cargo.toml Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Remove unneeded event. * Grumbles * Apply suggestions from code review Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -274,10 +274,6 @@ decl_storage! {
|
||||
/// of each entry; It may be the direct summed approval stakes, or a weighted version of it.
|
||||
/// Sorted from low to high.
|
||||
pub Leaderboard get(fn leaderboard): Option<Vec<(BalanceOf<T>, T::AccountId)> >;
|
||||
|
||||
/// Who is able to vote for whom. Value is the fund-holding account, key is the
|
||||
/// vote-transaction-sending account.
|
||||
pub Proxy get(fn proxy): map hasher(blake2_128_concat) T::AccountId => Option<T::AccountId>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,8 +288,6 @@ decl_error! {
|
||||
CannotReapPresenting,
|
||||
/// Cannot reap during grace period.
|
||||
ReapGrace,
|
||||
/// Not a proxy.
|
||||
NotProxy,
|
||||
/// Invalid reporter index.
|
||||
InvalidReporterIndex,
|
||||
/// Invalid target index.
|
||||
@@ -430,23 +424,6 @@ decl_module! {
|
||||
Self::do_set_approvals(who, votes, index, hint, value)
|
||||
}
|
||||
|
||||
/// Set candidate approvals from a proxy. Approval slots stay valid as long as candidates in
|
||||
/// those slots are registered.
|
||||
///
|
||||
/// # <weight>
|
||||
/// - Same as `set_approvals` with one additional storage read.
|
||||
/// # </weight>
|
||||
#[weight = 2_500_000_000]
|
||||
fn proxy_set_approvals(origin,
|
||||
votes: Vec<bool>,
|
||||
#[compact] index: VoteIndex,
|
||||
hint: SetIndex,
|
||||
#[compact] value: BalanceOf<T>,
|
||||
) -> DispatchResult {
|
||||
let who = Self::proxy(ensure_signed(origin)?).ok_or(Error::<T>::NotProxy)?;
|
||||
Self::do_set_approvals(who, votes, index, hint, value)
|
||||
}
|
||||
|
||||
/// Remove a voter. For it not to be a bond-consuming no-op, all approved candidate indices
|
||||
/// must now be either unregistered or registered to a candidate that registered the slot
|
||||
/// after the voter gave their last approval set.
|
||||
|
||||
@@ -868,45 +868,6 @@ fn election_voting_should_work() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn election_proxy_voting_should_work() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0));
|
||||
|
||||
<Proxy<Test>>::insert(11, 1);
|
||||
<Proxy<Test>>::insert(12, 2);
|
||||
<Proxy<Test>>::insert(13, 3);
|
||||
<Proxy<Test>>::insert(14, 4);
|
||||
assert_ok!(
|
||||
Elections::proxy_set_approvals(Origin::signed(11), vec![true], 0, 0, 10)
|
||||
);
|
||||
assert_ok!(
|
||||
Elections::proxy_set_approvals(Origin::signed(14), vec![true], 0, 1, 40)
|
||||
);
|
||||
|
||||
assert_eq!(Elections::all_approvals_of(&1), vec![true]);
|
||||
assert_eq!(Elections::all_approvals_of(&4), vec![true]);
|
||||
assert_eq!(voter_ids(), vec![1, 4]);
|
||||
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 1));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3), 2));
|
||||
|
||||
assert_ok!(
|
||||
Elections::proxy_set_approvals(Origin::signed(12), vec![false, true], 0, 2, 20)
|
||||
);
|
||||
assert_ok!(
|
||||
Elections::proxy_set_approvals(Origin::signed(13), vec![false, true], 0, 3, 30)
|
||||
);
|
||||
|
||||
assert_eq!(Elections::all_approvals_of(&1), vec![true]);
|
||||
assert_eq!(Elections::all_approvals_of(&4), vec![true]);
|
||||
assert_eq!(Elections::all_approvals_of(&2), vec![false, true]);
|
||||
assert_eq!(Elections::all_approvals_of(&3), vec![false, true]);
|
||||
|
||||
assert_eq!(voter_ids(), vec![1, 4, 2, 3]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn election_simple_tally_should_work() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
|
||||
Reference in New Issue
Block a user