Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
b20b807
Merge remote-tracking branch 'origin/master' into gav-xts-dont-panic
gavofyork May 29, 2018
b7ca4ae
Merge remote-tracking branch 'origin/master' into gav-xts-dont-panic
gavofyork May 29, 2018
b2a48c8
Update wasm.
gavofyork May 29, 2018
2d3a1ce
consensus, session and staking all panic-safe.
gavofyork May 29, 2018
881f6af
Democracy doesn't panic in apply.
gavofyork May 29, 2018
fee0f6f
Fix tests.
gavofyork May 29, 2018
8b9f50f
Extra helper macro, council depanicked.
gavofyork May 30, 2018
0e31a73
Fix one test.
gavofyork May 30, 2018
820ec13
Fix up all council tests. No panics!
gavofyork May 30, 2018
62ab840
Council voting depanicked.
gavofyork May 30, 2018
ff5da1a
Dispatch returns result.
gavofyork May 31, 2018
1123ff7
session & staking tests updated
gavofyork May 31, 2018
00ba4e0
Fix democracy tests.
gavofyork May 31, 2018
b6e54c1
Fix council tests.
gavofyork May 31, 2018
f3c1b9b
Fix up polkadot parachains in runtime
gavofyork May 31, 2018
3b8a4be
Merge branch 'master' into gav-result-dispatch
gavofyork May 31, 2018
d51a9bd
Merge remote-tracking branch 'origin/master' into gav-result-dispatch
gavofyork May 31, 2018
6c81a1e
Fix borked merge
gavofyork May 31, 2018
0141a68
More Slicable support
gavofyork Jun 1, 2018
34d0b75
Basic storage types.
gavofyork Jun 1, 2018
96a9b01
Existential deposit for contract creation
gavofyork Jun 1, 2018
ea2499f
Basic implemnetation along with removals
gavofyork Jun 1, 2018
193dde7
Fix tests.
gavofyork Jun 1, 2018
6f9636c
externalities builder fix.
gavofyork Jun 1, 2018
777f4dc
Tests.
gavofyork Jun 1, 2018
4027bd2
Fix up the runtime.
gavofyork Jun 1, 2018
de952ba
Fix tests.
gavofyork Jun 2, 2018
5e19a40
Add generic `Address` type.
gavofyork Jun 2, 2018
752f1a9
Merge branch 'master' into gav-enum-accounts
gavofyork Jun 2, 2018
014c13e
Initial function integration of Address into Extrinsic.
gavofyork Jun 3, 2018
8d34279
Fix build
gavofyork Jun 3, 2018
dd824ef
All tests compile.
gavofyork Jun 3, 2018
f2bebd2
Fix (some) tests.
gavofyork Jun 3, 2018
9ed26a5
Fix signing.
gavofyork Jun 3, 2018
f4ab2e5
Merge branch 'gav-enum-accounts' of github.com:paritytech/polkadot in…
gavofyork Jun 3, 2018
3a1835a
Push error.
gavofyork Jun 3, 2018
b3a5037
transfer can accept Address
gavofyork Jun 3, 2018
a0f0e05
Make Address generic over AccountIndex
gavofyork Jun 4, 2018
3e978c3
Fix test
gavofyork Jun 4, 2018
b04ff33
Make Council use Address for dispatch.
gavofyork Jun 4, 2018
95063be
Fix build
gavofyork Jun 4, 2018
0bd2d97
Bend over backwards to support braindead derive.
gavofyork Jun 4, 2018
e241ebd
Repot some files.
gavofyork Jun 4, 2018
67d1e74
Fix tests.
gavofyork Jun 4, 2018
d6439e8
Fix grumbles
gavofyork Jun 4, 2018
2a391c1
Remove Default bound
gavofyork Jun 4, 2018
2353b0b
Fix build for new nightly.
gavofyork Jun 4, 2018
1f5b7da
Merge remote-tracking branch 'origin/master' into gav-enum-accounts
gavofyork Jun 4, 2018
904c7cc
Make `apply_extrinsic` never panic, return useful Result.
gavofyork Jun 4, 2018
cef4d4e
Merge remote-tracking branch 'origin/master' into gav-enum-accounts
gavofyork Jun 5, 2018
5401577
Merge remote-tracking branch 'origin/master' into gav-enum-accounts
gavofyork Jun 7, 2018
48d1e9f
More merge hell
gavofyork Jun 7, 2018
b689e16
Doesn't build, but might do soon
gavofyork Jun 7, 2018
f9f875e
Serde woes
gavofyork Jun 7, 2018
d83316a
get substrate-runtime-staking compiling
rphmeier Jun 7, 2018
86de50a
Polkadot builds again!
gavofyork Jun 8, 2018
fcdfdce
Fix all build.
gavofyork Jun 8, 2018
9ad1272
Fix tests & binaries.
gavofyork Jun 8, 2018
6d27096
Merge remote-tracking branch 'origin/master' into gav-enum-accounts
gavofyork Jun 8, 2018
d3cb378
Reserve some extra initial byte values of address for future format c…
gavofyork Jun 8, 2018
c614f5d
Make semantic of `ReservedBalance` clear.
gavofyork Jun 8, 2018
684daf0
Fix panic handler.
gavofyork Jun 8, 2018
f5a8b74
Integrate other balance transformations into the new model
gavofyork Jun 8, 2018
6ba768d
Fix runtime tests.
gavofyork Jun 9, 2018
3534cc5
Fix panic build.
gavofyork Jun 10, 2018
267c360
Tests for demonstrating interaction between balance types.
gavofyork Jun 10, 2018
7abaa1d
Repot some runtime code
gavofyork Jun 10, 2018
2a39363
Fix checkedblock in non-std builds
gavofyork Jun 10, 2018
8b820ed
Get rid of `DoLookup` phantom.
gavofyork Jun 11, 2018
a6426db
Attempt to make transaction_pool work with lookups.
gavofyork Jun 11, 2018
fe6fee9
Remove vscode settings
gavofyork Jun 11, 2018
766e455
New attempt at making transaction pool work.
gavofyork Jun 12, 2018
2015e6d
It builds again!
gavofyork Jun 12, 2018
584d3e1
--all builds
gavofyork Jun 12, 2018
25bd52e
Fix tests.
gavofyork Jun 12, 2018
917455e
New build.
gavofyork Jun 12, 2018
abe5d64
Test account nonce reset.
gavofyork Jun 12, 2018
c4b2703
polkadot transaction pool tests/framework.
gavofyork Jun 13, 2018
97c0e02
Initial draft (working).
gavofyork Jun 14, 2018
8269eb3
Address grumbles.
gavofyork Jun 14, 2018
b54081a
Merge branch 'gav-enum-accounts' into gav-slogging
gavofyork Jun 14, 2018
1cea609
Revert bad `map_or`
gavofyork Jun 14, 2018
49b539e
Merge remote-tracking branch 'origin/dk-pwasm-alloc-fix' into gav-enu…
gavofyork Jun 15, 2018
8e30aad
Rebuild binaries, workaround.
gavofyork Jun 15, 2018
1d351d0
Merge branch 'gav-enum-accounts' into gav-slogging
gavofyork Jun 15, 2018
8c999d2
Avoid checking in vscode
gavofyork Jun 15, 2018
2dcd073
reconnecting, shared, slog
gavofyork Jun 15, 2018
0e2aa61
Merge
gavofyork Jun 15, 2018
678d027
Merge branch 'gav-enum-accounts' into gav-slogging
gavofyork Jun 15, 2018
4c2cb9c
CLI options for name and telemetry url
gavofyork Jun 15, 2018
9fe8144
ensure telemetry url imples enabled
gavofyork Jun 15, 2018
8065ad8
Avoid casting to usize early.
gavofyork Jun 15, 2018
5fa7866
Merge branch 'gav-enum-accounts' into gav-slogging
gavofyork Jun 15, 2018
f474509
Provide on-connect event for session message
gavofyork Jun 15, 2018
3747b9b
Better port
gavofyork Jun 15, 2018
94e15d0
heartbeat and some renaming
gavofyork Jun 15, 2018
e5cc4e3
transaction pool stuff
gavofyork Jun 15, 2018
e9fcff0
minor renaming.
gavofyork Jun 15, 2018
c1e89f5
report telemetry
gavofyork Jun 15, 2018
d924faf
cleanups.
gavofyork Jun 15, 2018
80aadf1
Fix for previous cleanup
gavofyork Jun 15, 2018
8e1041f
Initial draft (working).
gavofyork Jun 14, 2018
a96fa41
Avoid checking in vscode
gavofyork Jun 15, 2018
1846099
reconnecting, shared, slog
gavofyork Jun 15, 2018
a18fcdc
CLI options for name and telemetry url
gavofyork Jun 15, 2018
7537ec7
ensure telemetry url imples enabled
gavofyork Jun 15, 2018
b683b73
Provide on-connect event for session message
gavofyork Jun 15, 2018
9408973
Better port
gavofyork Jun 15, 2018
62e336f
heartbeat and some renaming
gavofyork Jun 15, 2018
b828986
transaction pool stuff
gavofyork Jun 15, 2018
96342fc
minor renaming.
gavofyork Jun 15, 2018
b4626c0
report telemetry
gavofyork Jun 15, 2018
2b0116e
cleanups.
gavofyork Jun 15, 2018
1e58c8e
Fix for previous cleanup
gavofyork Jun 15, 2018
f27740f
Merge branch 'gav-slogging' of github.com:paritytech/polkadot into ga…
gavofyork Jun 19, 2018
16daf46
Address grumble
gavofyork Jun 19, 2018
4d88d11
Final grumble and repot telemetry to substrate
gavofyork Jun 19, 2018
2f3ed06
Fix comment
gavofyork Jun 19, 2018
d734aec
Merge
gavofyork Jun 19, 2018
c593380
Please build, travis...
gavofyork Jun 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make Council use Address for dispatch.
  • Loading branch information
gavofyork committed Jun 4, 2018
commit b04ff33d319b23f9f5c4824807ff6f1502ab450d
9 changes: 5 additions & 4 deletions polkadot/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub const PARACHAINS_SET_POSITION: u32 = 1;
/// Concrete runtime type used to parameterize the various modules.
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
pub struct Concrete;

impl HasPublicAux for Concrete {
Expand All @@ -85,6 +85,8 @@ impl system::Trait for Concrete {
type Hashing = BlakeTwo256;
type Digest = generic::Digest<Log>;
type AccountId = AccountId;
type Address = Address;
type Lookup = Staking;
type Header = generic::Header<BlockNumber, Hash, Log>;
}
/// System module for this concrete runtime.
Expand All @@ -110,9 +112,6 @@ impl session::Trait for Concrete {
/// Session module for this concrete runtime.
pub type Session = session::Module<Concrete>;

/// The address format for describing accounts.
pub type Address = staking::Address<AccountId, AccountIndex>;

impl staking::Trait for Concrete {
type Balance = Balance;
type DetermineContractAddress = BlakeTwo256;
Expand Down Expand Up @@ -162,6 +161,8 @@ impl_outer_dispatch! {
}
}

/// The address format for describing accounts.
pub type Address = staking::Address<Concrete>;
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, Hash, Log>;
/// Block type as expected by this runtime.
Expand Down
4 changes: 2 additions & 2 deletions substrate/runtime-support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ macro_rules! decl_module {
) => {
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
pub struct $mod_type<$trait_instance: $trait_name>($crate::dispatch::PhantomData<$trait_instance>);
decl_dispatch! {
impl for $mod_type<$trait_instance: $trait_name>;
Expand All @@ -92,7 +92,7 @@ macro_rules! decl_module {
) => {
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
struct $mod_type<$trait_instance: $trait_name>($crate::dispatch::PhantomData<$trait_instance>);
decl_dispatch! {
impl for $mod_type<$trait_instance: $trait_name>;
Expand Down
17 changes: 10 additions & 7 deletions substrate/runtime/council/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern crate substrate_runtime_staking as staking;
extern crate substrate_runtime_system as system;

use rstd::prelude::*;
use primitives::traits::{Zero, One, RefInto, As};
use primitives::traits::{Zero, One, RefInto, As, Lookup};
use runtime_support::{StorageValue, StorageMap};
use runtime_support::dispatch::Result;

Expand Down Expand Up @@ -103,14 +103,14 @@ decl_module! {
pub struct Module<T: Trait>;
pub enum Call where aux: T::PublicAux {
fn set_approvals(aux, votes: Vec<bool>, index: VoteIndex) -> Result = 0;
fn reap_inactive_voter(aux, signed_index: u32, who: T::AccountId, who_index: u32, assumed_vote_index: VoteIndex) -> Result = 1;
fn reap_inactive_voter(aux, signed_index: u32, who: staking::Address<T>, who_index: u32, assumed_vote_index: VoteIndex) -> Result = 1;
fn retract_voter(aux, index: u32) -> Result = 2;
fn submit_candidacy(aux, slot: u32) -> Result = 3;
fn present_winner(aux, candidate: T::AccountId, total: T::Balance, index: VoteIndex) -> Result = 4;
fn present_winner(aux, candidate: staking::Address<T>, total: T::Balance, index: VoteIndex) -> Result = 4;
}
pub enum PrivCall {
fn set_desired_seats(count: u32) -> Result = 0;
fn remove_member(who: T::AccountId) -> Result = 1;
fn remove_member(who: staking::Address<T>) -> Result = 1;
fn set_presentation_duration(count: T::BlockNumber) -> Result = 2;
fn set_term_duration(count: T::BlockNumber) -> Result = 3;
}
Expand Down Expand Up @@ -251,10 +251,11 @@ impl<T: Trait> Module<T> {
fn reap_inactive_voter(
aux: &T::PublicAux,
signed_index: u32,
who: T::AccountId,
who: staking::Address<T>,
who_index: u32,
assumed_vote_index: VoteIndex
) -> Result {
let who = <staking::Module<T>>::lookup(who)?;
ensure!(!Self::presentation_active(), "cannot reap during presentation period");
ensure!(Self::voter_last_active(aux.ref_into()).is_some(), "reaper must be a voter");
let last_active = Self::voter_last_active(&who).ok_or("target for inactivity cleanup must be active")?;
Expand Down Expand Up @@ -336,10 +337,11 @@ impl<T: Trait> Module<T> {
/// `signed` should have at least
fn present_winner(
aux: &T::PublicAux,
candidate: T::AccountId,
candidate: staking::Address<T>,
total: T::Balance,
index: VoteIndex
) -> Result {
let candidate = <staking::Module<T>>::lookup(candidate)?;
ensure!(index == Self::vote_index(), "index not current");
let (_, _, expiring) = Self::next_finalise().ok_or("cannot present outside of presentation period")?;
let stakes = Self::snapshoted_stakes();
Expand Down Expand Up @@ -391,7 +393,8 @@ impl<T: Trait> Module<T> {
/// Remove a particular member. A tally will happen instantly (if not already in a presentation
/// period) to fill the seat if removal means that the desired members are not met.
/// This is effective immediately.
fn remove_member(who: T::AccountId) -> Result {
fn remove_member(who: staking::Address<T>) -> Result {
let who = <staking::Module<T>>::lookup(who)?;
let new_council: Vec<(T::AccountId, T::BlockNumber)> = Self::active_council()
.into_iter()
.filter(|i| i.0 != who)
Expand Down
2 changes: 1 addition & 1 deletion substrate/runtime/primitives/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<Address, Index, Call, Signature, DoLookup> traits::Checkable for UncheckedE
} else {
let extrinsic: Extrinsic<<DoLookup as Lookup<Address>>::Target, Index, Call>
= Extrinsic {
signed: <DoLookup as Lookup<Address>>::lookup(self.extrinsic.signed).ok_or("bad address in extrinsic")?,
signed: <DoLookup as Lookup<Address>>::lookup(self.extrinsic.signed)?,
index: self.extrinsic.index,
function: self.extrinsic.function,
};
Expand Down
4 changes: 2 additions & 2 deletions substrate/runtime/primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Primitives for the runtime modules.

use rstd::prelude::*;
use rstd;
use rstd::{self, result};
#[cfg(not(feature = "std"))] use runtime_io;
use substrate_primitives;
use codec::Slicable;
Expand All @@ -38,7 +38,7 @@ pub trait Lookup<Source> {
/// Type to lookup into.
type Target;
/// Attempt a lookup.
fn lookup(s: Source) -> Option<Self::Target>;
fn lookup(s: Source) -> result::Result<Self::Target, &'static str>;
}

/// Simple payment making trait, operating on a single generic `AccountId` type.
Expand Down
146 changes: 76 additions & 70 deletions substrate/runtime/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use runtime_support::{StorageValue, StorageMap, Parameter};
use runtime_support::dispatch::Result;
use primitives::traits::{Zero, One, Bounded, RefInto, SimpleArithmetic, Executable, MakePayment,
As, Lookup};
use primitives::generic::Member;
use primitives::generic::{Member, MaybeSerializeDebug};

mod contract;
#[cfg(test)]
Expand All @@ -67,78 +67,84 @@ const ENUM_SET_SIZE: usize = 64;
/// The byte to identify intention to reclaim an existing account index.
const RECLAIM_INDEX_MAGIC: usize = 0x69;

/// A vetted and verified extrinsic from the external world.
#[derive(PartialEq, Eq, Clone)]
#[cfg_attr(feature = "std", derive(Serialize, Debug))]
pub enum Address<AccountId, AccountIndex> where
AccountId: Member,
AccountIndex: Member,
{
/// It's an account ID (pubkey).
Id(AccountId),
/// It's an account index.
Index(AccountIndex),
}

impl<AccountId, AccountIndex> From<AccountId> for Address<AccountId, AccountIndex> where
AccountId: Member,
AccountIndex: Member,
{
fn from(a: AccountId) -> Self {
Address::Id(a)
pub mod address {
use super::{Member, Slicable, As, Input};

/// A vetted and verified extrinsic from the external world.
#[derive(PartialEq, Eq, Clone)]
#[cfg_attr(feature = "std", derive(Serialize, Debug))]
pub enum Address<AccountId, AccountIndex> where
AccountId: Member,
AccountIndex: Member,
{
/// It's an account ID (pubkey).
Id(AccountId),
/// It's an account index.
Index(AccountIndex),
}

impl<AccountId, AccountIndex> From<AccountId> for Address<AccountId, AccountIndex> where
AccountId: Member,
AccountIndex: Member,
{
fn from(a: AccountId) -> Self {
Address::Id(a)
}
}
}

impl<AccountId, AccountIndex> Slicable for Address<AccountId, AccountIndex> where
AccountId: Member + Slicable,
AccountIndex: Member + Slicable + PartialOrd<AccountIndex> + Ord + As<u32> + As<u16> + As<u8> + Copy,
{
fn decode<I: Input>(input: &mut I) -> Option<Self> {
match input.read_byte()? {
255 => Some(Address::Id(Slicable::decode(input)?)),
254 => Some(Address::Index(Slicable::decode(input)?)),
253 => Some(Address::Index(As::sa(u32::decode(input)?))),
252 => Some(Address::Index(As::sa(u16::decode(input)?))),
x => Some(Address::Index(As::sa(x))),
impl<AccountId, AccountIndex> Slicable for Address<AccountId, AccountIndex> where
AccountId: Member + Slicable,
AccountIndex: Member + Slicable + PartialOrd<AccountIndex> + Ord + As<u32> + As<u16> + As<u8> + Copy,
{
fn decode<I: Input>(input: &mut I) -> Option<Self> {
match input.read_byte()? {
255 => Some(Address::Id(Slicable::decode(input)?)),
254 => Some(Address::Index(Slicable::decode(input)?)),
253 => Some(Address::Index(As::sa(u32::decode(input)?))),
252 => Some(Address::Index(As::sa(u16::decode(input)?))),
x => Some(Address::Index(As::sa(x))),
}
}
}

fn encode(&self) -> Vec<u8> {
let mut v = Vec::new();
fn encode(&self) -> Vec<u8> {
let mut v = Vec::new();

match *self {
Address::Id(ref i) => {
v.push(255);
i.using_encoded(|s| v.extend(s));
}
Address::Index(i) if i > As::sa(0xffffffffu32) => {
v.push(254);
i.using_encoded(|s| v.extend(s));
}
Address::Index(i) if i > As::sa(0xffffu32) => {
v.push(253);
As::<u32>::as_(i).using_encoded(|s| v.extend(s));
}
Address::Index(i) if i >= As::sa(252u32) => {
v.push(252);
As::<u16>::as_(i).using_encoded(|s| v.extend(s));
match *self {
Address::Id(ref i) => {
v.push(255);
i.using_encoded(|s| v.extend(s));
}
Address::Index(i) if i > As::sa(0xffffffffu32) => {
v.push(254);
i.using_encoded(|s| v.extend(s));
}
Address::Index(i) if i > As::sa(0xffffu32) => {
v.push(253);
As::<u32>::as_(i).using_encoded(|s| v.extend(s));
}
Address::Index(i) if i >= As::sa(252u32) => {
v.push(252);
As::<u16>::as_(i).using_encoded(|s| v.extend(s));
}
Address::Index(i) => v.push(As::<u8>::as_(i)),
}
Address::Index(i) => v.push(As::<u8>::as_(i)),
}

v
v
}
}
}

impl<AccountId, AccountIndex> Default for Address<AccountId, AccountIndex> where
AccountId: Member + Default,
AccountIndex: Member,
{
fn default() -> Self {
Address::Id(Default::default())
impl<AccountId, AccountIndex> Default for Address<AccountId, AccountIndex> where
AccountId: Member + Default,
AccountIndex: Member,
{
fn default() -> Self {
Address::Id(Default::default())
}
}
}

pub type Address<T> = address::Address<<T as system::Trait>::AccountId, <T as Trait>::AccountIndex>;

#[cfg(test)]
#[derive(Debug, PartialEq, Clone)]
pub enum LockStatus<BlockNumber: Debug + PartialEq + Clone> {
Expand Down Expand Up @@ -171,7 +177,8 @@ impl<Hashing, AccountId> ContractAddressFor<AccountId> for Hashing where
}
}

pub trait Trait: system::Trait + session::Trait {
// MaybeSerializeDebug is workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
pub trait Trait: system::Trait + session::Trait + MaybeSerializeDebug {
/// The balance of an account.
type Balance: Parameter + SimpleArithmetic + Slicable + Default + Copy + As<Self::AccountIndex> + As<usize>;
/// Function type to get the contract address given the creator.
Expand All @@ -184,7 +191,7 @@ pub trait Trait: system::Trait + session::Trait {
decl_module! {
pub struct Module<T: Trait>;
pub enum Call where aux: T::PublicAux {
fn transfer(aux, dest: Address<T::AccountId, T::AccountIndex>, value: T::Balance) -> Result = 0;
fn transfer(aux, dest: Address<T>, value: T::Balance) -> Result = 0;
fn stake(aux) -> Result = 1;
fn unstake(aux) -> Result = 2;
}
Expand Down Expand Up @@ -304,8 +311,8 @@ impl<T: Trait> Module<T> {

/// Transfer some unlocked staking balance to another staker.
/// TODO: probably want to state gas-limit and gas-price.
fn transfer(aux: &T::PublicAux, dest: Address<T::AccountId, T::AccountIndex>, value: T::Balance) -> Result {
let dest = Self::lookup(dest).ok_or("bad destination")?;
fn transfer(aux: &T::PublicAux, dest: Address<T>, value: T::Balance) -> Result {
let dest = Self::lookup(dest)?;
// commit anything that made it this far to storage
if let Some(commit) = Self::effect_transfer(aux.ref_into(), &dest, value, &DirectAccountDb)? {
<AccountDb<T>>::merge(&mut DirectAccountDb, commit);
Expand Down Expand Up @@ -573,17 +580,16 @@ impl<T: Trait> Executable for Module<T> {
}
}

impl<T: Trait> Lookup<Address<T::AccountId, T::AccountIndex>> for Module<T> {
impl<T: Trait> Lookup<address::Address<T::AccountId, T::AccountIndex>> for Module<T> {
type Target = T::AccountId;
fn lookup(a: Address<T::AccountId, T::AccountIndex>) -> Option<T::AccountId> {
fn lookup(a: address::Address<T::AccountId, T::AccountIndex>) -> result::Result<T::AccountId, &'static str> {
match a {
Address::Id(i) => Some(i),
Address::Index(i) => <Module<T>>::lookup_index(i),
address::Address::Id(i) => Ok(i),
address::Address::Index(i) => <Module<T>>::lookup_index(i).ok_or("invalid account index"),
}
}
}


// Each identity's stake may be in one of three bondage states, given by an integer:
// - n | n <= <CurrentEra<T>>::get(): inactive: free to be transferred.
// - ~0: active: currently representing a validator.
Expand Down
4 changes: 3 additions & 1 deletion substrate/runtime/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern crate safe_mix;

use rstd::prelude::*;
use runtime_io::Hashing;
use primitives::traits::{self, CheckEqual, SimpleArithmetic, SimpleBitOps, Zero, One, Bounded};
use primitives::traits::{self, CheckEqual, SimpleArithmetic, SimpleBitOps, Zero, One, Bounded, Lookup};
use runtime_support::{StorageValue, StorageMap, Parameter};
use safe_mix::TripletMix;

Expand Down Expand Up @@ -65,6 +65,8 @@ pub trait Trait {
type Hashing: Hashing<Output = Self::Hash>;
type Digest: Parameter + Default + traits::Digest;
type AccountId: Parameter + Ord + Default;
type Address: Parameter + Default;
type Lookup: Lookup<Self::Address, Target=Self::AccountId>;
type Header: traits::Header<Number = Self::BlockNumber, Hash = Self::Hash, Digest = Self::Digest>;
}

Expand Down