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
25 commits
Select commit Hold shift + click to select a range
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
Remove some aux-dispatch stuff and fix balances
  • Loading branch information
gavofyork committed Sep 6, 2018
commit 5e4c1c40f2f1743501d18677302e070d96ebbf72
116 changes: 0 additions & 116 deletions substrate/runtime-support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,35 +144,6 @@ macro_rules! decl_module {
/// Implement several dispatch modules to create a pairing of a dispatch trait and enum.
#[macro_export]
macro_rules! decl_dispatch {
// WITHOUT AUX
(
impl for $mod_type:ident<$trait_instance:ident: $trait_name:ident>;
$(#[$attr:meta])*
pub enum $call_type:ident {
$(
$(#[$fn_attr:meta])*
fn $fn_name:ident(
$(
$param_name:ident : $param:ty
),*
) -> $result:ty;
)*
}
$($rest:tt)*
) => {
__decl_dispatch_module_without_aux! {
impl for $mod_type<$trait_instance: $trait_name>;
$(#[$attr])*
pub enum $call_type;
$(
fn $fn_name( $( $param_name: $param ),* ) -> $result;
)*
}
decl_dispatch! {
impl for $mod_type<$trait_instance: $trait_name>;
$($rest)*
}
};
// WITH AUX
(
impl for $mod_type:ident<$trait_instance:ident: $trait_name:ident>;
Expand Down Expand Up @@ -217,51 +188,6 @@ macro_rules! decl_dispatch {
}
}

#[macro_export]
#[doc(hidden)]
/// Implement a single dispatch modules to create a pairing of a dispatch trait and enum.
macro_rules! __decl_dispatch_module_without_aux {
(
impl for $mod_type:ident<$trait_instance:ident: $trait_name:ident>;
$(#[$attr:meta])*
pub enum $call_type:ident;
$(
fn $fn_name:ident(
$(
$param_name:ident : $param:ty
),*
)
-> $result:ty;
)*
) => {
__decl_dispatch_module_common! {
impl for $mod_type<$trait_instance: $trait_name>;
$(#[$attr])*
pub enum $call_type;
$( fn $fn_name( $( $param_name : $param ),* ) -> $result; )*
}
impl<$trait_instance: $trait_name> $crate::dispatch::Dispatchable
for $call_type<$trait_instance>
{
type Trait = $trait_instance;
fn dispatch(self) -> $crate::dispatch::Result {
match self {
$(
$call_type::$fn_name( $( $param_name ),* ) =>
<$mod_type<$trait_instance>>::$fn_name( $( $param_name ),* ),
)*
$call_type::__PhantomItem(_) => { panic!("__PhantomItem should never be used.") },
}
}
}
impl<$trait_instance: $trait_name> $crate::dispatch::Callable
for $mod_type<$trait_instance>
{
type Call = $call_type<$trait_instance>;
}
}
}

#[macro_export]
#[doc(hidden)]
/// Implement a single dispatch modules to create a pairing of a dispatch trait and enum.
Expand Down Expand Up @@ -491,9 +417,6 @@ macro_rules! __impl_encode {
) => {{}}
}

pub trait IsSubType<T: Callable> {
fn is_sub_type(&self) -> Option<&<T as Callable>::Call>;
}
pub trait IsAuxSubType<T: AuxCallable> {
fn is_aux_sub_type(&self) -> Option<&<T as AuxCallable>::Call>;
}
Expand Down Expand Up @@ -541,45 +464,6 @@ macro_rules! impl_outer_dispatch {
}
)*
impl_outer_dispatch!{ $($rest)* }
};
(
$(#[$attr:meta])*
pub enum $call_type:ident {
$(
$camelcase:ident,
)*
}
$( $rest:tt )*
) => {
$(#[$attr])*
pub enum $call_type {
$(
$camelcase ( $crate::dispatch::CallableCallFor<$camelcase> )
,)*
}
__impl_outer_dispatch_common! { $call_type, $($camelcase,)* }
impl $crate::dispatch::Dispatchable for $call_type {
type Trait = $call_type;
fn dispatch(self) -> $crate::dispatch::Result {
match self {
$(
$call_type::$camelcase(call) => call.dispatch(),
)*
}
}
}
$(
impl $crate::dispatch::IsSubType<$camelcase> for $call_type {
fn is_sub_type(&self) -> Option<&<$camelcase as $crate::dispatch::Callable>::Call> {
if let $call_type::$camelcase ( ref r ) = *self {
Some(r)
} else {
None
}
}
}
)*
impl_outer_dispatch!{ $($rest)* }
}
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/runtime-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod hashable;

pub use self::storage::{StorageVec, StorageList, StorageValue, StorageMap};
pub use self::hashable::Hashable;
pub use self::dispatch::{Parameter, Dispatchable, Callable, AuxDispatchable, AuxCallable, IsSubType, IsAuxSubType};
pub use self::dispatch::{Parameter, Dispatchable, Callable, AuxDispatchable, AuxCallable, IsAuxSubType};
pub use runtime_io::print;


Expand Down
20 changes: 10 additions & 10 deletions substrate/runtime/balances/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

use super::*;
use runtime_io::with_externalities;
use mock::{Balances, System, Test, new_test_ext};
use mock::{Balances, System, Runtime, new_test_ext};

#[test]
fn reward_should_work() {
with_externalities(&mut new_test_ext(0, true), || {
assert_eq!(Balances::total_balance(&1), 10);
assert_ok!(Balances::reward(&1, 10));
assert_eq!(Balances::total_balance(&1), 20);
assert_eq!(<TotalIssuance<Test>>::get(), 110);
assert_eq!(<TotalIssuance<Runtime>>::get(), 110);
});
}

Expand Down Expand Up @@ -189,7 +189,7 @@ fn slashing_balance_should_work() {
assert!(Balances::slash(&1, 69).is_none());
assert_eq!(Balances::free_balance(&1), 0);
assert_eq!(Balances::reserved_balance(&1), 42);
assert_eq!(<TotalIssuance<Test>>::get(), 44);
assert_eq!(<TotalIssuance<Runtime>>::get(), 44);
});
}

Expand All @@ -202,7 +202,7 @@ fn slashing_incomplete_balance_should_work() {
assert!(Balances::slash(&1, 69).is_some());
assert_eq!(Balances::free_balance(&1), 0);
assert_eq!(Balances::reserved_balance(&1), 0);
assert_eq!(<TotalIssuance<Test>>::get(), 2);
assert_eq!(<TotalIssuance<Runtime>>::get(), 2);
});
}

Expand All @@ -226,7 +226,7 @@ fn slashing_reserved_balance_should_work() {
assert!(Balances::slash_reserved(&1, 42).is_none());
assert_eq!(Balances::reserved_balance(&1), 69);
assert_eq!(Balances::free_balance(&1), 0);
assert_eq!(<TotalIssuance<Test>>::get(), 71);
assert_eq!(<TotalIssuance<Runtime>>::get(), 71);
});
}

Expand All @@ -239,7 +239,7 @@ fn slashing_incomplete_reserved_balance_should_work() {
assert!(Balances::slash_reserved(&1, 69).is_some());
assert_eq!(Balances::free_balance(&1), 69);
assert_eq!(Balances::reserved_balance(&1), 0);
assert_eq!(<TotalIssuance<Test>>::get(), 71);
assert_eq!(<TotalIssuance<Runtime>>::get(), 71);
});
}

Expand Down Expand Up @@ -283,8 +283,8 @@ fn transferring_incomplete_reserved_balance_should_work() {
#[test]
fn transferring_too_high_value_should_not_panic() {
with_externalities(&mut new_test_ext(0, false), || {
<FreeBalance<Test>>::insert(1, u64::max_value());
<FreeBalance<Test>>::insert(2, 1);
<FreeBalance<Runtime>>::insert(1, u64::max_value());
<FreeBalance<Runtime>>::insert(2, 1);

assert_err!(
Balances::transfer(Some(1).into(), 2.into(), u64::max_value()),
Expand All @@ -307,7 +307,7 @@ fn account_removal_on_free_too_low() {
Balances::set_free_balance(&2, 110);
Balances::increase_total_stake_by(110);

assert_eq!(<TotalIssuance<Test>>::get(), 732);
assert_eq!(<TotalIssuance<Runtime>>::get(), 732);
}

// Transfer funds from account 1 of such amount that after this transfer
Expand All @@ -319,6 +319,6 @@ fn account_removal_on_free_too_low() {
assert_eq!(Balances::free_balance(&1), 0);

// Verify that TotalIssuance tracks balance removal when free balance is too low.
assert_eq!(<TotalIssuance<Test>>::get(), 642);
assert_eq!(<TotalIssuance<Runtime>>::get(), 642);
});
}