Indices maintenance (#1705)

* Migrate the indicies crate to 2018 edition.

* Use .cloned() instead of .map(|x| x.clone())

* Update documentation.
This commit is contained in:
Sergei Pepyakin
2019-02-06 14:51:14 +01:00
committed by Bastian Köcher
parent 1d0049ee00
commit 7d8ae2df5c
5 changed files with 28 additions and 41 deletions
+10 -9
View File
@@ -2,6 +2,7 @@
name = "srml-indices"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
hex-literal = "0.1.0"
@@ -10,12 +11,12 @@ safe-mix = { version = "1.0", default-features = false}
parity-codec = { version = "3.0", default-features = false }
parity-codec-derive = { version = "3.0", default-features = false }
substrate-keyring = { path = "../../core/keyring", optional = true }
substrate-primitives = { path = "../../core/primitives", default-features = false }
sr-std = { path = "../../core/sr-std", default-features = false }
sr-io = { path = "../../core/sr-io", default-features = false }
sr-primitives = { path = "../../core/sr-primitives", default-features = false }
rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false }
runtime-io = { package = "sr-io", path = "../../core/sr-io", default-features = false }
primitives = { package = "sr-primitives", path = "../../core/sr-primitives", default-features = false }
srml-support = { path = "../support", default-features = false }
srml-system = { path = "../system", default-features = false }
system = { package = "srml-system", path = "../system", default-features = false }
substrate-primitives = { path = "../../core/primitives", default-features = false }
[dev-dependencies]
ref_thread_local = "0.0"
@@ -29,9 +30,9 @@ std = [
"parity-codec/std",
"parity-codec-derive/std",
"substrate-primitives/std",
"sr-std/std",
"sr-io/std",
"rstd/std",
"runtime-io/std",
"srml-support/std",
"sr-primitives/std",
"srml-system/std",
"primitives/std",
"system/std",
]
+3 -2
View File
@@ -18,9 +18,10 @@
#[cfg(feature = "std")]
use std::fmt;
use super::{Member, Decode, Encode, As, Input, Output};
use crate::{Member, Decode, Encode, As, Input, Output};
/// A vetted and verified extrinsic from the external world.
/// An indices-aware address, which can be either a direct `AccountId` or
/// an index.
#[derive(PartialEq, Eq, Clone)]
#[cfg_attr(feature = "std", derive(Debug, Hash))]
pub enum Address<AccountId, AccountIndex> where
+11 -25
View File
@@ -14,43 +14,26 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! Balances: Handles setting and retrieval of free balance,
//! retrieving total balance, reserve and unreserve balance,
//! repatriating a reserved balance to a beneficiary account that exists,
//! transfering a balance between accounts (when not reserved),
//! slashing an account balance, account removal, rewards,
//! lookup of an index to reclaim an account (when not balance not reserved),
//! increasing total stake.
//! An index is a short form of an address. This module handles allocation
//! of indices for a newly created accounts.
#![cfg_attr(not(feature = "std"), no_std)]
// We need these `extern crate` to be placed here otherwise there will be errors.
// TODO: https://github.com/paritytech/substrate/issues/1509
#[macro_use]
extern crate srml_support as runtime_support;
extern crate sr_std as rstd;
#[macro_use]
extern crate parity_codec_derive;
extern crate parity_codec as codec;
extern crate sr_primitives as primitives;
extern crate srml_system as system;
#[cfg(test)]
#[macro_use]
extern crate ref_thread_local;
#[cfg(test)]
extern crate sr_io as runtime_io;
#[cfg(test)]
extern crate substrate_primitives;
use rstd::{prelude::*, result, marker::PhantomData};
use codec::{Encode, Decode, Codec, Input, Output};
use runtime_support::{StorageValue, StorageMap, Parameter};
use primitives::traits::{One, SimpleArithmetic, As, StaticLookup, Member};
use address::Address as RawAddress;
use system::{IsDeadAccount, OnNewAccount};
use self::address::Address as RawAddress;
mod mock;
pub mod address;
@@ -104,7 +87,10 @@ decl_event!(
<T as system::Trait>::AccountId,
<T as Trait>::AccountIndex
{
/// A new account was created.
/// A new account index was assigned.
///
/// This event is not triggered when an existing index is reassigned
/// to another `AccountId`.
NewAccountIndex(AccountId, AccountIndex),
}
);
@@ -138,7 +124,7 @@ impl<T: Trait> Module<T> {
let enum_set_size = Self::enum_set_size();
let set = Self::enum_set(index / enum_set_size);
let i: usize = (index % enum_set_size).as_();
set.get(i).map(|x| x.clone())
set.get(i).cloned()
}
/// `true` if the account `index` is ready for reclaim.
+3 -4
View File
@@ -19,13 +19,12 @@
#![cfg(test)]
use std::collections::HashSet;
use ref_thread_local::RefThreadLocal;
use ref_thread_local::{ref_thread_local, RefThreadLocal};
use primitives::BuildStorage;
use primitives::testing::{Digest, DigestItem, Header};
use substrate_primitives::{H256, Blake2Hasher};
use runtime_io;
use {GenesisConfig, Module, Trait, system};
use super::{IsDeadAccount, OnNewAccount, ResolveHint};
use {runtime_io, system};
use crate::{GenesisConfig, Module, Trait, IsDeadAccount, OnNewAccount, ResolveHint};
impl_outer_origin!{
pub enum Origin for Runtime {}
+1 -1
View File
@@ -19,7 +19,7 @@
#![cfg(test)]
use super::*;
use mock::{Indices, new_test_ext, make_account, kill_account, TestIsDeadAccount};
use crate::mock::{Indices, new_test_ext, make_account, kill_account, TestIsDeadAccount};
use runtime_io::with_externalities;
#[test]