diff --git a/substrate/core/sr-primitives/src/traits.rs b/substrate/core/sr-primitives/src/traits.rs
index 3004a5e069..9e43ddc60f 100644
--- a/substrate/core/sr-primitives/src/traits.rs
+++ b/substrate/core/sr-primitives/src/traits.rs
@@ -150,35 +150,6 @@ impl Convert for () {
fn convert(_: A) -> B { Default::default() }
}
-/// A structure that converts the currency type into a lossy u64
-/// And back from u128
-pub struct CurrencyToVoteHandler;
-
-impl Convert for CurrencyToVoteHandler {
- fn convert(x: u128) -> u64 {
- if x >> 96 == 0 {
- // Remove dust; divide by 2^32
- (x >> 32) as u64
- } else {
- u64::max_value()
- }
- }
-}
-
-impl Convert for CurrencyToVoteHandler {
- fn convert(x: u128) -> u128 {
- // if it practically fits in u64
- if x >> 64 == 0 {
- // Add zero dust; multiply by 2^32
- x << 32
- }
- else {
- // 0000_0000_FFFF_FFFF_FFFF_FFFF_0000_0000
- (u64::max_value() << 32) as u128
- }
- }
-}
-
/// A structure that performs identity conversion.
pub struct Identity;
impl Convert for Identity {
diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs
index 340220160e..b765abd380 100644
--- a/substrate/node/runtime/src/lib.rs
+++ b/substrate/node/runtime/src/lib.rs
@@ -34,8 +34,7 @@ use client::{
use runtime_primitives::{ApplyResult, generic, create_runtime_str};
use runtime_primitives::transaction_validity::TransactionValidity;
use runtime_primitives::traits::{
- BlakeTwo256, Block as BlockT, DigestFor, NumberFor, StaticLookup, CurrencyToVoteHandler,
- AuthorityIdFor,
+ BlakeTwo256, Block as BlockT, DigestFor, NumberFor, StaticLookup, AuthorityIdFor, Convert
};
use version::RuntimeVersion;
use council::{motions as council_motions, voting as council_voting};
@@ -59,8 +58,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node"),
impl_name: create_runtime_str!("substrate-node"),
authoring_version: 10,
- spec_version: 65,
- impl_version: 65,
+ spec_version: 66,
+ impl_version: 66,
apis: RUNTIME_API_VERSIONS,
};
@@ -73,6 +72,20 @@ pub fn native_version() -> NativeVersion {
}
}
+pub struct CurrencyToVoteHandler;
+
+impl CurrencyToVoteHandler {
+ fn factor() -> u128 { (Balances::total_issuance() / u64::max_value() as u128).max(1) }
+}
+
+impl Convert for CurrencyToVoteHandler {
+ fn convert(x: u128) -> u64 { (x / Self::factor()) as u64 }
+}
+
+impl Convert for CurrencyToVoteHandler {
+ fn convert(x: u128) -> u128 { x * Self::factor() }
+}
+
impl system::Trait for Runtime {
type Origin = Origin;
type Index = Index;