Skip to content

Commit

Permalink
Vote extrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Jan 11, 2025
1 parent 6bc36f0 commit e8a8f90
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
11 changes: 11 additions & 0 deletions substrate/frame/opf/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ impl<T: Config> Pallet<T> {
T::PotId::get().into_account_truncating()
}

pub fn convert_balance(amount: BalanceOf<T>) -> Option<BalanceOfD<T>> {
let value = match TryInto::<u128>::try_into(amount) {
Ok(val) => {
TryInto::<BalanceOfD<T>>::try_into(val).ok()
},
Err(e) => None
};

value

}
/// Funds transfer from the Pot to a project account
pub fn spend(amount: BalanceOf<T>, beneficiary: AccountIdOf<T>) -> DispatchResult {
// Get Pot account
Expand Down
5 changes: 3 additions & 2 deletions substrate/frame/opf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,10 @@ pub mod pallet {
.ok_or(Error::<T>::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::<T>::vote(origin, ref_index, account_vote)?;
Democracy::Pallet::<T>::vote(origin, ref_index, account_vote)?;

Ok(())
}
Expand Down
13 changes: 10 additions & 3 deletions substrate/frame/opf/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub use frame_support::{
dispatch::GetDispatchInfo,
pallet_prelude::*,
traits::{
fungible,
fungible, Currency,
fungible::{Inspect, InspectHold, Mutate, MutateHold},
fungibles,
schedule::{
Expand All @@ -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};
Expand All @@ -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<T> = <<T as Config>::NativeBalance as fungible::Inspect<
<T as frame_system::Config>::AccountId,
>>::Balance;

pub type BalanceOfD<T> = <<T as Democracy::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
/// A reward index.
pub type SpendIndex = u32;
Expand Down Expand Up @@ -223,3 +226,7 @@ impl<T: Config> VotingRoundInfo<T> {
round_infos
}
}




0 comments on commit e8a8f90

Please sign in to comment.