diff --git a/pallets/council/src/functions.rs b/pallets/council/src/functions.rs index b373cb2a..4c7e6351 100644 --- a/pallets/council/src/functions.rs +++ b/pallets/council/src/functions.rs @@ -67,7 +67,7 @@ impl Pallet { for proposal_hash in proposal_hashes{ let prop0 = Coll::Pallet::::proposal_of(proposal_hash.clone()).unwrap(); if proposal == prop0{ - let mut proposal_all = ProposalOf::::new(account.clone(), Some(Roles::Accounts::None),proposal_hash.clone()); + let mut proposal_all = ProposalOf::::new(account.clone(), Some(Roles::Accounts::NONE),proposal_hash.clone()); proposal_all.proposal_index = index; proposal_all.proposal_hash = proposal_hash; SellerProposal::::insert(&account, proposal_all); diff --git a/pallets/council/src/lib.rs b/pallets/council/src/lib.rs index ab88e650..53d76bfe 100644 --- a/pallets/council/src/lib.rs +++ b/pallets/council/src/lib.rs @@ -103,6 +103,13 @@ pub mod pallet { ProposalDoesNotExist, } + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_initialize(n: BlockNumberFor) -> Weight { + Self::begin_block(n) + } + } + #[pallet::call] impl Pallet { diff --git a/pallets/onboarding/src/functions.rs b/pallets/onboarding/src/functions.rs index bf7974d9..827442a2 100644 --- a/pallets/onboarding/src/functions.rs +++ b/pallets/onboarding/src/functions.rs @@ -127,6 +127,14 @@ impl Pallet { ::Preimages::bound(call).unwrap() } + pub fn add_proposal(who:T::AccountId,call: CallOf) -> DispatchResult { + + let value = ::MinimumDeposit::get(); + let proposal = Self::make_proposal(call); + DEM::Pallet::::propose(RawOrigin::Signed(who).into(), proposal.clone(), value)?; + Ok(()) + } + pub fn start_dem_referendum(proposal:BoundedCallOf ,delay:BlockNumberFor) -> DEM::ReferendumIndex{ let threshold = DEM::VoteThreshold::SimpleMajority; let referendum_index = @@ -222,7 +230,6 @@ impl Pallet { let coll_id = asset.0; let item_id = asset.1; let status = asset.2.status; - let index = asset.2.ref_index; let items = Roles::Asset::::iter(); //Start awaiting referendums @@ -231,22 +238,17 @@ impl Pallet { //start Democracy referendum //Send Proposal struct to voting pallet //get the needed call and convert them to pallet_voting format - let out_call = Vcalls::::get(coll_id, item_id).unwrap(); - let call0 = Self::get_formatted_call(out_call.after_vote_status) ; - let proposal = Self::make_proposal(call0.into()); - let delay = T::Delay::get(); - let index=Self::start_dem_referendum(proposal,delay); - Houses::::mutate_exists(coll_id,item_id,|val|{ - let mut v0 = val.clone().unwrap(); - v0.ref_index=index; - v0.status=Status::VOTING; - *val = Some(v0); - }); - } - } - + let owner_origin= RawOrigin::Signed(item.0); + Self::investor_referendum(owner_origin.into(),coll_id, item_id).ok(); + let asset0 = Self::houses(coll_id,item_id).unwrap(); + let index0 = asset0.ref_index; + //Event referendum started + Self::deposit_event(Event::ReferendumStarted{ + index:index0 + }); + //Use index to get referendum infos - let infos = DEM::Pallet::::referendum_info(index).unwrap(); + let infos = DEM::Pallet::::referendum_info(index0).unwrap(); let b = match infos { DEM::ReferendumInfo::Finished { approved, end: _ } => { (1, approved) @@ -262,6 +264,11 @@ impl Pallet { Call::::reject_edit { collection:coll, item_id, infos: asset.2.clone() }.into(); call2.dispatch_bypass_filter(frame_system::RawOrigin::Root.into()).ok();} } + + } + } + + } diff --git a/pallets/onboarding/src/lib.rs b/pallets/onboarding/src/lib.rs index d71a96b3..9e569ce1 100644 --- a/pallets/onboarding/src/lib.rs +++ b/pallets/onboarding/src/lib.rs @@ -160,20 +160,6 @@ pub mod pallet { OptionQuery, >; - #[pallet::storage] - #[pallet::getter(fn voting_calls)] - /// Stores Calls - pub(super) type Vcalls = StorageDoubleMap< - _, - Blake2_128Concat, - T::NftCollectionId, - Blake2_128Concat, - T::NftItemId, - VotingCalls, - OptionQuery, - >; - - // Test Genesis Configuration #[derive(frame_support::DefaultNoBound)] #[pallet::genesis_config] @@ -248,6 +234,9 @@ pub struct GenesisConfig { collection: T::NftCollectionId, item: T::NftItemId, }, + ReferendumStarted{ + index:u32 + } } // Errors inform users that something went wrong. @@ -283,6 +272,15 @@ pub struct GenesisConfig { ReservedToInvestors, /// Failed to unreserved fund in Housing fund HousingFundUnreserveFundFailed, + ///ReferendumFailed + FailedReferendum, + } + + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_initialize(n: BlockNumberOf) -> Weight { + Self::begin_block(n) + } } // Dispatchable functions allows users to interact with the pallet and invoke state changes. @@ -500,20 +498,6 @@ pub struct GenesisConfig { let collection_id: T::NftCollectionId = collection.clone().value().into(); - let house = Self::houses(collection_id, item_id).unwrap(); - - let _new_call = VotingCalls::::new(collection_id, item_id).ok(); - - - //Create Call for asset status change after Investor's vote - let call4 = - Call::::change_status { collection, item_id, status: Status::ONBOARDED }; - Vcalls::::mutate(collection_id, item_id, |val| { - let mut v0 = val.clone().unwrap(); - v0.after_vote_status = call4.clone().into(); - *val = Some(v0); - }); - Self::deposit_event(Event::ProposalCreated { who: caller.clone(), collection: collection_id, @@ -605,6 +589,25 @@ pub struct GenesisConfig { DEM::Pallet::::vote(origin,index,config).ok(); Ok(()) + } + + #[pallet::call_index(8)] + #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1).ref_time())] + pub fn investor_referendum(origin: OriginFor,coll_id:T::NftCollectionId,item_id: T::NftItemId )-> DispatchResult { + let _who = ensure_signed(origin.clone())?; + let out_call = Call::::change_status { collection:Self::collection_name(coll_id.into()), item_id, status: Status::ONBOARDED }; + let call0 = Self::get_formatted_call(out_call) ; + let proposal = Self::make_proposal(call0.into()); + let delay = T::Delay::get(); + let index=Self::start_dem_referendum(proposal,delay); + Houses::::mutate_exists(coll_id,item_id,|val|{ + let mut v0 = val.clone().unwrap(); + v0.ref_index=index; + v0.status=Status::VOTING; + *val = Some(v0); + }); + Ok(()) + } } diff --git a/pallets/onboarding/src/types.rs b/pallets/onboarding/src/types.rs index d857adf7..fbd79578 100644 --- a/pallets/onboarding/src/types.rs +++ b/pallets/onboarding/src/types.rs @@ -102,18 +102,3 @@ pub struct VotingCalls { pub(super) after_vote_status: Call, } -impl VotingCalls { - pub fn new(collection: T::NftCollectionId, item: T::NftItemId) -> DispatchResult { - let nbr: u32 = 0; - let call:Call = Call::::do_something { something: nbr }.into(); - - let calls = VotingCalls:: { - reject_edit: call.clone(), - reject_destroy: call.clone(), - democracy_status: call.clone(), - after_vote_status: call, - }; - Vcalls::::insert(collection, item, calls); - Ok(()) - } -} \ No newline at end of file diff --git a/pallets/roles/src/functions.rs b/pallets/roles/src/functions.rs index 267ab299..eeed72b7 100644 --- a/pallets/roles/src/functions.rs +++ b/pallets/roles/src/functions.rs @@ -221,6 +221,7 @@ impl Pallet { proposal_len, ).ok(); let mut index:u32 = Coll::Pallet::::proposal_count(); + debug_assert!(index>0); index = index.saturating_sub(1); //Update proposal index and hash diff --git a/pallets/roles/src/lib.rs b/pallets/roles/src/lib.rs index e6078d57..c9aaff35 100644 --- a/pallets/roles/src/lib.rs +++ b/pallets/roles/src/lib.rs @@ -428,12 +428,12 @@ pub mod pallet { .map_err(|_:Error| >::InitializationError)?; Self::deposit_event(Event::CreationRequestCreated(now, account.clone())); }, - Accounts::None => {Self::deposit_event(Event::NoCreationRequestCreated(now, account.clone()));} + Accounts::NONE => {Self::deposit_event(Event::NoCreationRequestCreated(now, account.clone()));} } let need_approval = !matches!( account_type, - Accounts::INVESTOR | Accounts::TENANT | Accounts::REPRESENTATIVE | Accounts::None + Accounts::INVESTOR | Accounts::TENANT | Accounts::REPRESENTATIVE | Accounts::NONE ); if need_approval { Self::start_council_session(account.clone(),account_type).ok(); diff --git a/pallets/roles/src/tests.rs b/pallets/roles/src/tests.rs index 45f8ee87..989d02ff 100644 --- a/pallets/roles/src/tests.rs +++ b/pallets/roles/src/tests.rs @@ -36,9 +36,12 @@ fn setting_roles(){ assert_eq!(RolesModule::get_pending_house_sellers().len(),1); let account =RolesModule::get_pending_house_sellers()[0].account_id.clone(); assert_eq!(account,BOB); + + //Check that collective referendum started + //assert_eq!(Collective::proposal_count(),1); - /*assert_eq!(RolesModule::get_pending_house_sellers().len(), 1); + /* assert_ok!(RolesModule::council_vote(RuntimeOrigin::signed(council[0].clone()),BOB,true)); assert_ok!(RolesModule::council_vote(RuntimeOrigin::signed(council[1].clone()),BOB,true)); diff --git a/pallets/roles/src/types.rs b/pallets/roles/src/types.rs index d5a9dcfb..7486d301 100644 --- a/pallets/roles/src/types.rs +++ b/pallets/roles/src/types.rs @@ -52,7 +52,7 @@ pub enum Accounts { SERVICER, NOTARY, REPRESENTATIVE, - None, + NONE, } #[derive(Clone,Copy, Encode, Decode, Default, PartialEq, Eq, TypeInfo, MaxEncodedLen)]