diff --git a/Cargo.lock b/Cargo.lock index 0542082f97..70904428ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4009,7 +4009,7 @@ checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" [[package]] name = "polymesh" -version = "2.0.0" +version = "2.0.9" dependencies = [ "chrono", "ctrlc", diff --git a/Cargo.toml b/Cargo.toml index f1ab0f0724..f288b45b9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polymesh" -version = "2.0.0" +version = "2.0.9" authors = ["Anonymous"] build = "build.rs" edition = "2018" diff --git a/pallets/pips/src/lib.rs b/pallets/pips/src/lib.rs index 942c5e875e..4c340d3a7a 100644 --- a/pallets/pips/src/lib.rs +++ b/pallets/pips/src/lib.rs @@ -71,7 +71,7 @@ use frame_support::{ weights::SimpleDispatchInfo, Parameter, }; -use frame_system::{self as system, ensure_signed}; +use frame_system::{self as system, ensure_root, ensure_signed}; use pallet_identity as identity; use pallet_treasury::TreasuryTrait; use polymesh_common_utilities::{ @@ -470,6 +470,35 @@ decl_module! { fn deposit_event() = default; + #[weight = SimpleDispatchInfo::FixedOperational(100_000)] + fn update_vote_tally(origin) { + ensure_root(origin)?; + let last_pip_id = ::get(); + // Iterate over all pips + for pip_id in 0..=last_pip_id { + // Skip pruned pips + if >::contains_key(pip_id) { + // Recalculate result + let mut stats = VotingResult::default(); + for vote in >::iter_prefix(pip_id) { + match vote { + Vote::None => {}, + Vote::Yes(deposit) => { + stats.ayes_count += 1; + stats.ayes_stake += deposit; + } + Vote::No(deposit) => { + stats.nays_count += 1; + stats.nays_stake += deposit; + } + } + } + // Update result + >::insert(pip_id, stats); + } + } + } + /// Change whether completed PIPs are pruned. Can only be called by governance council /// /// # Arguments @@ -1351,11 +1380,11 @@ impl Module { .ok_or_else(|| Error::::StakeAmountOfVotesExceeded)?; } Vote::No(deposit) => { - stats.nays_count += stats + stats.nays_count = stats .nays_count .checked_add(1) .ok_or_else(|| Error::::NumberOfVotesExceeded)?; - stats.nays_stake += stats + stats.nays_stake = stats .nays_stake .checked_add(&deposit) .ok_or_else(|| Error::::StakeAmountOfVotesExceeded)?; diff --git a/pallets/runtime/develop/src/runtime.rs b/pallets/runtime/develop/src/runtime.rs index 763fe51c04..ea4b63be5f 100644 --- a/pallets/runtime/develop/src/runtime.rs +++ b/pallets/runtime/develop/src/runtime.rs @@ -95,8 +95,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("polymesh"), impl_name: create_runtime_str!("polymath-polymesh"), authoring_version: 1, - spec_version: 1008, - impl_version: 1008, + spec_version: 1009, + impl_version: 1009, apis: RUNTIME_API_VERSIONS, }; diff --git a/pallets/runtime/testnet-v1/src/runtime.rs b/pallets/runtime/testnet-v1/src/runtime.rs index 5cff976463..8177aef565 100644 --- a/pallets/runtime/testnet-v1/src/runtime.rs +++ b/pallets/runtime/testnet-v1/src/runtime.rs @@ -86,8 +86,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("polymesh"), impl_name: create_runtime_str!("polymath-polymesh"), authoring_version: 1, - spec_version: 1008, - impl_version: 1008, + spec_version: 1009, + impl_version: 1009, apis: RUNTIME_API_VERSIONS, };