Skip to content

Commit

Permalink
fixup! feat(evm-reader): Read claim acceptance
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoura committed Sep 3, 2024
1 parent 429c3eb commit 386079b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 66 deletions.
65 changes: 0 additions & 65 deletions internal/repository/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
57 changes: 56 additions & 1 deletion internal/repository/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 386079b

Please sign in to comment.