@@ -107,7 +107,6 @@ pub mod EventFactory {
107
107
upgradeable : UpgradeableComponent :: Storage ,
108
108
event_count : u256 ,
109
109
events : Map <u256 , EventData >,
110
- event_array : Array <EventData >,
111
110
event_ticket_balance : Map <u256 , u256 >,
112
111
strk_token_address : felt252 ,
113
112
ticket_721_class_hash : felt252 ,
@@ -152,72 +151,21 @@ pub mod EventFactory {
152
151
end_date : u64 ,
153
152
total_tickets : u256 ,
154
153
ticket_price : u256 ,
155
- ) -> bool {
156
- let caller = get_caller_address ();
157
- let event_count = self . event_count. read () + 1 ;
158
- let address_this = get_contract_address ();
159
-
160
- // assert not zero ContractAddress
161
- assert (caller . is_non_zero (), Errors :: ZERO_ADDRESS_CALLER );
162
-
163
- // create event role
164
- let event_hash = PedersenTrait :: new (0 )
165
- . update (' CROWD_PASS_EVENT' )
166
- . update (event_count . try_into (). unwrap ())
167
- . finalize ();
168
- // grant role to caller
169
- self . accesscontrol. _grant_role (event_hash , caller );
170
-
171
- // let event_ticket_addr = self.deploy_ticket(address_this, address_this, ''.into());
172
-
173
- // deploy ticket721 contract
174
- let event_ticket = deploy_syscall (
175
- self . ticket_721_class_hash. read (). try_into (). unwrap (),
176
- event_hash ,
177
- array! [address_this . into (), address_this . into ()]. span (),
178
- true ,
179
- );
180
-
181
- let (event_ticket_addr , _ ) = event_ticket . unwrap_syscall ();
182
-
183
- // initialize ticket721 contract
184
- ITicket721Dispatcher { contract_address : event_ticket_addr }
185
- . initialize (name , symbol , uri ,);
186
-
187
- // new event struct instance
188
- let event_instance = EventData {
189
- id : event_count ,
190
- organizer : caller ,
191
- ticket_addr : event_ticket_addr ,
192
- description : description ,
193
- location : location ,
194
- created_at : get_block_timestamp (),
195
- updated_at : 0 ,
196
- start_date : start_date ,
197
- end_date : end_date ,
198
- total_tickets : total_tickets ,
199
- ticket_price : ticket_price ,
200
- is_canceled : false ,
201
- };
202
-
203
- // Map event_id to new_event
204
- self . events. entry (event_count ). write (event_instance );
205
-
206
- // Append event to event_array
207
- // self.event_array.append(event_instance);
208
-
209
- // Update event count
210
- self . event_count. write (event_count );
211
-
212
- // emit event for event creation
213
- self
214
- . emit (
215
- EventCreated {
216
- id : event_count , organizer : caller , ticket_address : event_ticket_addr
217
- }
154
+ ) -> EventData {
155
+ let event = self
156
+ . _create_event (
157
+ name ,
158
+ symbol ,
159
+ uri ,
160
+ description ,
161
+ location ,
162
+ start_date ,
163
+ end_date ,
164
+ total_tickets ,
165
+ ticket_price
218
166
);
219
167
220
- true
168
+ event
221
169
}
222
170
223
171
fn update_event (
@@ -235,10 +183,7 @@ pub mod EventFactory {
235
183
) -> bool {
236
184
let caller = get_caller_address ();
237
185
238
- let event_hash = PedersenTrait :: new (0 )
239
- . update (' CROWD_PASS_EVENT' )
240
- . update (event_id . try_into (). unwrap ())
241
- . finalize ();
186
+ let event_hash = self . _gen_event_hash (event_id );
242
187
// assert caller has role
243
188
self . accesscontrol. assert_only_role (event_hash );
244
189
@@ -269,17 +214,14 @@ pub mod EventFactory {
269
214
let organizer = self . events. entry (event_id ). read (). organizer;
270
215
let mut event_instance = self . events. entry (event_id ). read ();
271
216
272
- let event_hash = PedersenTrait :: new (0 )
273
- . update (' CROWD_PASS_EVENT' )
274
- . update (event_id . try_into (). unwrap ())
275
- . finalize ();
276
- // assert caller has role
277
- self . accesscontrol. assert_only_role (event_hash );
217
+ let event_hash = self . _gen_event_hash (event_id );
278
218
279
219
assert (event_id <= event_count , Errors :: EVENT_NOT_CREATED );
280
220
// assert not zeroAddr caller
281
221
assert (caller . is_non_zero (), Errors :: ZERO_ADDRESS_CALLER );
282
- // assert caller is event organizer
222
+ // assert caller has role
223
+ self . accesscontrol. assert_only_role (event_hash );
224
+ // assert caller is the main event organizer
283
225
assert (caller == organizer , Errors :: NOT_EVENT_ORGANIZER );
284
226
// assert event has not ended
285
227
assert (event_instance . end_date > get_block_timestamp (), Errors :: EVENT_ENDED );
@@ -293,6 +235,17 @@ pub mod EventFactory {
293
235
true
294
236
}
295
237
238
+ fn add_organizer (ref self : ContractState , event_id : u256 , organizer : ContractAddress ) {
239
+ let event_hash = self . _gen_event_hash (event_id );
240
+ self . accesscontrol. assert_only_role (event_hash );
241
+ self . _add_organizer (event_hash , organizer );
242
+ }
243
+ fn remove_organizer (ref self : ContractState , event_id : u256 , organizer : ContractAddress ) {
244
+ let event_hash = self . _gen_event_hash (event_id );
245
+ self . accesscontrol. assert_only_role (event_hash );
246
+ self . _remove_organizer (event_hash , organizer );
247
+ }
248
+
296
249
fn purchase_ticket (ref self : ContractState , event_id : u256 ) -> bool {
297
250
let caller : ContractAddress = get_caller_address ();
298
251
let event_count : u256 = self . event_count. read ();
@@ -413,6 +366,98 @@ pub mod EventFactory {
413
366
/// ///////////////////////////////////////////////////////////////////////*//
414
367
impl AccessControlInternalImpl = AccessControlComponent :: InternalImpl <ContractState >;
415
368
impl UpgradeableInternalImpl = UpgradeableComponent :: InternalImpl <ContractState >;
369
+
370
+ #[generate_trait]
371
+ impl InternalImpl of InternalTrait {
372
+ fn _gen_event_hash (self : @ ContractState , event_id : u256 ) -> felt252 {
373
+ PedersenTrait :: new (0 )
374
+ . update (' CROWD_PASS_EVENT' )
375
+ . update (event_id . try_into (). unwrap ())
376
+ . finalize ()
377
+ }
378
+
379
+ fn _create_event (
380
+ ref self : ContractState ,
381
+ name : ByteArray ,
382
+ symbol : ByteArray ,
383
+ uri : ByteArray ,
384
+ description : ByteArray ,
385
+ location : ByteArray ,
386
+ start_date : u64 ,
387
+ end_date : u64 ,
388
+ total_tickets : u256 ,
389
+ ticket_price : u256 ,
390
+ ) -> EventData {
391
+ let caller = get_caller_address ();
392
+ let event_count = self . event_count. read () + 1 ;
393
+ let address_this = get_contract_address ();
394
+
395
+ // create event role
396
+ let event_hash = self . _gen_event_hash (event_count );
397
+ // grant caller event role
398
+ self . accesscontrol. _grant_role (event_hash , caller );
399
+
400
+ // deploy ticket721 contract
401
+ let event_ticket = deploy_syscall (
402
+ self . ticket_721_class_hash. read (). try_into (). unwrap (),
403
+ event_hash ,
404
+ array! [address_this . into (), address_this . into ()]. span (),
405
+ true ,
406
+ );
407
+
408
+ let (event_ticket_addr , _ ) = event_ticket . unwrap_syscall ();
409
+
410
+ // initialize ticket721 contract
411
+ ITicket721Dispatcher { contract_address : event_ticket_addr }
412
+ . initialize (name , symbol , uri ,);
413
+
414
+ // new event struct instance
415
+ let event_instance = EventData {
416
+ id : event_count ,
417
+ organizer : caller ,
418
+ ticket_addr : event_ticket_addr ,
419
+ description : description ,
420
+ location : location ,
421
+ created_at : get_block_timestamp (),
422
+ updated_at : 0 ,
423
+ start_date : start_date ,
424
+ end_date : end_date ,
425
+ total_tickets : total_tickets ,
426
+ ticket_price : ticket_price ,
427
+ is_canceled : false ,
428
+ };
429
+
430
+ // Map event_id to new_event
431
+ self . events. entry (event_count ). write (event_instance );
432
+
433
+ // Update event count
434
+ self . event_count. write (event_count );
435
+
436
+ // emit event for event creation
437
+ self
438
+ . emit (
439
+ EventCreated {
440
+ id : event_count , organizer : caller , ticket_address : event_ticket_addr
441
+ }
442
+ );
443
+
444
+ self . events. entry (event_count ). read ()
445
+ }
446
+
447
+ fn _add_organizer (
448
+ ref self : ContractState , event_hash : felt252 , organizer : ContractAddress
449
+ ) {
450
+ // grant role to caller
451
+ self . accesscontrol. _grant_role (event_hash , organizer );
452
+ }
453
+
454
+ fn _remove_organizer (
455
+ ref self : ContractState , event_hash : felt252 , organizer : ContractAddress
456
+ ) {
457
+ // revoke role from caller
458
+ self . accesscontrol. _revoke_role (event_hash , organizer );
459
+ }
460
+ }
416
461
// #[generate_trait]
417
462
// pub impl MultiCallImpl of IMultiCallTrait<ContractState> {
418
463
// // Internal function to execute multiple calls
0 commit comments