diff --git a/internal/repository/base.go b/internal/repository/base.go index d05c1e1a..822909da 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 aed7d5b4..8a998936 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