From e8a8f90dff968e30102c42e07524b94379ff276d Mon Sep 17 00:00:00 2001 From: ndkazu Date: Sat, 11 Jan 2025 21:13:44 +0900 Subject: [PATCH] Vote extrinsic --- substrate/frame/opf/src/functions.rs | 11 +++++++++++ substrate/frame/opf/src/lib.rs | 5 +++-- substrate/frame/opf/src/types.rs | 13 ++++++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/substrate/frame/opf/src/functions.rs b/substrate/frame/opf/src/functions.rs index dccb2abc753c..b32cc978aa9f 100644 --- a/substrate/frame/opf/src/functions.rs +++ b/substrate/frame/opf/src/functions.rs @@ -127,6 +127,17 @@ impl Pallet { T::PotId::get().into_account_truncating() } + pub fn convert_balance(amount: BalanceOf) -> Option> { + let value = match TryInto::::try_into(amount) { + Ok(val) => { + TryInto::>::try_into(val).ok() + }, + Err(e) => None + }; + + value + + } /// Funds transfer from the Pot to a project account pub fn spend(amount: BalanceOf, beneficiary: AccountIdOf) -> DispatchResult { // Get Pot account diff --git a/substrate/frame/opf/src/lib.rs b/substrate/frame/opf/src/lib.rs index 69f6d40f6013..e1fcfd4301f5 100644 --- a/substrate/frame/opf/src/lib.rs +++ b/substrate/frame/opf/src/lib.rs @@ -387,9 +387,10 @@ pub mod pallet { .ok_or(Error::::NoProjectAvailable)?; let ref_index = infos.index; let vote = Democracy::Vote { aye: is_fund, conviction }; - // let account_vote = Democracy::AccountVote::Standard { vote, balance: amount }; + let converted_amount = Self::convert_balance(amount).ok_or("Failed Conversion!!!")?; + let account_vote = Democracy::AccountVote::Standard { vote, balance: converted_amount }; - // Democracy::Pallet::::vote(origin, ref_index, account_vote)?; + Democracy::Pallet::::vote(origin, ref_index, account_vote)?; Ok(()) } diff --git a/substrate/frame/opf/src/types.rs b/substrate/frame/opf/src/types.rs index 906288f48e42..bc53b66ba21e 100644 --- a/substrate/frame/opf/src/types.rs +++ b/substrate/frame/opf/src/types.rs @@ -23,7 +23,7 @@ pub use frame_support::{ dispatch::GetDispatchInfo, pallet_prelude::*, traits::{ - fungible, + fungible, Currency, fungible::{Inspect, InspectHold, Mutate, MutateHold}, fungibles, schedule::{ @@ -35,7 +35,7 @@ pub use frame_support::{ StorePreimage, UnfilteredDispatchable, }, transactional, - weights::WeightMeter, + weights::{WeightMeter, WeightToFee}, PalletId, Serialize, }; pub use frame_system::{pallet_prelude::*, RawOrigin}; @@ -45,13 +45,16 @@ pub use sp_runtime::{ AccountIdConversion, BlockNumberProvider, Convert, Dispatchable, Saturating, StaticLookup, Zero, }, - Percent, + Percent, SaturatedConversion, }; pub use sp_std::boxed::Box; pub type BalanceOf = <::NativeBalance as fungible::Inspect< ::AccountId, >>::Balance; + +pub type BalanceOfD = <::Currency as Currency<::AccountId>>::Balance; + pub type AccountIdOf = ::AccountId; /// A reward index. pub type SpendIndex = u32; @@ -223,3 +226,7 @@ impl VotingRoundInfo { round_infos } } + + + +