Skip to content

Commit d0dc349

Browse files
s1nafjl
authored andcommitted
graphql: return correct logs for tx (#25612)
* graphql: fix tx logs * minor * Use optimized search for selecting tx logs
1 parent d901d85 commit d0dc349

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

graphql/graphql.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"errors"
2323
"fmt"
2424
"math/big"
25+
"sort"
2526
"strconv"
2627

2728
"github.com/ethereum/go-ethereum"
@@ -478,13 +479,16 @@ func (t *Transaction) getLogs(ctx context.Context) (*[]*Log, error) {
478479
if err != nil {
479480
return nil, err
480481
}
481-
ret := make([]*Log, 0, len(logs))
482-
for _, log := range logs {
482+
var ret []*Log
483+
// Select tx logs from all block logs
484+
ix := sort.Search(len(logs), func(i int) bool { return uint64(logs[i].TxIndex) == t.index })
485+
for ix < len(logs) && uint64(logs[ix].TxIndex) == t.index {
483486
ret = append(ret, &Log{
484487
r: t.r,
485488
transaction: t,
486-
log: log,
489+
log: logs[ix],
487490
})
491+
ix++
488492
}
489493
return &ret, nil
490494
}

0 commit comments

Comments
 (0)