|
@@ -6,7 +6,7 @@ use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
|
|
|
use sp_api::impl_runtime_apis;
|
|
|
use sp_core::crypto::KeyTypeId;
|
|
|
use sp_core::OpaqueMetadata;
|
|
|
-use sp_runtime::traits::{BlakeTwo256, Block as BlockT, NumberFor};
|
|
|
+use sp_runtime::traits::{BlakeTwo256, Block as BlockT, Convert, NumberFor};
|
|
|
use sp_runtime::{generic, ApplyExtrinsicResult};
|
|
|
use sp_std::vec::Vec;
|
|
|
|
|
@@ -16,10 +16,32 @@ use crate::{
|
|
|
GrandpaId, Hash, Index, RuntimeVersion, Signature, VERSION,
|
|
|
};
|
|
|
use crate::{
|
|
|
- AllModules, AuthorityDiscovery, Babe, Call, Grandpa, Historical, InherentDataExt,
|
|
|
+ AllModules, AuthorityDiscovery, Babe, Balances, Call, Grandpa, Historical, InherentDataExt,
|
|
|
RandomnessCollectiveFlip, Runtime, SessionKeys, System, TransactionPayment,
|
|
|
};
|
|
|
|
|
|
+/// Struct that handles the conversion of Balance -> `u64`. This is used for staking's election
|
|
|
+/// calculation.
|
|
|
+pub struct CurrencyToVoteHandler;
|
|
|
+
|
|
|
+impl CurrencyToVoteHandler {
|
|
|
+ fn factor() -> Balance {
|
|
|
+ (Balances::total_issuance() / u64::max_value() as Balance).max(1)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl Convert<Balance, u64> for CurrencyToVoteHandler {
|
|
|
+ fn convert(x: Balance) -> u64 {
|
|
|
+ (x / Self::factor()) as u64
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl Convert<u128, Balance> for CurrencyToVoteHandler {
|
|
|
+ fn convert(x: u128) -> Balance {
|
|
|
+ x * Self::factor()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/// The SignedExtension to the basic transaction logic.
|
|
|
pub type SignedExtra = (
|
|
|
frame_system::CheckSpecVersion<Runtime>,
|