Skip to content

Commit d9a9328

Browse files
committed
Remove unnecesarry storagemaps
1 parent 169f509 commit d9a9328

File tree

4 files changed

+31
-123
lines changed

4 files changed

+31
-123
lines changed

pallets/proxy-financial/src/functions.rs

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,6 @@ 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-
//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-
})?;
577-
578572
// Create a budget for the expenditure
579573
Self::do_create_budget(expenditure_id, 0, project_id)?;
580574
}
@@ -657,12 +651,6 @@ impl<T: Config> Pallet<T> {
657651
// Delete expenditure data
658652
<ExpendituresInfo<T>>::remove(expenditure_id);
659653

660-
// Delete expenditure_id from ExpendituresByProject
661-
<ExpendituresByProject<T>>::try_mutate::<_,_,DispatchError,_>(project_id, |expenditures| {
662-
expenditures.retain(|expenditure| expenditure != &expenditure_id);
663-
Ok(())
664-
})?;
665-
666654
// Delete expenditure budget
667655
Self::do_delete_budget(project_id, expenditure_id)?;
668656

@@ -795,13 +783,12 @@ impl<T: Config> Pallet<T> {
795783
// For now drawdowns functions are private, but in the future they may be public
796784

797785
fn do_create_drawdown(
798-
admin: T::AccountId,
799786
project_id: [u8;32],
800787
drawdown_type: DrawdownType,
801788
drawdown_number: u32,
802789
) -> DispatchResult {
803-
// Ensure admin permissions
804-
Self::is_superuser(admin.clone(), &Self::get_global_scope(), ProxyRole::Administrator.id())?;
790+
// TOOD: Ensure builder permissions
791+
//Self::is_superuser(admin.clone(), &Self::get_global_scope(), ProxyRole::Administrator.id())?;
805792

806793
// Ensure project exists
807794
ensure!(ProjectsInfo::<T>::contains_key(project_id), Error::<T>::ProjectNotFound);
@@ -810,7 +797,7 @@ impl<T: Config> Pallet<T> {
810797
let timestamp = Self::get_timestamp_in_milliseconds().ok_or(Error::<T>::TimestampError)?;
811798

812799
// Create drawdown id
813-
let drawdown_id = (project_id, drawdown_type, drawdown_number).using_encoded(blake2_256);
800+
let drawdown_id = (project_id, drawdown_type, drawdown_number, timestamp).using_encoded(blake2_256);
814801

815802
// Create drawdown data
816803
let drawdown_data = DrawdownData::<T> {
@@ -819,9 +806,9 @@ impl<T: Config> Pallet<T> {
819806
drawdown_type,
820807
total_amount: 0,
821808
status: DrawdownStatus::default(),
809+
documents: None,
822810
created_date: timestamp,
823811
close_date: 0,
824-
creator: Some(admin.clone()),
825812
};
826813

827814
// Insert drawdown data
@@ -836,7 +823,6 @@ impl<T: Config> Pallet<T> {
836823
})?;
837824

838825
//TOREVIEW: Check if an event is needed
839-
840826
Ok(())
841827
}
842828

@@ -855,13 +841,13 @@ impl<T: Config> Pallet<T> {
855841
ensure!(ProjectsInfo::<T>::contains_key(project_id), Error::<T>::ProjectNotFound);
856842

857843
//Create a EB5 drawdown
858-
Self::do_create_drawdown(admin.clone(), project_id, DrawdownType::EB5, 1)?;
844+
Self::do_create_drawdown(project_id, DrawdownType::EB5, 1)?;
859845

860846
//Create a Construction Loan drawdown
861-
Self::do_create_drawdown(admin.clone(), project_id, DrawdownType::ConstructionLoan, 1)?;
847+
Self::do_create_drawdown(project_id, DrawdownType::ConstructionLoan, 1)?;
862848

863849
//Create a Developer Equity drawdown
864-
Self::do_create_drawdown(admin.clone(), project_id, DrawdownType::DeveloperEquity, 1)?;
850+
Self::do_create_drawdown(project_id, DrawdownType::DeveloperEquity, 1)?;
865851

866852
Ok(())
867853
}
@@ -880,18 +866,24 @@ impl<T: Config> Pallet<T> {
880866
// when a drawdown is approved, the amount is transfered to every expenditure
881867
// using the storage map, transactions_by_drawdown, we can get the transactions for a specific drawdown
882868

869+
fn do_execute_transaction(
870+
) -> DispatchResult {
871+
872+
873+
Ok(())
874+
}
875+
876+
883877
fn do_create_transaction(
884-
admin: T::AccountId,
885878
project_id: [u8;32],
886879
drawdown_id: [u8;32],
887880
expenditure_id: [u8;32],
888881
amount: u64,
889-
description: FieldDescription,
882+
feedback: FieldDescription,
890883
//TOREVIEW: Is mandatory to upload documents with every transaction? If not we can wrap this field in an Option
891884
documents: Option<Documents<T>>
892885
) -> DispatchResult {
893-
// Ensure admin permissions
894-
Self::is_superuser(admin.clone(), &Self::get_global_scope(), ProxyRole::Administrator.id())?;
886+
// TODO:Ensure builder permissions
895887

896888
// Ensure drawdown exists
897889
ensure!(DrawdownsInfo::<T>::contains_key(drawdown_id), Error::<T>::DrawdownNotFound);
@@ -915,11 +907,10 @@ impl<T: Config> Pallet<T> {
915907
project_id,
916908
drawdown_id,
917909
expenditure_id,
918-
creator: admin.clone(),
919910
created_date: timestamp,
920911
updated_date: timestamp,
921912
closed_date: 0,
922-
description,
913+
feedback,
923914
amount,
924915
status: TransactionStatus::default(),
925916
documents,
@@ -930,24 +921,12 @@ impl<T: Config> Pallet<T> {
930921
ensure!(!TransactionsInfo::<T>::contains_key(transaction_id), Error::<T>::TransactionAlreadyExists);
931922
<TransactionsInfo<T>>::insert(transaction_id, transaction_data);
932923

933-
// Insert transaction id into TransactionsByProject
934-
<TransactionsByProject<T>>::try_mutate::<_,_,DispatchError,_>(project_id, |transactions| {
935-
transactions.try_push(transaction_id).map_err(|_| Error::<T>::MaxTransactionsPerProjectReached)?;
936-
Ok(())
937-
})?;
938-
939924
// Insert transaction id into TransactionsByDrawdown
940925
<TransactionsByDrawdown<T>>::try_mutate::<_,_,_,DispatchError,_>(project_id, drawdown_id, |transactions| {
941926
transactions.try_push(transaction_id).map_err(|_| Error::<T>::MaxTransactionsPerDrawdownReached)?;
942927
Ok(())
943928
})?;
944929

945-
// Insert transaction id into TransactionsByExpenditure
946-
<TransactionsByExpenditure<T>>::try_mutate::<_,_,_,DispatchError,_>(project_id, expenditure_id, |transactions| {
947-
transactions.try_push(transaction_id).map_err(|_| Error::<T>::MaxTransactionsPerExpenditureReached)?;
948-
Ok(())
949-
})?;
950-
951930
//TOREVIEW: Check if this event is needed
952931
Self::deposit_event(Event::TransactionCreated(transaction_id));
953932
Ok(())
@@ -958,7 +937,7 @@ impl<T: Config> Pallet<T> {
958937
admin: T::AccountId,
959938
transaction_id: [u8;32],
960939
amount: Option<u64>,
961-
description: Option<BoundedVec<FieldDescription, T::MaxBoundedVecs>>,
940+
feedback: Option<BoundedVec<FieldDescription, T::MaxBoundedVecs>>,
962941
documents: Option<Documents<T>>
963942
) -> DispatchResult {
964943
// Ensure admin permissions
@@ -999,9 +978,9 @@ impl<T: Config> Pallet<T> {
999978
if let Some(amount) = amount.clone() {
1000979
mod_transaction_data.amount = amount;
1001980
}
1002-
if let Some(description) = description.clone() {
1003-
let mod_description = description.into_inner();
1004-
mod_transaction_data.description = mod_description[0].clone();
981+
if let Some(feedback) = feedback.clone() {
982+
let mod_feedback = feedback.into_inner();
983+
mod_transaction_data.feedback = mod_feedback[0].clone();
1005984
}
1006985
if let Some(documents) = documents.clone() {
1007986
mod_transaction_data.documents = Some(documents);
@@ -1035,24 +1014,12 @@ impl<T: Config> Pallet<T> {
10351014
// Ensure transaction is not completed
10361015
ensure!(Self::is_transaction_editable(transaction_id).is_ok(), Error::<T>::TransactionIsAlreadyCompleted);
10371016

1038-
// Remove transaction from TransactionsByProject
1039-
<TransactionsByProject<T>>::try_mutate::<_,_,DispatchError,_>(transaction_data.project_id, |transactions| {
1040-
transactions.retain(|transaction| transaction != &transaction_id);
1041-
Ok(())
1042-
})?;
1043-
10441017
// Remove transaction from TransactionsByDrawdown
10451018
<TransactionsByDrawdown<T>>::try_mutate::<_,_,_,DispatchError,_>(transaction_data.project_id, transaction_data.drawdown_id, |transactions| {
10461019
transactions.retain(|transaction| transaction != &transaction_id);
10471020
Ok(())
10481021
})?;
10491022

1050-
// Remove transaction from TransactionsByExpenditure
1051-
<TransactionsByExpenditure<T>>::try_mutate::<_,_,_,DispatchError,_>(transaction_data.project_id, transaction_data.expenditure_id, |transactions| {
1052-
transactions.retain(|transaction| transaction != &transaction_id);
1053-
Ok(())
1054-
})?;
1055-
10561023
// Remove transaction from TransactionsInfo
10571024
<TransactionsInfo<T>>::remove(transaction_id);
10581025

pallets/proxy-financial/src/lib.rs

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

98-
#[pallet::constant]
99-
type MaxExpendituresPerProject: Get<u32>;
10098

10199
#[pallet::constant]
102100
type MaxBudgetsPerProject: Get<u32>;
103101

104102
#[pallet::constant]
105103
type MaxDrawdownsPerProject: Get<u32>;
106104

107-
#[pallet::constant]
108-
type MaxTransactionsPerProject: Get<u32>;
109-
110105
#[pallet::constant]
111106
type MaxTransactionsPerDrawdown: Get<u32>;
112107

113108
#[pallet::constant]
114-
type MaxTransactionsPerExpenditure: Get<u32>;
109+
type MaxRegistrationsAtTime: Get<u32>;
115110

116111
#[pallet::constant]
117-
type MaxRegistrationsAtTime: Get<u32>;
112+
type MaxDrawdownsByStatus: Get<u32>;
118113

119114

120115
}
@@ -183,16 +178,7 @@ pub mod pallet {
183178
OptionQuery,
184179
>;
185180

186-
#[pallet::storage]
187-
#[pallet::getter(fn expenditures_by_project)]
188-
pub(super) type ExpendituresByProject<T: Config> = StorageMap<
189-
_,
190-
Identity,
191-
[u8;32], // Key project_id
192-
BoundedVec<[u8;32], T::MaxExpendituresPerProject>, // Value expenditures
193-
ValueQuery,
194-
>;
195-
181+
//TODO: remove
196182
#[pallet::storage]
197183
#[pallet::getter(fn budgets)]
198184
pub(super) type BudgetsInfo<T: Config> = StorageMap<
@@ -203,6 +189,7 @@ pub mod pallet {
203189
OptionQuery,
204190
>;
205191

192+
//TODO: remove
206193
#[pallet::storage]
207194
#[pallet::getter(fn budgets_by_project)]
208195
pub(super) type BudgetsByProject<T: Config> = StorageMap<
@@ -233,18 +220,6 @@ pub mod pallet {
233220
ValueQuery,
234221
>;
235222

236-
#[pallet::storage]
237-
#[pallet::getter(fn drawdowns_by_project_by_type)]
238-
pub(super) type DrawdownsByProjectByType<T: Config> = StorageDoubleMap<
239-
_,
240-
Identity,
241-
[u8;32], // Key project_id
242-
Identity,
243-
DrawdownType, // Key drawdown type
244-
BoundedVec<[u8;32], T::MaxDrawdownsPerProject>, // Value Drawdowns
245-
ValueQuery,
246-
>;
247-
248223
#[pallet::storage]
249224
#[pallet::getter(fn transactions)]
250225
pub(super) type TransactionsInfo<T: Config> = StorageMap<
@@ -255,16 +230,6 @@ pub mod pallet {
255230
OptionQuery,
256231
>;
257232

258-
#[pallet::storage]
259-
#[pallet::getter(fn transactions_by_project)]
260-
pub(super) type TransactionsByProject<T: Config> = StorageMap<
261-
_,
262-
Identity,
263-
[u8;32], // Key project_id
264-
BoundedVec<[u8;32], T::MaxTransactionsPerProject>, // Value transactions
265-
ValueQuery,
266-
>;
267-
268233
#[pallet::storage]
269234
#[pallet::getter(fn transactions_by_drawdown)]
270235
pub(super) type TransactionsByDrawdown<T: Config> = StorageDoubleMap<
@@ -277,17 +242,6 @@ pub mod pallet {
277242
ValueQuery
278243
>;
279244

280-
#[pallet::storage]
281-
#[pallet::getter(fn transactions_by_expenditure)]
282-
pub(super) type TransactionsByExpenditure<T: Config> = StorageDoubleMap<
283-
_,
284-
Identity,
285-
[u8;32], //K1: project id
286-
Identity,
287-
[u8;32], //K2: expenditure id
288-
BoundedVec<[u8;32], T::MaxTransactionsPerExpenditure>, // Value transactions
289-
ValueQuery
290-
>;
291245
// E V E N T S
292246
// ------------------------------------------------------------------------------------------------------------
293247

@@ -395,8 +349,6 @@ pub mod pallet {
395349
MaxBudgetsPerProjectReached,
396350
/// Expenditure already exist
397351
ExpenditureAlreadyExists,
398-
/// Max number of expenditures per project reached
399-
MaxExpendituresPerProjectReached,
400352
/// Name for expenditure is too long
401353
NameTooLong,
402354
/// There is no expenditure with such project id
@@ -419,12 +371,8 @@ pub mod pallet {
419371
TransactionNotFound,
420372
/// Transaction already exist
421373
TransactionAlreadyExists,
422-
/// Max number of transactions per project reached
423-
MaxTransactionsPerProjectReached,
424374
/// Max number of transactions per drawdown reached
425375
MaxTransactionsPerDrawdownReached,
426-
/// Max number of transactions per expenditure reached
427-
MaxTransactionsPerExpenditureReached,
428376
/// Drawdown already exist
429377
DrawdownAlreadyExists,
430378
/// Max number of drawdowns per project reached

pallets/proxy-financial/src/mock.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +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 MaxExpendituresPerProject:u32 = 1000;
7574
pub const MaxBudgetsPerProject:u32 = 1000;
7675
pub const MaxDrawdownsPerProject:u32 = 1000;
77-
pub const MaxTransactionsPerProject:u32 = 1000;
7876
pub const MaxTransactionsPerDrawdown:u32 = 500;
79-
pub const MaxTransactionsPerExpenditure:u32 = 500;
8077
pub const MaxRegistrationsAtTime:u32 = 50;
78+
pub const MaxDrawdownsByStatus:u32 = 2000;
8179

8280
}
8381

@@ -96,13 +94,12 @@ impl pallet_proxy_financial::Config for Test {
9694
type MaxIssuersPerProject = MaxIssuersPerProject;
9795
type MaxRegionalCenterPerProject = MaxRegionalCenterPerProject;
9896
type MaxBoundedVecs = MaxBoundedVecs;
99-
type MaxExpendituresPerProject = MaxExpendituresPerProject;
10097
type MaxBudgetsPerProject = MaxBudgetsPerProject;
10198
type MaxDrawdownsPerProject = MaxDrawdownsPerProject;
102-
type MaxTransactionsPerProject = MaxTransactionsPerProject;
10399
type MaxTransactionsPerDrawdown = MaxTransactionsPerDrawdown;
104-
type MaxTransactionsPerExpenditure = MaxTransactionsPerExpenditure;
105100
type MaxRegistrationsAtTime = MaxRegistrationsAtTime;
101+
type MaxDrawdownsByStatus = MaxDrawdownsByStatus;
102+
106103

107104
type Timestamp = Timestamp;
108105
type Moment = u64;

runtime/src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,13 +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 MaxExpendituresPerProject:u32 = 1000;
563562
pub const MaxBudgetsPerProject:u32 = 1000;
564563
pub const MaxDrawdownsPerProject:u32 = 1000;
565-
pub const MaxTransactionsPerProject:u32 = 1000;
566564
pub const MaxTransactionsPerDrawdown:u32 = 500;
567-
pub const MaxTransactionsPerExpenditure:u32 = 500;
568565
pub const MaxRegistrationsAtTime:u32 = 50;
566+
pub const MaxDrawdownsByStatus:u32 = 2000;
569567

570568

571569
}
@@ -591,13 +589,11 @@ impl pallet_proxy_financial::Config for Runtime {
591589
type MaxIssuersPerProject = MaxIssuersPerProject;
592590
type MaxRegionalCenterPerProject = MaxRegionalCenterPerProject;
593591
type MaxBoundedVecs = MaxBoundedVecs;
594-
type MaxExpendituresPerProject = MaxExpendituresPerProject;
595592
type MaxBudgetsPerProject = MaxBudgetsPerProject;
596593
type MaxDrawdownsPerProject = MaxDrawdownsPerProject;
597-
type MaxTransactionsPerProject = MaxTransactionsPerProject;
598594
type MaxTransactionsPerDrawdown = MaxTransactionsPerDrawdown;
599-
type MaxTransactionsPerExpenditure = MaxTransactionsPerExpenditure;
600595
type MaxRegistrationsAtTime = MaxRegistrationsAtTime;
596+
type MaxDrawdownsByStatus = MaxDrawdownsByStatus;
601597

602598
}
603599

0 commit comments

Comments
 (0)