1- use soroban_sdk:: { Address , Bytes , Env , Symbol } ;
1+ use soroban_sdk:: { contractevent , Address , Bytes , Env } ;
22
33use crate :: types:: { ProposalStatus , ProposalType , VoteDirection } ;
44
5+ #[ contractevent]
6+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
7+ pub struct ProposalCreatedEvent {
8+ pub proposal_id : u64 ,
9+ pub proposer : Address ,
10+ pub title : Bytes ,
11+ pub proposal_type : ProposalType ,
12+ }
13+
14+ #[ contractevent]
15+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
16+ pub struct VoteCastEvent {
17+ pub proposal_id : u64 ,
18+ pub voter : Address ,
19+ pub direction : VoteDirection ,
20+ pub power : i128 ,
21+ }
22+
23+ #[ contractevent]
24+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
25+ pub struct ProposalStatusChangedEvent {
26+ pub proposal_id : u64 ,
27+ pub old_status : ProposalStatus ,
28+ pub new_status : ProposalStatus ,
29+ }
30+
31+ #[ contractevent]
32+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
33+ pub struct ProposalExecutedEvent {
34+ pub proposal_id : u64 ,
35+ pub executor : Address ,
36+ }
37+
38+ #[ contractevent]
39+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
40+ pub struct ProposalCancelledEvent {
41+ pub proposal_id : u64 ,
42+ pub cancelled_by : Address ,
43+ }
44+
45+ #[ contractevent]
46+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
47+ pub struct ConfigUpdatedEvent {
48+ pub admin : Address ,
49+ }
50+
551/// Emitted when a new proposal is created
652pub fn proposal_created (
753 env : & Env ,
@@ -10,9 +56,13 @@ pub fn proposal_created(
1056 title : & Bytes ,
1157 proposal_type : & ProposalType ,
1258) {
13- let topics = ( Symbol :: new ( env, "proposal_created" ) , proposer) ;
14- env. events ( )
15- . publish ( topics, ( proposal_id, title. clone ( ) , proposal_type. clone ( ) ) ) ;
59+ ProposalCreatedEvent {
60+ proposal_id,
61+ proposer : proposer. clone ( ) ,
62+ title : title. clone ( ) ,
63+ proposal_type : proposal_type. clone ( ) ,
64+ }
65+ . publish ( env) ;
1666}
1767
1868/// Emitted when a vote is cast
@@ -23,9 +73,13 @@ pub fn vote_cast(
2373 direction : & VoteDirection ,
2474 power : i128 ,
2575) {
26- let topics = ( Symbol :: new ( env, "vote_cast" ) , voter) ;
27- env. events ( )
28- . publish ( topics, ( proposal_id, direction. clone ( ) , power) ) ;
76+ VoteCastEvent {
77+ proposal_id,
78+ voter : voter. clone ( ) ,
79+ direction : direction. clone ( ) ,
80+ power,
81+ }
82+ . publish ( env) ;
2983}
3084
3185/// Emitted when a proposal status changes
@@ -35,27 +89,36 @@ pub fn proposal_status_changed(
3589 old_status : & ProposalStatus ,
3690 new_status : & ProposalStatus ,
3791) {
38- let topics = ( Symbol :: new ( env, "proposal_status" ) , ) ;
39- env. events ( ) . publish (
40- topics,
41- ( proposal_id, old_status. clone ( ) , new_status. clone ( ) ) ,
42- ) ;
92+ ProposalStatusChangedEvent {
93+ proposal_id,
94+ old_status : old_status. clone ( ) ,
95+ new_status : new_status. clone ( ) ,
96+ }
97+ . publish ( env) ;
4398}
4499
45100/// Emitted when a proposal is executed
46101pub fn proposal_executed ( env : & Env , proposal_id : u64 , executor : & Address ) {
47- let topics = ( Symbol :: new ( env, "proposal_executed" ) , executor) ;
48- env. events ( ) . publish ( topics, proposal_id) ;
102+ ProposalExecutedEvent {
103+ proposal_id,
104+ executor : executor. clone ( ) ,
105+ }
106+ . publish ( env) ;
49107}
50108
51109/// Emitted when a proposal is cancelled
52110pub fn proposal_cancelled ( env : & Env , proposal_id : u64 , cancelled_by : & Address ) {
53- let topics = ( Symbol :: new ( env, "proposal_cancelled" ) , cancelled_by) ;
54- env. events ( ) . publish ( topics, proposal_id) ;
111+ ProposalCancelledEvent {
112+ proposal_id,
113+ cancelled_by : cancelled_by. clone ( ) ,
114+ }
115+ . publish ( env) ;
55116}
56117
57118/// Emitted when governance configuration is updated
58119pub fn config_updated ( env : & Env , admin : & Address ) {
59- let topics = ( Symbol :: new ( env, "config_updated" ) , admin) ;
60- env. events ( ) . publish ( topics, ( ) ) ;
120+ ConfigUpdatedEvent {
121+ admin : admin. clone ( ) ,
122+ }
123+ . publish ( env) ;
61124}
0 commit comments