From 386079bf906550dfe66dfd7b3ab239d9e0b11b87 Mon Sep 17 00:00:00 2001 From: Francisco Moura Date: Mon, 2 Sep 2024 21:56:27 -0300 Subject: [PATCH] fixup! feat(evm-reader): Read claim acceptance --- internal/repository/base.go | 65 -------------------------------- internal/repository/validator.go | 57 +++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 66 deletions(-) diff --git a/internal/repository/base.go b/internal/repository/base.go index d05c1e1ac..822909dae 100644 --- a/internal/repository/base.go +++ b/internal/repository/base.go @@ -477,71 +477,6 @@ func (pg *Database) GetEpoch( } -// getEpochsByStatus returns epochs from the application with the given status. -// Epochs are returned in ascending order by index. -func (pg *Database) getEpochsByStatus( - ctx context.Context, - application Address, - criteria EpochStatus, -) ([]Epoch, error) { - query := ` - SELECT - id, - application_address, - index, - first_block, - last_block, - claim_hash, - transaction_hash, - status - FROM - epoch - WHERE - application_address=@appAddress AND status=@status - ORDER BY - index ASC` - - args := pgx.NamedArgs{ - "appAddress": application, - "status": criteria, - } - - rows, err := pg.db.Query(ctx, query, args) - if err != nil { - return nil, fmt.Errorf("GetProcessedEpochs failed: %w", err) - } - - var ( - id, index, firstBlock, lastBlock uint64 - appAddress Address - claimHash, transactionHash *Hash - status string - results []Epoch - ) - - scans := []any{ - &id, &appAddress, &index, &firstBlock, &lastBlock, &claimHash, &transactionHash, &status, - } - _, err = pgx.ForEachRow(rows, scans, func() error { - epoch := Epoch{ - Id: id, - Index: index, - AppAddress: appAddress, - FirstBlock: firstBlock, - LastBlock: lastBlock, - ClaimHash: claimHash, - TransactionHash: transactionHash, - Status: EpochStatus(status), - } - results = append(results, epoch) - return nil - }) - if err != nil { - return nil, fmt.Errorf("GetProcessedEpochs failed: %w", err) - } - return results, nil -} - func (pg *Database) GetInput( ctx context.Context, indexKey uint64, diff --git a/internal/repository/validator.go b/internal/repository/validator.go index aed7d5b4a..8a9989368 100644 --- a/internal/repository/validator.go +++ b/internal/repository/validator.go @@ -79,7 +79,62 @@ func (pg *Database) GetOutputsProducedInBlockRange( // GetProcessedEpochs returns epochs from the application which had all // its inputs processed. Epochs are returned in ascending order by index. func (pg *Database) GetProcessedEpochs(ctx context.Context, application Address) ([]Epoch, error) { - return pg.getEpochsByStatus(ctx, application, EpochStatusProcessedAllInputs) + query := ` + SELECT + id, + application_address, + index, + first_block, + last_block, + claim_hash, + transaction_hash, + status + FROM + epoch + WHERE + application_address=@appAddress AND status=@status + ORDER BY + index ASC` + + args := pgx.NamedArgs{ + "appAddress": application, + "status": EpochStatusProcessedAllInputs, + } + + rows, err := pg.db.Query(ctx, query, args) + if err != nil { + return nil, fmt.Errorf("GetProcessedEpochs failed: %w", err) + } + + var ( + id, index, firstBlock, lastBlock uint64 + appAddress Address + claimHash, transactionHash *Hash + status string + results []Epoch + ) + + scans := []any{ + &id, &appAddress, &index, &firstBlock, &lastBlock, &claimHash, &transactionHash, &status, + } + _, err = pgx.ForEachRow(rows, scans, func() error { + epoch := Epoch{ + Id: id, + Index: index, + AppAddress: appAddress, + FirstBlock: firstBlock, + LastBlock: lastBlock, + ClaimHash: claimHash, + TransactionHash: transactionHash, + Status: EpochStatus(status), + } + results = append(results, epoch) + return nil + }) + if err != nil { + return nil, fmt.Errorf("GetProcessedEpochs failed: %w", err) + } + return results, nil } // GetLastInputOutputsHash returns the outputs Merkle tree hash calculated