-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Use EncodeLike for storages traits #3676
Changes from all commits
dcfee51
a932ddd
2013b81
09035c3
36a97a5
c58fddb
4fadf1b
a06f08e
767b306
e05776e
c71c3c1
ee9c5c6
4103679
1800cfe
e3081fc
a22ac94
bdd8260
c58027b
6dfe36f
c5cce62
ab00065
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ use sr_primitives::{ | |
traits::{Zero, Bounded, CheckedMul, CheckedDiv, EnsureOrigin, Hash, Dispatchable}, | ||
weights::SimpleDispatchInfo, | ||
}; | ||
use codec::{Encode, Decode, Input, Output, Error}; | ||
use codec::{Ref, Encode, Decode, Input, Output, Error}; | ||
use support::{ | ||
decl_module, decl_storage, decl_event, ensure, | ||
Parameter, | ||
|
@@ -377,10 +377,10 @@ decl_module! { | |
|
||
let index = Self::public_prop_count(); | ||
PublicPropCount::put(index + 1); | ||
<DepositOf<T>>::insert(index, (value, vec![who.clone()])); | ||
<DepositOf<T>>::insert(index, (value, &[&who][..])); | ||
|
||
let new_prop = (index, (*proposal).clone(), who); | ||
<PublicProps<T>>::append_or_put([new_prop].into_iter()); | ||
let new_prop = (index, proposal, who); | ||
<PublicProps<T>>::append_or_put(&[Ref::from(&new_prop)][..]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If can be refactored and you think it is worth it, would be good to have a small issue for it after the PR is merged 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ref from inside srml-support/storage/generator like in the implementation of linkedmap and map. |
||
|
||
Self::deposit_event(RawEvent::Proposed(index, value)); | ||
} | ||
|
@@ -609,7 +609,7 @@ decl_module! { | |
#[weight = SimpleDispatchInfo::FixedNormal(500_000)] | ||
pub fn delegate(origin, to: T::AccountId, conviction: Conviction) { | ||
let who = ensure_signed(origin)?; | ||
<Delegations<T>>::insert(who.clone(), (to.clone(), conviction)); | ||
<Delegations<T>>::insert(&who, (&to, conviction)); | ||
// Currency is locked indefinitely as long as it's delegated. | ||
T::Currency::extend_lock( | ||
DEMOCRACY_ID, | ||
|
@@ -788,10 +788,10 @@ impl<T: Trait> Module<T> { | |
/// Actually enact a vote, if legit. | ||
fn do_vote(who: T::AccountId, ref_index: ReferendumIndex, vote: Vote) -> Result { | ||
ensure!(Self::is_active_referendum(ref_index), "vote given for invalid referendum."); | ||
if !<VoteOf<T>>::exists(&(ref_index, who.clone())) { | ||
<VotersFor<T>>::append_or_insert(ref_index, [who.clone()].into_iter()); | ||
if !<VoteOf<T>>::exists((ref_index, &who)) { | ||
<VotersFor<T>>::append_or_insert(ref_index, &[&who][..]); | ||
} | ||
<VoteOf<T>>::insert(&(ref_index, who), vote); | ||
<VoteOf<T>>::insert((ref_index, &who), vote); | ||
Ok(()) | ||
} | ||
|
||
|
@@ -929,7 +929,7 @@ impl<T: Trait> Module<T> { | |
} else { | ||
<DispatchQueue<T>>::append_or_insert( | ||
now + info.delay, | ||
[Some((info.proposal, index))].into_iter() | ||
&[Some((info.proposal, index))][..] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that makes no real difference, but okay. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no it will compile with something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm at some point we should derive EncodeLike for standard iterator structures. |
||
); | ||
} | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -816,7 +816,7 @@ impl<T: Trait> Module<T> { | |
if set_len + 1 == VOTER_SET_SIZE { | ||
NextVoterSet::put(next + 1); | ||
} | ||
<Voters<T>>::append_or_insert(next, [Some(who.clone())].into_iter()) | ||
<Voters<T>>::append_or_insert(next, &[Some(who.clone())][..]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are still cloning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes because satisfying both iterator constrained and |
||
} | ||
} | ||
|
||
|
@@ -862,7 +862,7 @@ impl<T: Trait> Module<T> { | |
|
||
// initialize leaderboard. | ||
let leaderboard_size = empty_seats + T::CarryCount::get() as usize; | ||
<Leaderboard<T>>::put(vec![(Zero::zero(), T::AccountId::default()); leaderboard_size]); | ||
<Leaderboard<T>>::put(vec![(BalanceOf::<T>::zero(), T::AccountId::default()); leaderboard_size]); | ||
|
||
Self::deposit_event(RawEvent::TallyStarted(empty_seats as u32)); | ||
} | ||
|
@@ -1027,7 +1027,7 @@ impl<T: Trait> Module<T> { | |
.chunks(APPROVAL_SET_SIZE) | ||
.enumerate() | ||
.for_each(|(index, slice)| <ApprovalsOf<T>>::insert( | ||
(who.clone(), index as SetIndex), slice.to_vec()) | ||
(&who, index as SetIndex), slice) | ||
); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @shawntabrizi in v2 for kitties tutorial: the original issue of the PR references the v2 tutorial. If keys of type tuple are still around they can be refactored now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome!