mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Fix treasury minting (#707)
* Fix minting to do what it's meant to. * Fix tests * Note and fix total issuance. * Undo last non-fix. * More doc
This commit is contained in:
@@ -229,7 +229,7 @@ mod tests {
|
||||
validator_count: 3,
|
||||
minimum_validator_count: 0,
|
||||
bonding_duration: 0,
|
||||
early_era_slash: 0,
|
||||
offline_slash: 0,
|
||||
session_reward: 0,
|
||||
offline_slash_grace: 0,
|
||||
}),
|
||||
@@ -262,7 +262,7 @@ mod tests {
|
||||
construct_block(
|
||||
1,
|
||||
[69u8; 32].into(),
|
||||
hex!("b7d85f23689ae4ae7951eda80e817dffb1c0925e77f5c0de8c94b265df80b9cf").into(),
|
||||
hex!("efdd1840ae46b687fc59fc730892d412a0fb051ef120f9e6dfcf1c416d0fc2cb").into(),
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
@@ -282,7 +282,7 @@ mod tests {
|
||||
construct_block(
|
||||
2,
|
||||
block1().1,
|
||||
hex!("a17d6006e9bb4292b8ebea3b14995672a88caff2c99eeef1d84aeb234e5a0534").into(),
|
||||
hex!("e360ad4a43929e521fd41cdabf8d772eb39f9cbf71fe95bada685e24bd3bbbbb").into(),
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
@@ -307,7 +307,7 @@ mod tests {
|
||||
construct_block(
|
||||
1,
|
||||
[69u8; 32].into(),
|
||||
hex!("27555b6e51bfdb689457fc076a54153a4f5188f47a17607da75e180d844db527").into(),
|
||||
hex!("989ebec4920fe4a99edcd3766eee35a31de92dff20427920ae68d15471afba9a").into(),
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
|
||||
@@ -61,7 +61,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
staking: Some(StakingConfig {
|
||||
current_era: 0,
|
||||
intentions: initial_authorities.iter().cloned().map(Into::into).collect(),
|
||||
early_era_slash: 10000,
|
||||
offline_slash: 10000,
|
||||
session_reward: 100,
|
||||
validator_count: 12,
|
||||
sessions_per_era: 12, // 1 hour per era
|
||||
@@ -148,7 +148,7 @@ fn testnet_genesis(initial_authorities: Vec<AuthorityId>) -> GenesisConfig {
|
||||
validator_count: 2,
|
||||
sessions_per_era: 5,
|
||||
bonding_duration: 2 * 60 * 12,
|
||||
early_era_slash: 0,
|
||||
offline_slash: 0,
|
||||
session_reward: 0,
|
||||
offline_slash_grace: 0,
|
||||
}),
|
||||
|
||||
@@ -764,12 +764,6 @@ macro_rules! __decl_storage_item {
|
||||
#[doc(hidden)]
|
||||
macro_rules! __decl_store_items {
|
||||
// simple values
|
||||
($(#[$doc:meta])* $name:ident : $ty:ty; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* pub $name:ident : $ty:ty; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* $name:ident : default $ty:ty; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
@@ -782,13 +776,13 @@ macro_rules! __decl_store_items {
|
||||
($(#[$doc:meta])* pub $name:ident : required $ty:ty; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* $name:ident : $ty:ty; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* pub $name:ident : $ty:ty; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
|
||||
($(#[$doc:meta])* $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
@@ -801,14 +795,14 @@ macro_rules! __decl_store_items {
|
||||
($(#[$doc:meta])* pub $name:ident get($getfn:ident) : required $ty:ty; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
|
||||
// maps
|
||||
($(#[$doc:meta])* $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
@@ -821,13 +815,13 @@ macro_rules! __decl_store_items {
|
||||
($(#[$doc:meta])* pub $name:ident : required map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
|
||||
($(#[$doc:meta])* $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
@@ -840,6 +834,12 @@ macro_rules! __decl_store_items {
|
||||
($(#[$doc:meta])* pub $name:ident get($getfn:ident) : required map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
($(#[$doc:meta])* pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__decl_store_item!($name); __decl_store_items!($($t)*);
|
||||
};
|
||||
|
||||
// exit
|
||||
() => ()
|
||||
@@ -855,12 +855,6 @@ macro_rules! __decl_store_item {
|
||||
#[doc(hidden)]
|
||||
macro_rules! __impl_store_fns {
|
||||
// simple values
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident : default $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
@@ -873,15 +867,13 @@ macro_rules! __impl_store_fns {
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident : required $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $ty);
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $ty);
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_fn!($traitinstance $name $getfn ($ty) $ty);
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
@@ -898,14 +890,16 @@ macro_rules! __impl_store_fns {
|
||||
__impl_store_fn!($traitinstance $name $getfn ($ty) $ty);
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $ty);
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $ty);
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
|
||||
// maps
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
@@ -918,15 +912,13 @@ macro_rules! __impl_store_fns {
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident : required map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_fn!($traitinstance $name $getfn (Option<$ty>) map [$kty => $ty]);
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_fn!($traitinstance $name $getfn (Option<$ty>) map [$kty => $ty]);
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_fn!($traitinstance $name $getfn ($ty) map [$kty => $ty]);
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
@@ -943,6 +935,14 @@ macro_rules! __impl_store_fns {
|
||||
__impl_store_fn!($traitinstance $name $getfn ($ty) map [$kty => $ty]);
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_fn!($traitinstance $name $getfn (Option<$ty>) map [$kty => $ty]);
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_fn!($traitinstance $name $getfn (Option<$ty>) map [$kty => $ty]);
|
||||
__impl_store_fns!($traitinstance $($t)*);
|
||||
};
|
||||
|
||||
// exit
|
||||
($traitinstance:ident) => ()
|
||||
@@ -967,14 +967,6 @@ macro_rules! __impl_store_fn {
|
||||
#[doc(hidden)]
|
||||
macro_rules! __impl_store_items {
|
||||
// simple values
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident : default $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
@@ -991,15 +983,15 @@ macro_rules! __impl_store_items {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
@@ -1016,16 +1008,16 @@ macro_rules! __impl_store_items {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
|
||||
// maps
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
@@ -1042,15 +1034,15 @@ macro_rules! __impl_store_items {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
@@ -1067,6 +1059,14 @@ macro_rules! __impl_store_items {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
($traitinstance:ident $(#[$doc:meta])* pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => {
|
||||
__impl_store_item!($name $traitinstance);
|
||||
__impl_store_items!($traitinstance $($t)*);
|
||||
};
|
||||
|
||||
// exit
|
||||
($traitinstance:ident) => ()
|
||||
@@ -1095,6 +1095,62 @@ macro_rules! __impl_store_json_metadata {
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! __store_functions_to_json {
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$name:ident :
|
||||
default $ty:ty; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($ty), default
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
pub $name:ident :
|
||||
default $ty:ty; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($ty), default
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$name:ident :
|
||||
required $ty:ty; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($ty), required
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
pub $name:ident :
|
||||
required $ty:ty; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($ty), required
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
// simple values
|
||||
(
|
||||
$prefix_str:tt;
|
||||
@@ -1124,91 +1180,7 @@ macro_rules! __store_functions_to_json {
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$name:ident :
|
||||
default $ty:ty; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($ty), default
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
pub $name:ident :
|
||||
default $ty:ty; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($ty), default
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$name:ident :
|
||||
required $ty:ty; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($ty), required
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
pub $name:ident :
|
||||
required $ty:ty; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($ty), required
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$name:ident get($getfn:ident) :
|
||||
$ty:ty; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($ty)
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
pub $name:ident get($getfn:ident) :
|
||||
$ty:ty; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($ty)
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
@@ -1265,36 +1237,36 @@ macro_rules! __store_functions_to_json {
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$name:ident get($getfn:ident) :
|
||||
$ty:ty; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($ty)
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
pub $name:ident get($getfn:ident) :
|
||||
$ty:ty; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($ty)
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
|
||||
// maps
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$name:ident :
|
||||
map [$kty:ty => $ty:ty]; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($kty, $ty)
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
pub $name:ident :
|
||||
map [$kty:ty => $ty:ty]; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($kty, $ty)
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
@@ -1351,7 +1323,89 @@ macro_rules! __store_functions_to_json {
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$name:ident :
|
||||
map [$kty:ty => $ty:ty]; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($kty, $ty)
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
pub $name:ident :
|
||||
map [$kty:ty => $ty:ty]; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($kty, $ty)
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])* $name:ident get($getfn:ident) :
|
||||
default map [$kty:ty => $ty:ty]; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($kty, $ty), default
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
pub $name:ident get($getfn:ident) :
|
||||
default map [$kty:ty => $ty:ty]; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($kty, $ty), default
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])* $name:ident get($getfn:ident) :
|
||||
required map [$kty:ty => $ty:ty]; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($kty, $ty), required
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
pub $name:ident get($getfn:ident) :
|
||||
required map [$kty:ty => $ty:ty]; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($kty, $ty), required
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
@@ -1380,60 +1434,6 @@ macro_rules! __store_functions_to_json {
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])* $name:ident get($getfn:ident) :
|
||||
default map [$kty:ty => $ty:ty]; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($kty, $ty), default
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
pub $name:ident get($getfn:ident) :
|
||||
default map [$kty:ty => $ty:ty]; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($kty, $ty), default
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])* $name:ident get($getfn:ident) :
|
||||
required map [$kty:ty => $ty:ty]; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($kty, $ty), required
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
(
|
||||
$prefix_str:tt;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
pub $name:ident get($getfn:ident) :
|
||||
required map [$kty:ty => $ty:ty]; $($t:tt)*
|
||||
) => {
|
||||
concat!(
|
||||
__store_function_to_json!($prefix_str,
|
||||
__function_doc_to_json!(""; $($doc_attr)*),
|
||||
$name, __store_type_to_json!($kty, $ty), required
|
||||
),
|
||||
__store_functions_to_json!(","; $($t)*)
|
||||
)
|
||||
};
|
||||
($prefix_str:tt;) => { "" }
|
||||
}
|
||||
|
||||
@@ -1627,3 +1627,33 @@ mod tests {
|
||||
serde_json::from_str(metadata).expect("Is valid json syntax");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
// Do not complain about unused `dispatch` and `dispatch_aux`.
|
||||
#[allow(dead_code)]
|
||||
mod test2 {
|
||||
pub trait Trait {
|
||||
type Origin;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
|
||||
}
|
||||
|
||||
type PairOf<T> = (T, T);
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as TestStorage {
|
||||
SingleDef : default u32;
|
||||
PairDef : default PairOf<u32>;
|
||||
Single : u32;
|
||||
Pair : (u32, u32);
|
||||
}
|
||||
}
|
||||
|
||||
struct TraitImpl {}
|
||||
|
||||
impl Trait for TraitImpl {
|
||||
type Origin = u32;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ impl<T: Trait> Default for GenesisConfig<T> {
|
||||
|
||||
impl<T: Trait> primitives::BuildStorage for GenesisConfig<T> {
|
||||
fn build_storage(self) -> ::std::result::Result<HashMap<Vec<u8>, Vec<u8>>, String> {
|
||||
let total_stake: T::Balance = self.balances.iter().fold(Zero::zero(), |acc, &(_, n)| acc + n);
|
||||
let total_issuance: T::Balance = self.balances.iter().fold(Zero::zero(), |acc, &(_, n)| acc + n);
|
||||
|
||||
let mut r: runtime_io::TestExternalities<KeccakHasher> = map![
|
||||
Self::hash(<NextEnumSet<T>>::key()).to_vec() => T::AccountIndex::sa(self.balances.len() / ENUM_SET_SIZE).encode(),
|
||||
@@ -68,7 +68,7 @@ impl<T: Trait> primitives::BuildStorage for GenesisConfig<T> {
|
||||
Self::hash(<CreationFee<T>>::key()).to_vec() => self.creation_fee.encode(),
|
||||
Self::hash(<ExistentialDeposit<T>>::key()).to_vec() => self.existential_deposit.encode(),
|
||||
Self::hash(<ReclaimRebate<T>>::key()).to_vec() => self.reclaim_rebate.encode(),
|
||||
Self::hash(<TotalIssuance<T>>::key()).to_vec() => total_stake.encode()
|
||||
Self::hash(<TotalIssuance<T>>::key()).to_vec() => total_issuance.encode()
|
||||
];
|
||||
|
||||
let ids: Vec<_> = self.balances.iter().map(|x| x.0.clone()).collect();
|
||||
|
||||
@@ -93,14 +93,15 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for a hook to get called when some balance has been minted.
|
||||
pub trait OnMinted<Balance> {
|
||||
/// Some balance `b` was minted.
|
||||
fn on_minted(b: Balance);
|
||||
/// Trait for a hook to get called when some balance has been minted, causing dilution.
|
||||
pub trait OnDilution<Balance> {
|
||||
/// Some `portion` of the total balance just "grew" by `minted`. `portion` is the pre-growth
|
||||
/// amount (it doesn't take account of the recent growth).
|
||||
fn on_dilution(minted: Balance, portion: Balance);
|
||||
}
|
||||
|
||||
impl<Balance> OnMinted<Balance> for () {
|
||||
fn on_minted(_b: Balance) {}
|
||||
impl<Balance> OnDilution<Balance> for () {
|
||||
fn on_dilution(_minted: Balance, _portion: Balance) {}
|
||||
}
|
||||
|
||||
/// Determinator for whether a given account is able to transfer balance.
|
||||
@@ -159,7 +160,7 @@ impl<A, I, B> From<RawEvent<A, I, B>> for () {
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as Balances {
|
||||
/// The total amount of stake on the system.
|
||||
pub TotalIssuance get(total_stake): required T::Balance;
|
||||
pub TotalIssuance get(total_issuance): required T::Balance;
|
||||
/// The minimum amount allowed to keep an account open.
|
||||
pub ExistentialDeposit get(existential_deposit): required T::Balance;
|
||||
/// The amount credited to a destination's account whose index was reclaimed.
|
||||
@@ -627,13 +628,13 @@ impl<T: Trait> Module<T> {
|
||||
|
||||
/// Increase TotalIssuance by Value.
|
||||
pub fn increase_total_stake_by(value: T::Balance) {
|
||||
if let Some(v) = <Module<T>>::total_stake().checked_add(&value) {
|
||||
if let Some(v) = <Module<T>>::total_issuance().checked_add(&value) {
|
||||
<TotalIssuance<T>>::put(v);
|
||||
}
|
||||
}
|
||||
/// Decrease TotalIssuance by Value.
|
||||
pub fn decrease_total_stake_by(value: T::Balance) {
|
||||
if let Some(v) = <Module<T>>::total_stake().checked_sub(&value) {
|
||||
if let Some(v) = <Module<T>>::total_issuance().checked_sub(&value) {
|
||||
<TotalIssuance<T>>::put(v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,9 +305,9 @@ impl<T: Trait> Module<T> {
|
||||
// tally up votes for any expiring referenda.
|
||||
for (index, _, proposal, vote_threshold) in Self::maturing_referendums_at(now) {
|
||||
let (approve, against) = Self::tally(index);
|
||||
let total_stake = <balances::Module<T>>::total_stake();
|
||||
let total_issuance = <balances::Module<T>>::total_issuance();
|
||||
Self::clear_referendum(index);
|
||||
if vote_threshold.approved(approve, against, total_stake) {
|
||||
if vote_threshold.approved(approve, against, total_issuance) {
|
||||
Self::deposit_event(RawEvent::Passed(index));
|
||||
let ok = proposal.dispatch(system::RawOrigin::Root.into()).is_ok();
|
||||
Self::deposit_event(RawEvent::Executed(index, ok));
|
||||
@@ -454,7 +454,7 @@ mod tests {
|
||||
assert_eq!(Democracy::minimum_deposit(), 1);
|
||||
assert_eq!(Democracy::referendum_count(), 0);
|
||||
assert_eq!(Balances::free_balance(&42), 0);
|
||||
assert_eq!(Balances::total_stake(), 210);
|
||||
assert_eq!(Balances::total_issuance(), 210);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -670,7 +670,7 @@ mod tests {
|
||||
fn passing_low_turnout_voting_should_work() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
assert_eq!(Balances::free_balance(&42), 0);
|
||||
assert_eq!(Balances::total_stake(), 210);
|
||||
assert_eq!(Balances::total_issuance(), 210);
|
||||
|
||||
System::set_block_number(1);
|
||||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap();
|
||||
|
||||
@@ -26,7 +26,7 @@ use primitives::traits::As;
|
||||
use substrate_primitives::KeccakHasher;
|
||||
use {runtime_io, primitives};
|
||||
use super::{Trait, Intentions, CurrentEra, OfflineSlashGrace, MinimumValidatorCount,
|
||||
BondingDuration, SessionsPerEra, ValidatorCount, SessionReward, EarlyEraSlash};
|
||||
BondingDuration, SessionsPerEra, ValidatorCount, SessionReward, OfflineSlash};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -39,7 +39,7 @@ pub struct GenesisConfig<T: Trait> {
|
||||
pub minimum_validator_count: u32,
|
||||
pub bonding_duration: T::BlockNumber,
|
||||
pub session_reward: T::Balance,
|
||||
pub early_era_slash: T::Balance,
|
||||
pub offline_slash: T::Balance,
|
||||
pub offline_slash_grace: u32,
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ impl<T: Trait> Default for GenesisConfig<T> {
|
||||
minimum_validator_count: 0,
|
||||
bonding_duration: T::BlockNumber::sa(1000),
|
||||
session_reward: T::Balance::sa(0),
|
||||
early_era_slash: T::Balance::sa(0),
|
||||
offline_slash: T::Balance::sa(0),
|
||||
offline_slash_grace: 0,
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ impl<T: Trait> primitives::BuildStorage for GenesisConfig<T> {
|
||||
Self::hash(<BondingDuration<T>>::key()).to_vec() => self.bonding_duration.encode(),
|
||||
Self::hash(<CurrentEra<T>>::key()).to_vec() => self.current_era.encode(),
|
||||
Self::hash(<SessionReward<T>>::key()).to_vec() => self.session_reward.encode(),
|
||||
Self::hash(<EarlyEraSlash<T>>::key()).to_vec() => self.early_era_slash.encode(),
|
||||
Self::hash(<OfflineSlash<T>>::key()).to_vec() => self.offline_slash.encode(),
|
||||
Self::hash(<OfflineSlashGrace<T>>::key()).to_vec() => self.offline_slash_grace.encode()
|
||||
];
|
||||
Ok(r.into())
|
||||
|
||||
@@ -51,7 +51,7 @@ use runtime_support::dispatch::Result;
|
||||
use session::OnSessionChange;
|
||||
use primitives::traits::{Zero, One, Bounded, OnFinalise,
|
||||
As, Lookup};
|
||||
use balances::{address::Address, OnMinted};
|
||||
use balances::{address::Address, OnDilution};
|
||||
use system::{ensure_root, ensure_signed};
|
||||
|
||||
mod mock;
|
||||
@@ -98,7 +98,7 @@ impl<B: Default> Default for ValidatorPrefs<B> {
|
||||
|
||||
pub trait Trait: balances::Trait + session::Trait {
|
||||
/// Some tokens minted.
|
||||
type OnRewardMinted: OnMinted<<Self as balances::Trait>::Balance>;
|
||||
type OnRewardMinted: OnDilution<<Self as balances::Trait>::Balance>;
|
||||
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
|
||||
@@ -137,6 +137,8 @@ impl<B, A> From<RawEvent<B, A>> for () {
|
||||
fn from(_: RawEvent<B, A>) -> () { () }
|
||||
}
|
||||
|
||||
pub type PairOf<T> = (T, T);
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as Staking {
|
||||
|
||||
@@ -148,8 +150,8 @@ decl_storage! {
|
||||
pub SessionsPerEra get(sessions_per_era): required T::BlockNumber;
|
||||
/// Maximum reward, per validator, that is provided per acceptable session.
|
||||
pub SessionReward get(session_reward): required T::Balance;
|
||||
/// Slash, per validator that is taken per abnormal era end.
|
||||
pub EarlyEraSlash get(early_era_slash): required T::Balance;
|
||||
/// Slash, per validator that is taken for the first time they are found to be offline.
|
||||
pub OfflineSlash get(offline_slash): required T::Balance;
|
||||
/// Number of instances of offline reports before slashing begins for validators.
|
||||
pub OfflineSlashGrace get(offline_slash_grace): default u32;
|
||||
/// The length of the bonding duration in blocks.
|
||||
@@ -172,8 +174,8 @@ decl_storage! {
|
||||
/// The session index at which the era length last changed.
|
||||
pub LastEraLengthChange get(last_era_length_change): default T::BlockNumber;
|
||||
|
||||
/// The current era stake threshold - unused at present. Consider for removal.
|
||||
pub StakeThreshold get(stake_threshold): required T::Balance;
|
||||
/// The highest and lowest staked validator slashable balances.
|
||||
pub StakeRange get(stake_range): default PairOf<T::Balance>;
|
||||
|
||||
/// The block at which the `who`'s funds become entirely liquid.
|
||||
pub Bondage get(bondage): default map [ T::AccountId => T::BlockNumber ];
|
||||
@@ -446,7 +448,9 @@ impl<T: Trait> Module<T> {
|
||||
Self::reward_validator(v, reward);
|
||||
}
|
||||
Self::deposit_event(RawEvent::Reward(reward));
|
||||
T::OnRewardMinted::on_minted(reward * <T::Balance as As<usize>>::sa(validators.len()));
|
||||
let total_minted = reward * <T::Balance as As<usize>>::sa(validators.len());
|
||||
let total_rewarded_stake = Self::stake_range().0 * <T::Balance as As<usize>>::sa(validators.len());
|
||||
T::OnRewardMinted::on_dilution(total_minted, total_rewarded_stake);
|
||||
}
|
||||
|
||||
let session_index = <session::Module<T>>::current_index();
|
||||
@@ -491,11 +495,13 @@ impl<T: Trait> Module<T> {
|
||||
|
||||
intentions.sort_unstable_by(|&(ref b1, _), &(ref b2, _)| b2.cmp(&b1));
|
||||
|
||||
<StakeThreshold<T>>::put(
|
||||
<StakeRange<T>>::put(
|
||||
if !intentions.is_empty() {
|
||||
let i = (<ValidatorCount<T>>::get() as usize).min(intentions.len() - 1);
|
||||
intentions[i].0.clone()
|
||||
} else { Zero::zero() }
|
||||
let n = <ValidatorCount<T>>::get() as usize;
|
||||
(intentions[0].0, intentions[n - 1].0)
|
||||
} else {
|
||||
(Zero::zero(), Zero::zero())
|
||||
}
|
||||
);
|
||||
let vals = &intentions.into_iter()
|
||||
.map(|(_, v)| v)
|
||||
@@ -551,7 +557,7 @@ impl<T: Trait> consensus::OnOfflineValidator for Module<T> {
|
||||
|
||||
let event = if slash_count >= grace {
|
||||
let instances = slash_count - grace;
|
||||
let slash = Self::early_era_slash() << instances;
|
||||
let slash = Self::offline_slash() << instances;
|
||||
let next_slash = slash << 1u32;
|
||||
let _ = Self::slash_validator(&v, slash);
|
||||
if instances >= Self::validator_preferences(&v).unstake_threshold
|
||||
|
||||
@@ -110,7 +110,7 @@ pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64
|
||||
minimum_validator_count: 0,
|
||||
bonding_duration: sessions_per_era * session_length * 3,
|
||||
session_reward: reward,
|
||||
early_era_slash: if monied { 20 } else { 0 },
|
||||
offline_slash: if monied { 20 } else { 0 },
|
||||
offline_slash_grace: 0,
|
||||
}.build_storage().unwrap());
|
||||
t.extend(timestamp::GenesisConfig::<Test>{
|
||||
|
||||
@@ -45,7 +45,7 @@ use rstd::prelude::*;
|
||||
use runtime_support::{StorageValue, StorageMap};
|
||||
use runtime_support::dispatch::Result;
|
||||
use runtime_primitives::{Permill, traits::{OnFinalise, Zero, EnsureOrigin}};
|
||||
use balances::OnMinted;
|
||||
use balances::OnDilution;
|
||||
use system::{ensure_signed, ensure_root};
|
||||
|
||||
/// Our module's configuration trait. All our types and consts go in here. If the
|
||||
@@ -278,9 +278,15 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> OnMinted<T::Balance> for Module<T> {
|
||||
fn on_minted(b: T::Balance) {
|
||||
<Pot<T>>::put(Self::pot() + b);
|
||||
impl<T: Trait> OnDilution<T::Balance> for Module<T> {
|
||||
fn on_dilution(minted: T::Balance, portion: T::Balance) {
|
||||
// Mint extra funds for the treasury to keep the ratio of portion to total_issuance equal
|
||||
// pre dilution and post-dilution.
|
||||
if !minted.is_zero() && !portion.is_zero() {
|
||||
let total_issuance = <balances::Module<T>>::total_issuance();
|
||||
let funding = (total_issuance - portion) / portion * minted;
|
||||
<Pot<T>>::mutate(|x| *x += funding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,7 +383,7 @@ mod tests {
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<KeccakHasher> {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(balances::GenesisConfig::<Test>{
|
||||
balances: vec![(0, 100), (1, 10), (2, 1)],
|
||||
balances: vec![(0, 100), (1, 99), (2, 1)],
|
||||
transaction_base_fee: 0,
|
||||
transaction_byte_fee: 0,
|
||||
transfer_fee: 0,
|
||||
@@ -410,7 +416,7 @@ mod tests {
|
||||
fn minting_works() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
// Check that accumulate works when we have Some value in Dummy already.
|
||||
Treasury::on_minted(100);
|
||||
Treasury::on_dilution(100, 100);
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
});
|
||||
}
|
||||
@@ -443,7 +449,7 @@ mod tests {
|
||||
#[test]
|
||||
fn accepted_spend_proposal_ignored_outside_spend_period() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_minted(100);
|
||||
Treasury::on_dilution(100, 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0));
|
||||
@@ -457,7 +463,7 @@ mod tests {
|
||||
#[test]
|
||||
fn unused_pot_should_diminish() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_minted(100);
|
||||
Treasury::on_dilution(100, 100);
|
||||
|
||||
<Treasury as OnFinalise<u64>>::on_finalise(2);
|
||||
assert_eq!(Treasury::pot(), 50);
|
||||
@@ -467,7 +473,7 @@ mod tests {
|
||||
#[test]
|
||||
fn rejected_spend_proposal_ignored_on_spend_period() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_minted(100);
|
||||
Treasury::on_dilution(100, 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0));
|
||||
@@ -481,7 +487,7 @@ mod tests {
|
||||
#[test]
|
||||
fn reject_already_rejected_spend_proposal_fails() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_minted(100);
|
||||
Treasury::on_dilution(100, 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0));
|
||||
@@ -506,7 +512,7 @@ mod tests {
|
||||
#[test]
|
||||
fn accept_already_rejected_spend_proposal_fails() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_minted(100);
|
||||
Treasury::on_dilution(100, 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(Origin::ROOT, 0));
|
||||
@@ -517,7 +523,7 @@ mod tests {
|
||||
#[test]
|
||||
fn accepted_spend_proposal_enacted_on_spend_period() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_minted(100);
|
||||
Treasury::on_dilution(100, 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0));
|
||||
@@ -531,7 +537,7 @@ mod tests {
|
||||
#[test]
|
||||
fn pot_underflow_should_not_diminish() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
Treasury::on_minted(100);
|
||||
Treasury::on_dilution(100, 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 150, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::ROOT, 0));
|
||||
@@ -539,7 +545,7 @@ mod tests {
|
||||
<Treasury as OnFinalise<u64>>::on_finalise(2);
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
|
||||
Treasury::on_minted(100);
|
||||
Treasury::on_dilution(100, 100);
|
||||
<Treasury as OnFinalise<u64>>::on_finalise(4);
|
||||
assert_eq!(Balances::free_balance(&3), 150);
|
||||
assert_eq!(Treasury::pot(), 25);
|
||||
|
||||
Reference in New Issue
Block a user