Skip to content

Commit 396e532

Browse files
committed
Delete all flow related to budgets (not expenditures budgets) it was a feature from EOSIO but it is no longer needed
1 parent d9a9328 commit 396e532

File tree

4 files changed

+23
-150
lines changed

4 files changed

+23
-150
lines changed

pallets/proxy-financial/src/functions.rs

Lines changed: 9 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,11 @@ impl<T: Config> Pallet<T> {
569569
ensure!(!<ExpendituresInfo<T>>::contains_key(expenditure_id), Error::<T>::ExpenditureAlreadyExists);
570570
<ExpendituresInfo<T>>::insert(expenditure_id, expenditure_data);
571571

572-
// Create a budget for the expenditure
573-
Self::do_create_budget(expenditure_id, 0, project_id)?;
572+
//Insert expenditure_id into ExpendituresByProject
573+
<ExpendituresByProject<T>>::try_mutate::<_,_,DispatchError,_>(project_id, |expenditures| {
574+
expenditures.try_push(expenditure_id).map_err(|_| Error::<T>::MaxExpendituresPerProjectReached)?;
575+
Ok(())
576+
})?;
574577
}
575578

576579
Self::deposit_event(Event::ExpenditureCreated);
@@ -651,133 +654,16 @@ impl<T: Config> Pallet<T> {
651654
// Delete expenditure data
652655
<ExpendituresInfo<T>>::remove(expenditure_id);
653656

654-
// Delete expenditure budget
655-
Self::do_delete_budget(project_id, expenditure_id)?;
656-
657-
Self::deposit_event(Event::ExpenditureDeleted(expenditure_id));
658-
Ok(())
659-
}
660-
661-
662-
663-
// B U D G E T S
664-
// --------------------------------------------------------------------------------------------
665-
// Buget functions are not exposed to the public. They are only used internally by the module.
666-
fn do_create_budget(
667-
expenditure_id: [u8;32],
668-
amount: u64,
669-
project_id: [u8;32],
670-
) -> DispatchResult {
671-
// Ensure expenditure_id exists
672-
ensure!(<ExpendituresInfo<T>>::contains_key(expenditure_id), Error::<T>::ExpenditureNotFound);
673-
674-
// Get timestamp
675-
let timestamp = Self::get_timestamp_in_milliseconds().ok_or(Error::<T>::TimestampError)?;
676-
677-
// Create budget id
678-
let budget_id = (expenditure_id, timestamp).using_encoded(blake2_256);
679-
680-
//TOREVIEW: Check if project_id exists.
681-
682-
// Create budget data
683-
let budget_data = BudgetData {
684-
expenditure_id,
685-
balance: amount,
686-
created_date: timestamp,
687-
updated_date: timestamp,
688-
};
689-
690-
// Insert budget data
691-
<BudgetsInfo<T>>::insert(budget_id, budget_data);
692-
693-
// Insert budget id into BudgetsByProject
694-
<BudgetsByProject<T>>::try_mutate::<_,_,DispatchError,_>(project_id, |budgets| {
695-
budgets.try_push(budget_id).map_err(|_| Error::<T>::MaxBudgetsPerProjectReached)?;
696-
Ok(())
697-
})?;
698-
699-
//TOREVIEW: Check if this event is needed
700-
Self::deposit_event(Event::BudgetCreated(budget_id));
701-
Ok(())
702-
}
703-
704-
//For now budgets are not editable.
705-
fn _do_edit_budget(
706-
admin: T::AccountId,
707-
budget_id: [u8;32],
708-
amount: u64,
709-
) -> DispatchResult {
710-
// Ensure admin permissions
711-
Self::is_superuser(admin.clone(), &Self::get_global_scope(), ProxyRole::Administrator.id())?;
712-
713-
//Ensure budget exists
714-
ensure!(<BudgetsInfo<T>>::contains_key(budget_id), Error::<T>::BudgetNotFound);
715-
716-
// Get timestamp
717-
let timestamp = Self::get_timestamp_in_milliseconds().ok_or(Error::<T>::TimestampError)?;
718-
719-
// Mutate budget data
720-
<BudgetsInfo<T>>::try_mutate::<_,_,DispatchError,_>(budget_id, |budget_data| {
721-
let mod_budget_data = budget_data.as_mut().ok_or(Error::<T>::BudgetNotFound)?;
722-
// Update budget data
723-
mod_budget_data.balance = amount;
724-
mod_budget_data.updated_date = timestamp;
657+
// Delete expenditure_id from ExpendituresByProject
658+
<ExpendituresByProject<T>>::try_mutate::<_,_,DispatchError,_>(project_id, |expenditures| {
659+
expenditures.retain(|expenditure| expenditure != &expenditure_id);
725660
Ok(())
726661
})?;
727662

663+
Self::deposit_event(Event::ExpenditureDeleted(expenditure_id));
728664
Ok(())
729665
}
730666

731-
fn do_delete_budget(
732-
project_id: [u8;32],
733-
expenditure_id: [u8;32],
734-
) -> DispatchResult {
735-
// Get budget id
736-
let budget_id = Self::get_budget_id(project_id, expenditure_id)?;
737-
738-
// Remove budget data
739-
<BudgetsInfo<T>>::remove(budget_id);
740-
741-
// Delete budget_id from BudgetsByProject
742-
<BudgetsByProject<T>>::try_mutate::<_,_,DispatchError,_>(project_id, |budgets| {
743-
budgets.retain(|budget| budget != &budget_id);
744-
Ok(())
745-
})?;
746-
747-
Ok(())
748-
}
749-
750-
fn get_budget_id(
751-
project_id: [u8;32],
752-
expenditure_id: [u8;32],
753-
) -> Result<[u8;32], DispatchError> {
754-
// Ensure project exists
755-
ensure!(ProjectsInfo::<T>::contains_key(project_id), Error::<T>::ProjectNotFound);
756-
757-
// Get budgets by project (Id's)
758-
let budget_ids = Self::budgets_by_project(project_id).into_inner();
759-
760-
// Check if the project has any budgets
761-
if budget_ids.len() == 0 {
762-
return Err(Error::<T>::ThereIsNoBudgetsForTheProject.into());
763-
}
764-
765-
// Get budget id
766-
let budget_id: [u8;32] = budget_ids.iter().try_fold::<_,_,Result<[u8;32], DispatchError>>([0;32], |mut accumulator, &budget_id| {
767-
// Get individual budget data
768-
let budget_data = BudgetsInfo::<T>::get(budget_id).ok_or(Error::<T>::BudgetNotFound)?;
769-
770-
// Check if budget belongs to expenditure
771-
if budget_data.expenditure_id == expenditure_id {
772-
accumulator = budget_id;
773-
}
774-
Ok(accumulator)
775-
})?;
776-
777-
Ok(budget_id)
778-
}
779-
780-
781667
// D R A W D O W N S
782668
// --------------------------------------------------------------------------------------------
783669
// For now drawdowns functions are private, but in the future they may be public

pallets/proxy-financial/src/lib.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ pub mod pallet {
9595
#[pallet::constant]
9696
type MaxBoundedVecs: Get<u32>;
9797

98-
99-
#[pallet::constant]
100-
type MaxBudgetsPerProject: Get<u32>;
101-
10298
#[pallet::constant]
10399
type MaxDrawdownsPerProject: Get<u32>;
104100

@@ -110,6 +106,9 @@ pub mod pallet {
110106

111107
#[pallet::constant]
112108
type MaxDrawdownsByStatus: Get<u32>;
109+
110+
#[pallet::constant]
111+
type MaxExpendituresPerProject: Get<u32>;
113112

114113

115114
}
@@ -139,7 +138,7 @@ pub mod pallet {
139138
>;
140139

141140
#[pallet::storage]
142-
#[pallet::getter(fn projects)]
141+
#[pallet::getter(fn projects_info)]
143142
pub(super) type ProjectsInfo<T: Config> = StorageMap<
144143
_,
145144
Identity,
@@ -169,7 +168,7 @@ pub mod pallet {
169168
>;
170169

171170
#[pallet::storage]
172-
#[pallet::getter(fn expenditures)]
171+
#[pallet::getter(fn expenditures_info)]
173172
pub(super) type ExpendituresInfo<T: Config> = StorageMap<
174173
_,
175174
Identity,
@@ -178,25 +177,13 @@ pub mod pallet {
178177
OptionQuery,
179178
>;
180179

181-
//TODO: remove
182-
#[pallet::storage]
183-
#[pallet::getter(fn budgets)]
184-
pub(super) type BudgetsInfo<T: Config> = StorageMap<
185-
_,
186-
Identity,
187-
[u8;32], // Key expenditure_id
188-
BudgetData, // Value BudgetData
189-
OptionQuery,
190-
>;
191-
192-
//TODO: remove
193180
#[pallet::storage]
194-
#[pallet::getter(fn budgets_by_project)]
195-
pub(super) type BudgetsByProject<T: Config> = StorageMap<
181+
#[pallet::getter(fn expenditures_by_project)]
182+
pub(super) type ExpendituresByProject<T: Config> = StorageMap<
196183
_,
197184
Identity,
198185
[u8;32], // Key project_id
199-
BoundedVec<[u8;32], T::MaxBudgetsPerProject>, // Value budgets
186+
BoundedVec<[u8;32], T::MaxExpendituresPerProject>, // Value expenditures
200187
ValueQuery,
201188
>;
202189

@@ -345,10 +332,10 @@ pub mod pallet {
345332
UserCannotHaveMoreThanOneRole,
346333
/// Expenditure not found
347334
ExpenditureNotFound,
348-
/// Maximum number of budgets per project reached
349-
MaxBudgetsPerProjectReached,
350335
/// Expenditure already exist
351336
ExpenditureAlreadyExists,
337+
/// Max number of expenditures per project reached
338+
MaxExpendituresPerProjectReached,
352339
/// Name for expenditure is too long
353340
NameTooLong,
354341
/// There is no expenditure with such project id

pallets/proxy-financial/src/mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ parameter_types! {
7171
pub const MaxIssuersPerProject:u32 = 1;
7272
pub const MaxRegionalCenterPerProject:u32 = 1;
7373
pub const MaxBoundedVecs:u32 = 1;
74-
pub const MaxBudgetsPerProject:u32 = 1000;
7574
pub const MaxDrawdownsPerProject:u32 = 1000;
7675
pub const MaxTransactionsPerDrawdown:u32 = 500;
7776
pub const MaxRegistrationsAtTime:u32 = 50;
7877
pub const MaxDrawdownsByStatus:u32 = 2000;
78+
pub const MaxExpendituresPerProject:u32 = 1000;
7979

8080
}
8181

@@ -94,11 +94,11 @@ impl pallet_proxy_financial::Config for Test {
9494
type MaxIssuersPerProject = MaxIssuersPerProject;
9595
type MaxRegionalCenterPerProject = MaxRegionalCenterPerProject;
9696
type MaxBoundedVecs = MaxBoundedVecs;
97-
type MaxBudgetsPerProject = MaxBudgetsPerProject;
9897
type MaxDrawdownsPerProject = MaxDrawdownsPerProject;
9998
type MaxTransactionsPerDrawdown = MaxTransactionsPerDrawdown;
10099
type MaxRegistrationsAtTime = MaxRegistrationsAtTime;
101100
type MaxDrawdownsByStatus = MaxDrawdownsByStatus;
101+
type MaxExpendituresPerProject = MaxExpendituresPerProject;
102102

103103

104104
type Timestamp = Timestamp;

runtime/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,11 @@ parameter_types! {
559559
pub const MaxIssuersPerProject:u32 = 1;
560560
pub const MaxRegionalCenterPerProject:u32 = 1;
561561
pub const MaxBoundedVecs:u32 = 1;
562-
pub const MaxBudgetsPerProject:u32 = 1000;
563562
pub const MaxDrawdownsPerProject:u32 = 1000;
564563
pub const MaxTransactionsPerDrawdown:u32 = 500;
565564
pub const MaxRegistrationsAtTime:u32 = 50;
566565
pub const MaxDrawdownsByStatus:u32 = 2000;
566+
pub const MaxExpendituresPerProject:u32 = 1000;
567567

568568

569569
}
@@ -589,11 +589,11 @@ impl pallet_proxy_financial::Config for Runtime {
589589
type MaxIssuersPerProject = MaxIssuersPerProject;
590590
type MaxRegionalCenterPerProject = MaxRegionalCenterPerProject;
591591
type MaxBoundedVecs = MaxBoundedVecs;
592-
type MaxBudgetsPerProject = MaxBudgetsPerProject;
593592
type MaxDrawdownsPerProject = MaxDrawdownsPerProject;
594593
type MaxTransactionsPerDrawdown = MaxTransactionsPerDrawdown;
595594
type MaxRegistrationsAtTime = MaxRegistrationsAtTime;
596595
type MaxDrawdownsByStatus = MaxDrawdownsByStatus;
596+
type MaxExpendituresPerProject = MaxExpendituresPerProject;
597597

598598
}
599599

0 commit comments

Comments
 (0)