Skip to content

Commit

Permalink
reset to 0 eventCount and transferCount each receipt and write blockI…
Browse files Browse the repository at this point in the history
…d only once
  • Loading branch information
paologalligit committed Nov 7, 2024
1 parent 57e4540 commit fbca57e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions logdb/logdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,6 @@ func (w *Writer) Write(b *block.Block, receipts tx.Receipts) error {
blockNum = b.Header().Number()
blockTimestamp = b.Header().Timestamp()
txs = b.Transactions()
eventCount,
transferCount uint32
isReceiptEmpty = func(r *tx.Receipt) bool {
for _, o := range r.Outputs {
if len(o.Events) > 0 || len(o.Transfers) > 0 {
Expand All @@ -456,18 +454,23 @@ func (w *Writer) Write(b *block.Block, receipts tx.Receipts) error {
}
)

writeBlockId := true

for i, r := range receipts {
eventCount, transferCount := uint32(0), uint32(0)

if isReceiptEmpty(r) {
continue
}

if eventCount == 0 && transferCount == 0 {
if writeBlockId {
// block id is not yet inserted
if err := w.exec(
"INSERT OR IGNORE INTO ref(data) VALUES(?)",
blockID[:]); err != nil {
return err
}
writeBlockId = false
}

var (
Expand Down
5 changes: 3 additions & 2 deletions logdb/logdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestEvents(t *testing.T) {
origin, _ := tx.Origin()
allEvents = append(allEvents, &Event{
BlockNumber: b.Header().Number(),
Index: uint32(j),
Index: uint32(0),
TxIndex: uint32(j),
BlockID: b.Header().ID(),
BlockTime: b.Header().Timestamp(),
Expand All @@ -160,7 +160,8 @@ func TestEvents(t *testing.T) {

allTransfers = append(allTransfers, &Transfer{
BlockNumber: b.Header().Number(),
Index: uint32(j),
Index: uint32(0),
TxIndex: uint32(j),
BlockID: b.Header().ID(),
BlockTime: b.Header().Timestamp(),
TxID: tx.ID(),
Expand Down

0 comments on commit fbca57e

Please sign in to comment.