Unverified Commit 8cfcb41e authored by Sina Mahmoodi's avatar Sina Mahmoodi Committed by GitHub

graphql: return correct logs for tx (#25612)

* graphql: fix tx logs

* minor

* Use optimized search for selecting tx logs
parent 279afd79
...@@ -22,6 +22,7 @@ import ( ...@@ -22,6 +22,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"math/big" "math/big"
"sort"
"strconv" "strconv"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
...@@ -478,13 +479,16 @@ func (t *Transaction) getLogs(ctx context.Context) (*[]*Log, error) { ...@@ -478,13 +479,16 @@ func (t *Transaction) getLogs(ctx context.Context) (*[]*Log, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
ret := make([]*Log, 0, len(logs)) var ret []*Log
for _, log := range logs { // 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{ ret = append(ret, &Log{
r: t.r, r: t.r,
transaction: t, transaction: t,
log: log, log: logs[ix],
}) })
ix++
} }
return &ret, nil return &ret, nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment