@@ -159,6 +159,12 @@ pub trait PriceAggregator:
159159 let first_sub_time_mapper = self . first_submission_timestamp ( & token_pair) ;
160160 let last_sub_time_mapper = self . last_submission_timestamp ( & token_pair) ;
161161
162+ let mut round_id = 0 ;
163+ let wrapped_rounds = self . rounds ( ) . get ( & token_pair) ;
164+ if wrapped_rounds. is_some ( ) {
165+ round_id = wrapped_rounds. unwrap ( ) . len ( ) + 1 ;
166+ }
167+
162168 let current_timestamp = self . blockchain ( ) . get_block_timestamp ( ) ;
163169 let mut is_first_submission = false ;
164170 let mut first_submission_timestamp = if submissions. is_empty ( ) {
@@ -182,27 +188,32 @@ pub trait PriceAggregator:
182188
183189 first_submission_timestamp = current_timestamp;
184190 is_first_submission = true ;
191+ self . discard_round_event ( & token_pair. from . clone ( ) , & token_pair. to . clone ( ) , round_id)
185192 }
186193
187194 let caller = self . blockchain ( ) . get_caller ( ) ;
188- let accepted = !submissions. contains_key ( & caller)
195+ let has_caller_already_submitted = submissions. contains_key ( & caller) ;
196+ let accepted = !has_caller_already_submitted
189197 && ( is_first_submission || submission_timestamp >= first_submission_timestamp) ;
190198 if accepted {
191199 submissions. insert ( caller. clone ( ) , price. clone ( ) ) ;
192200 last_sub_time_mapper. set ( current_timestamp) ;
193201
194- let mut round_id = 0 ;
195- let wrapped_rounds = self . rounds ( ) . get ( & token_pair) ;
196- if wrapped_rounds. is_some ( ) {
197- round_id = wrapped_rounds. unwrap ( ) . len ( ) + 1 ;
198- }
199202 self . create_new_round ( token_pair. clone ( ) , round_id, submissions, decimals) ;
200203 self . add_submission_event (
201204 & token_pair. from . clone ( ) ,
202205 & token_pair. to . clone ( ) ,
203206 round_id,
204207 & price,
205208 ) ;
209+ } else {
210+ self . emit_discard_submission_event (
211+ & token_pair,
212+ round_id,
213+ submission_timestamp,
214+ first_submission_timestamp,
215+ has_caller_already_submitted,
216+ ) ;
206217 }
207218
208219 self . oracle_status ( )
@@ -299,8 +310,6 @@ pub trait PriceAggregator:
299310 . get ( )
300311 . push ( & price_feed) ;
301312 self . emit_new_round_event ( & token_pair, round_id, & price_feed) ;
302- } else {
303- self . discard_round_event ( & token_pair. from . clone ( ) , & token_pair. to . clone ( ) , round_id) ;
304313 }
305314 }
306315
0 commit comments