From b4436858cb08eaf02dd19caf28830f2c2ddfa31e Mon Sep 17 00:00:00 2001 From: Shankar Rao Mata Date: Thu, 17 Aug 2023 23:22:59 -0400 Subject: [PATCH] compilation fix for the accountid --- pallets/disputes/src/lib.rs | 281 ++++++++++++++++----------------- pallets/disputes/src/traits.rs | 9 +- 2 files changed, 143 insertions(+), 147 deletions(-) diff --git a/pallets/disputes/src/lib.rs b/pallets/disputes/src/lib.rs index 115c75d1..373fee42 100644 --- a/pallets/disputes/src/lib.rs +++ b/pallets/disputes/src/lib.rs @@ -3,155 +3,148 @@ pub use pallet::*; pub mod traits; pub mod weights; +use sp_runtime::{traits::AtLeast32BitUnsigned, DispatchError}; pub use weights::*; -use sp_runtime::{DispatchError, traits::AtLeast32BitUnsigned}; #[frame_support::pallet] pub mod pallet { - use super::*; - use codec::{FullEncode, FullCodec}; -use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; - use traits::DisputeRaiser; - - #[pallet::pallet] - pub struct Pallet(_); - - pub(crate) type AccountIdOf = ::AccountId; - - #[pallet::config] - pub trait Config: frame_system::Config { - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type WeightInfo: WeightInfo; - //Felix teachings --> to keep an associated type into storage it needs to implement certain traits - type DisputeKey: AtLeast32BitUnsigned + FullEncode + FullCodec + MaxEncodedLen + TypeInfo; - type MaxReasonLength: Get; - type MaxJurySize: Get; - type DisputeHooks: traits::DisputeHooks; - type TimeLimit: Get<::BlockNumber>; - } - - #[pallet::storage] - #[pallet::getter(fn disputes)] + use super::*; + use codec::{FullCodec, FullEncode}; + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + use traits::DisputeRaiser; + + #[pallet::pallet] + pub struct Pallet(_); + + pub(crate) type AccountIdOf = ::AccountId; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type WeightInfo: WeightInfo; + //Felix teachings --> to keep an associated type into storage it needs to implement certain traits + type DisputeKey: AtLeast32BitUnsigned + FullEncode + FullCodec + MaxEncodedLen + TypeInfo; + type MaxReasonLength: Get; + type MaxJurySize: Get; + type DisputeHooks: traits::DisputeHooks; + type TimeLimit: Get<::BlockNumber>; + } + + #[pallet::storage] + #[pallet::getter(fn disputes)] pub type Disputes = StorageMap<_, Blake2_128Concat, T::DisputeKey, Dispute, OptionQuery>; - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - //This event is emitted when a dispute is being raised - DisputeRaised {who: AccountIdOf}, - //This event is emitted from the vote_on_dispute extrinsics - //to notify what dispute is being voted on - DisputeVotedOn {who: AccountIdOf}, - } - - #[pallet::error] - pub enum Error { - NoneValue, - StorageOverflow, - //This error is thrown whenever the dispute key passed doesn't correspond to any dispute - DisputeDoesNotExist, - DisputeAlreadyExists, - } - - - #[pallet::call] - impl Pallet { - #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::do_something())] - pub fn vote_on_dispute( - origin: OriginFor, - dispute_key: T::DisputeKey, - is_yay: bool, - ) -> DispatchResult { - // get dispute struct - // ensure caller is part of the jury - // mutate vote accordingly. - //TODO only the choosen jury can vote on the disputes? - let mut dispute = Disputes::::get(dispute_key).ok_or(Error::::DisputeDoesNotExist)?; - let mut vote = dispute.votes; - if is_yay{ - vote.yay +=1; - } - else { - vote.nay +=1; - } - - - //TODO will update the mutated votes into the dispute correct? - //TODO If the votes met the threshold we need to call the refund pallet correct? - - Ok(().into()) - } - - #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::do_something())] - pub fn force_cancel_dispute( - origin: OriginFor, - dispute_key: T::DisputeKey, - is_yay: bool, - ) -> DispatchResult { - - Ok(().into()) - } - } - - impl DisputeRaiser> for Pallet { - type DisputeKey = T::DisputeKey; - - fn raise_dispute( - dispute_key: Self::DisputeKey, - raised_by: AccountIdOf, - fund_account: AccountIdOf, - reason: Vec, - project_id: u32, - jury: Vec>, - ) -> Result<(), DispatchError> { - // creating the struct with the passed information and initializing vote as 0 initially - let dispute:Dispute = Dispute{ - raised_by, - fund_account, - votes: Vote{ - yay: 0, - nay: 0, - }, - reason, - jury, - }; - - ensure!(!Disputes::::contains_key(dispute_key), Error::::DisputeAlreadyExists); - - //storing the raised dispute inside the disputes storage - Disputes::::insert(dispute_key, dispute); - - // Raise Event - //TODO need to check if want to add more information while raising a dispute like returning the whole dispute struct? - Self::deposit_event(Event::DisputeRaised( - raised_by - )); - - Ok(()) - } - } - - #[derive(Encode, Decode, PartialEq, Eq, Clone, Debug, TypeInfo, MaxEncodedLen)] - #[scale_info(skip_type_params(T))] - struct Dispute { - raised_by: AccountIdOf, - fund_account: AccountIdOf, - // TODO: Add balance type - // currencyid: CurrencyId - //fund_amount: BalanceOf - votes: Vote, - reason: BoundedVec::MaxReasonLength>, - jury: BoundedVec, ::MaxJurySize> - } - - #[derive(Encode, Decode, PartialEq, Eq, Clone, Debug, TypeInfo, MaxEncodedLen)] - pub struct Vote { - yay: u32 , - nay: u32, + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + //This event is emitted when a dispute is being raised + DisputeRaised { who: AccountIdOf }, + //This event is emitted from the vote_on_dispute extrinsics + //to notify what dispute is being voted on + DisputeVotedOn { who: AccountIdOf }, + } + + #[pallet::error] + pub enum Error { + NoneValue, + StorageOverflow, + //This error is thrown whenever the dispute key passed doesn't correspond to any dispute + DisputeDoesNotExist, + DisputeAlreadyExists, + } + + #[pallet::call] + impl Pallet { + #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::do_something())] + pub fn vote_on_dispute( + origin: OriginFor, + dispute_key: T::DisputeKey, + is_yay: bool, + ) -> DispatchResult { + // get dispute struct + // ensure caller is part of the jury + // mutate vote accordingly. + //TODO only the choosen jury can vote on the disputes? + let mut dispute = + Disputes::::get(dispute_key).ok_or(Error::::DisputeDoesNotExist)?; + let mut vote = dispute.votes; + if is_yay { + vote.yay += 1; + } else { + vote.nay += 1; + } + + //TODO will update the mutated votes into the dispute correct? + //TODO If the votes met the threshold we need to call the refund pallet correct? + + Ok(().into()) + } + + #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::do_something())] + pub fn force_cancel_dispute( + origin: OriginFor, + dispute_key: T::DisputeKey, + is_yay: bool, + ) -> DispatchResult { + Ok(().into()) + } + } + + impl DisputeRaiser> for Pallet { + type DisputeKey = T::DisputeKey; + + fn raise_dispute( + dispute_key: Self::DisputeKey, + raised_by: AccountIdOf, + fund_account: AccountIdOf, + reason: Vec, + project_id: u32, + jury: Vec>, + ) -> Result<(), DispatchError> { + // creating the struct with the passed information and initializing vote as 0 initially + let dispute: Dispute = Dispute { + raised_by, + fund_account, + votes: Vote { yay: 0, nay: 0 }, + reason, + jury, + }; + + ensure!( + !Disputes::::contains_key(dispute_key), + Error::::DisputeAlreadyExists + ); + //storing the raised dispute inside the disputes storage + Disputes::::insert(dispute_key, dispute); + + // Raise Event + //TODO need to check if want to add more information while raising a dispute like returning the whole dispute struct? + Self::deposit_event(Event::DisputeRaised(raised_by)); + + Ok(()) + } + } + + #[derive(Encode, Decode, PartialEq, Eq, Clone, Debug, TypeInfo, MaxEncodedLen)] + #[scale_info(skip_type_params(T))] + struct Dispute { + raised_by: AccountIdOf, + fund_account: AccountIdOf, + // TODO: Add balance type + // currencyid: CurrencyId + //fund_amount: BalanceOf + votes: Vote, + reason: BoundedVec::MaxReasonLength>, + jury: BoundedVec, ::MaxJurySize>, + } + + #[derive(Encode, Decode, PartialEq, Eq, Clone, Debug, TypeInfo, MaxEncodedLen)] + pub struct Vote { + yay: u32, + nay: u32, + } } - -} \ No newline at end of file diff --git a/pallets/disputes/src/traits.rs b/pallets/disputes/src/traits.rs index 7199e4cf..c7e6638c 100644 --- a/pallets/disputes/src/traits.rs +++ b/pallets/disputes/src/traits.rs @@ -1,5 +1,8 @@ +use codec::{FullEncode, FullCodec, MaxEncodedLen}; +use scale_info::TypeInfo; use sp_runtime::{DispatchError, traits::AtLeast32BitUnsigned}; + pub trait DisputeRaiser { type DisputeKey: AtLeast32BitUnsigned + FullEncode + FullCodec + MaxEncodedLen + TypeInfo; @@ -9,11 +12,11 @@ pub trait DisputeRaiser { // Bind the string to a constant amount (500) fn raise_dispute( dispute_key: Self::DisputeKey, - raised_by: AccountIdOf, - fund_account: AccountIdOf, + raised_by: AccountId, + fund_account: AccountId, reason: Vec, project_id: u32, - jury: Vec>, + jury: Vec, ) -> Result<(), DispatchError>; }