-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: locate log within receipt using logIndex
Log.LogIndex is indexed at the block level, so it's incorrect to locate a log using receipt.Logs[log.LogIndex]. Instead, we should traverse through receipt.Logs and find the matching log based on log.LogIndex.
- Loading branch information
1 parent
494b941
commit a601215
Showing
2 changed files
with
43 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package core | ||
|
||
import "github.com/ethereum/go-ethereum/core/types" | ||
|
||
// GetLogByLogIndex searches through receipt.Logs using the provided logIndex and return the corresponding log. | ||
// | ||
// Be aware that: | ||
// - Log.Index is accumulated for the entire block. | ||
// - There is no guarantee that receipt.Logs will be ordered by index. | ||
func GetLogByLogIndex(receipt *types.Receipt, logIndex uint) *types.Log { | ||
if receipt == nil { | ||
return nil | ||
} | ||
|
||
for _, vlog := range receipt.Logs { | ||
if vlog.Index == logIndex { | ||
return vlog | ||
} | ||
} | ||
return nil | ||
} |