@@ -235,24 +235,43 @@ impl ToAscPtr for MappingTrigger {
235235 }
236236}
237237
238+ #[ derive( Clone , Debug ) ]
239+ pub struct LogPosition {
240+ pub index : usize ,
241+ pub receipt : Arc < TransactionReceipt > ,
242+ pub requires_transaction_receipt : bool ,
243+ }
244+
238245#[ derive( Clone , Debug ) ]
239246pub enum LogRef {
240247 FullLog ( Arc < Log > , Option < Arc < TransactionReceipt > > ) ,
241- LogPosition ( usize , Arc < TransactionReceipt > ) ,
248+ LogPosition ( LogPosition ) ,
242249}
243250
244251impl LogRef {
245252 pub fn log ( & self ) -> & Log {
246253 match self {
247254 LogRef :: FullLog ( log, _) => log. as_ref ( ) ,
248- LogRef :: LogPosition ( index , receipt ) => receipt. logs . get ( * index) . unwrap ( ) ,
255+ LogRef :: LogPosition ( pos ) => pos . receipt . logs . get ( pos . index ) . unwrap ( ) ,
249256 }
250257 }
251258
259+ /// Returns the transaction receipt if it's available and required.
260+ ///
261+ /// For `FullLog` variants, returns the receipt if present.
262+ /// For `LogPosition` variants, only returns the receipt if the
263+ /// `requires_transaction_receipt` flag is true, otherwise returns None
264+ /// even though the receipt is stored internally.
252265 pub fn receipt ( & self ) -> Option < & Arc < TransactionReceipt > > {
253266 match self {
254267 LogRef :: FullLog ( _, receipt) => receipt. as_ref ( ) ,
255- LogRef :: LogPosition ( _, receipt) => Some ( receipt) ,
268+ LogRef :: LogPosition ( pos) => {
269+ if pos. requires_transaction_receipt {
270+ Some ( & pos. receipt )
271+ } else {
272+ None
273+ }
274+ }
256275 }
257276 }
258277
0 commit comments