Skip to content

Commit

Permalink
graphql: return correct logs for tx (#25612)
Browse files Browse the repository at this point in the history
* graphql: fix tx logs

* minor

* Use optimized search for selecting tx logs
  • Loading branch information
s1na authored and fjl committed Sep 13, 2022
1 parent d901d85 commit d0dc349
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"math/big"
"sort"
"strconv"

"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -478,13 +479,16 @@ func (t *Transaction) getLogs(ctx context.Context) (*[]*Log, error) {
if err != nil {
return nil, err
}
ret := make([]*Log, 0, len(logs))
for _, log := range logs {
var ret []*Log
// Select tx logs from all block logs
ix := sort.Search(len(logs), func(i int) bool { return uint64(logs[i].TxIndex) == t.index })
for ix < len(logs) && uint64(logs[ix].TxIndex) == t.index {
ret = append(ret, &Log{
r: t.r,
transaction: t,
log: log,
log: logs[ix],
})
ix++
}
return &ret, nil
}
Expand Down

0 comments on commit d0dc349

Please sign in to comment.