@@ -18,7 +18,7 @@ mod test;
1818pub use error:: CoordinatorError ;
1919pub use types:: { DataKey , ExcursionSummary , WorkflowRecord , WorkflowStatus } ;
2020
21- use soroban_sdk:: { contract, contractimpl , contracttype , symbol_short , Address , Env , String , Vec } ;
21+ use soroban_sdk:: { contract, contractevent , contractimpl , contracttype , Address , Env , String , Vec } ;
2222
2323/// Default workflow expiry window: 6 hours expressed in seconds.
2424/// After `allocate_units` is called, if `confirm_delivery` is never invoked
@@ -122,6 +122,7 @@ mod request_client {
122122 use soroban_sdk:: { contractclient, Address , Env } ;
123123
124124 #[ contractclient( name = "RequestContractClient" ) ]
125+ #[ allow( dead_code) ]
125126 pub trait RequestContractInterface {
126127 fn get_request ( env : Env , request_id : u64 ) -> BloodRequest ;
127128 }
@@ -132,6 +133,7 @@ mod inventory_client {
132133 use soroban_sdk:: { contractclient, Address , Env , String } ;
133134
134135 #[ contractclient( name = "InventoryContractClient" ) ]
136+ #[ allow( dead_code) ]
135137 pub trait InventoryContractInterface {
136138 fn get_blood_unit ( env : Env , blood_unit_id : u64 ) -> BloodUnit ;
137139 fn update_status (
@@ -168,6 +170,7 @@ mod payment_client {
168170 }
169171
170172 #[ contractclient( name = "PaymentContractClient" ) ]
173+ #[ allow( dead_code) ]
171174 pub trait PaymentContractInterface {
172175 fn get_payment ( env : Env , payment_id : u64 ) -> Payment ;
173176 fn update_status ( env : Env , payment_id : u64 , status : PaymentStatus ) ;
@@ -179,6 +182,54 @@ use inventory_client::InventoryContractClient;
179182use payment_client:: PaymentContractClient ;
180183use request_client:: RequestContractClient ;
181184
185+ // ── Contract events ───────────────────────────────────────────────────────────
186+
187+ #[ contractevent( topics = [ "coord" , "init" ] , data_format = "single-value" ) ]
188+ pub struct CoordInitialized {
189+ pub admin : Address ,
190+ }
191+
192+ #[ contractevent( topics = [ "coord" , "emrghlt" ] , data_format = "single-value" ) ]
193+ pub struct CoordEmergencyHalt {
194+ pub admin : Address ,
195+ }
196+
197+ #[ contractevent( topics = [ "coord" , "alloc" ] , data_format = "vec" ) ]
198+ pub struct CoordAllocated {
199+ pub request_id : u64 ,
200+ pub unit_ids : Vec < u64 > ,
201+ pub unit_count : u32 ,
202+ }
203+
204+ #[ contractevent( topics = [ "coord" , "dlvrd" ] , data_format = "vec" ) ]
205+ pub struct CoordDelivered {
206+ pub request_id : u64 ,
207+ pub location : String ,
208+ }
209+
210+ #[ contractevent( topics = [ "coord" , "settld" ] , data_format = "vec" ) ]
211+ pub struct CoordSettled {
212+ pub request_id : u64 ,
213+ pub payment_id : u64 ,
214+ }
215+
216+ #[ contractevent( topics = [ "coord" , "rollbk" ] , data_format = "single-value" ) ]
217+ pub struct CoordRolledBack {
218+ pub request_id : u64 ,
219+ }
220+
221+ #[ contractevent( topics = [ "coord" , "expired" ] , data_format = "single-value" ) ]
222+ pub struct CoordExpired {
223+ pub request_id : u64 ,
224+ }
225+
226+ #[ contractevent( topics = [ "coord" , "tmp_brch" ] , data_format = "vec" ) ]
227+ pub struct CoordTemperatureBreach {
228+ pub payment_id : u64 ,
229+ pub unit_id : u64 ,
230+ pub timestamp : u64 ,
231+ }
232+
182233// ── Storage helpers ────────────────────────────────────────────────────────────
183234
184235fn get_admin ( env : & Env ) -> Result < Address , CoordinatorError > {
@@ -250,14 +301,7 @@ impl CoordinatorContract {
250301 env. storage ( )
251302 . instance ( )
252303 . set ( & DataKey :: PaymentContract , & payment_contract) ;
253- env. events ( ) . publish (
254- (
255- symbol_short ! ( "coord" ) ,
256- symbol_short ! ( "init" ) ,
257- symbol_short ! ( "v1" ) ,
258- ) ,
259- admin,
260- ) ;
304+ CoordInitialized { admin } . publish ( & env) ;
261305 Ok ( ( ) )
262306 }
263307
@@ -341,14 +385,7 @@ impl CoordinatorContract {
341385 return Err ( CoordinatorError :: Unauthorized ) ;
342386 }
343387 env. storage ( ) . instance ( ) . set ( & DataKey :: EmergencyHalt , & true ) ;
344- env. events ( ) . publish (
345- (
346- symbol_short ! ( "coord" ) ,
347- symbol_short ! ( "emrghlt" ) ,
348- symbol_short ! ( "v1" ) ,
349- ) ,
350- admin,
351- ) ;
388+ CoordEmergencyHalt { admin } . publish ( & env) ;
352389 Ok ( ( ) )
353390 }
354391
@@ -440,14 +477,7 @@ impl CoordinatorContract {
440477 . map_err ( |_| CoordinatorError :: InventoryUpdateFailed ) ?;
441478 }
442479
443- env. events ( ) . publish (
444- (
445- symbol_short ! ( "coord" ) ,
446- symbol_short ! ( "alloc" ) ,
447- symbol_short ! ( "v1" ) ,
448- ) ,
449- ( request_id, unit_ids. clone ( ) , unit_ids. len ( ) ) ,
450- ) ;
480+ CoordAllocated { request_id, unit_ids : unit_ids. clone ( ) , unit_count : unit_ids. len ( ) } . publish ( & env) ;
451481
452482 save_workflow (
453483 & env,
@@ -514,14 +544,7 @@ impl CoordinatorContract {
514544 wf. delivery_location = Some ( location. clone ( ) ) ;
515545 save_workflow ( & env, & wf) ;
516546
517- env. events ( ) . publish (
518- (
519- symbol_short ! ( "coord" ) ,
520- symbol_short ! ( "dlvrd" ) ,
521- symbol_short ! ( "v1" ) ,
522- ) ,
523- ( request_id, location) ,
524- ) ;
547+ CoordDelivered { request_id, location } . publish ( & env) ;
525548
526549 Ok ( ( ) )
527550 }
@@ -567,14 +590,7 @@ impl CoordinatorContract {
567590 wf. status = WorkflowStatus :: Settled ;
568591 save_workflow ( & env, & wf) ;
569592
570- env. events ( ) . publish (
571- (
572- symbol_short ! ( "coord" ) ,
573- symbol_short ! ( "settld" ) ,
574- symbol_short ! ( "v1" ) ,
575- ) ,
576- ( request_id, wf. payment_id ) ,
577- ) ;
593+ CoordSettled { request_id, payment_id : wf. payment_id } . publish ( & env) ;
578594
579595 Ok ( ( ) )
580596 }
@@ -628,14 +644,7 @@ impl CoordinatorContract {
628644 wf. status = WorkflowStatus :: RolledBack ;
629645 save_workflow ( & env, & wf) ;
630646
631- env. events ( ) . publish (
632- (
633- symbol_short ! ( "coord" ) ,
634- symbol_short ! ( "rollbk" ) ,
635- symbol_short ! ( "v1" ) ,
636- ) ,
637- request_id,
638- ) ;
647+ CoordRolledBack { request_id } . publish ( & env) ;
639648
640649 Ok ( ( ) )
641650 }
@@ -709,14 +718,7 @@ impl CoordinatorContract {
709718 expired_wf. status = WorkflowStatus :: RolledBack ;
710719 save_workflow ( & env, & expired_wf) ;
711720
712- env. events ( ) . publish (
713- (
714- symbol_short ! ( "coord" ) ,
715- symbol_short ! ( "expired" ) ,
716- symbol_short ! ( "v1" ) ,
717- ) ,
718- request_id,
719- ) ;
721+ CoordExpired { request_id } . publish ( & env) ;
720722
721723 Ok ( ( ) )
722724 }
@@ -771,10 +773,7 @@ impl CoordinatorContract {
771773 . map_err ( |_| CoordinatorError :: PaymentFlagFailed ) ?;
772774
773775 let now = env. ledger ( ) . timestamp ( ) ;
774- env. events ( ) . publish (
775- ( symbol_short ! ( "coord" ) , symbol_short ! ( "tmp_brch" ) ) ,
776- ( payment_id, excursion_summary. unit_id , now) ,
777- ) ;
776+ CoordTemperatureBreach { payment_id, unit_id : excursion_summary. unit_id , timestamp : now } . publish ( & env) ;
778777
779778 Ok ( ( ) )
780779 }
0 commit comments