@@ -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
0 commit comments