@@ -26,15 +26,24 @@ pub struct FeeDistributedEvent {
2626 pub pool_id : u64 ,
2727 pub fee : i128 ,
2828}
29+ #[ contractevent]
30+ pub struct PoolCreatedEvent {
31+ pub pool_id : u64 ,
32+ pub creator : Address ,
33+ pub end_time : u64 ,
34+ }
2935
3036#[ contracttype]
3137#[ derive( Clone ) ]
3238pub struct Pool {
39+ pub creator : Address , // Added for auth/tracking
3340 pub end_time : u64 ,
3441 pub resolved : bool ,
3542 pub outcome : u32 ,
3643 pub token : Address ,
3744 pub total_stake : i128 ,
45+ pub category : soroban_sdk:: Symbol ,
46+ pub options_count : u32 , // To validate outcomes later
3847}
3948
4049#[ contracttype]
@@ -151,32 +160,61 @@ impl PredifiContract {
151160 ///
152161 /// # Errors
153162 /// * `EndTimeMustBeFuture` - If end_time is not in the future
154- pub fn create_pool ( env : Env , end_time : u64 , token : Address ) -> Result < u64 , PrediFiError > {
155- // Validate end_time is in the future
163+ /// Create a new prediction pool.
164+ pub fn create_pool (
165+ env : Env ,
166+ creator : Address ,
167+ end_time : u64 ,
168+ token : Address ,
169+ category : soroban_sdk:: Symbol ,
170+ options_count : u32 ,
171+ ) -> Result < u64 , PrediFiError > {
172+ // 1. Authorization
173+ creator. require_auth ( ) ;
174+
175+ // 2. Validate Parameters
156176 let current_time = env. ledger ( ) . timestamp ( ) ;
157177 if end_time <= current_time {
158178 return Err ( PrediFiError :: EndTimeMustBeFuture ) ;
159179 }
160180
181+ if options_count < 2 {
182+ return Err ( PrediFiError :: InvalidOptionsCount ) ;
183+ }
184+
185+ // 3. Generate Unique ID
161186 let pool_id: u64 = env
162187 . storage ( )
163188 . instance ( )
164189 . get ( & DataKey :: PoolIdCounter )
165190 . unwrap_or ( 0 ) ;
166191
192+ // 4. Initialize Pool with ALL fields
167193 let pool = Pool {
194+ creator : creator. clone ( ) , // Field added here
168195 end_time,
169196 resolved : false ,
170197 outcome : 0 ,
171- total_stake : 0 ,
172198 token,
199+ total_stake : 0 ,
200+ category : category. clone ( ) , // Field added here
201+ options_count, // Field added here
173202 } ;
174203
204+ // 5. Save State
175205 env. storage ( ) . instance ( ) . set ( & DataKey :: Pool ( pool_id) , & pool) ;
176206 env. storage ( )
177207 . instance ( )
178208 . set ( & DataKey :: PoolIdCounter , & ( pool_id + 1 ) ) ;
179209
210+ // 6. Emit Event
211+ PoolCreatedEvent {
212+ pool_id,
213+ creator,
214+ end_time,
215+ }
216+ . publish ( & env) ;
217+
180218 Ok ( pool_id)
181219 }
182220
0 commit comments