mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Use balances::TotalIssuance for scaling between votes and balances (#… (#2364)
* Use balances::TotalIssuance for scaling between votes and balances (#2361) * Use total issuance to convert between votes and balances * Remove cruft * Bump runtime version
This commit is contained in:
@@ -150,35 +150,6 @@ impl<A, B: Default> Convert<A, B> 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<u128, u64> 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<u128, u128> 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<T> Convert<T, T> for Identity {
|
||||
|
||||
@@ -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<u128, u64> for CurrencyToVoteHandler {
|
||||
fn convert(x: u128) -> u64 { (x / Self::factor()) as u64 }
|
||||
}
|
||||
|
||||
impl Convert<u128, u128> for CurrencyToVoteHandler {
|
||||
fn convert(x: u128) -> u128 { x * Self::factor() }
|
||||
}
|
||||
|
||||
impl system::Trait for Runtime {
|
||||
type Origin = Origin;
|
||||
type Index = Index;
|
||||
|
||||
Reference in New Issue
Block a user