feat(idea/vara-eth/backend): prepare for indexing injected transactions#2478
feat(idea/vara-eth/backend): prepare for indexing injected transactions#2478osipov-mit wants to merge 11 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the InjectedTransactionsModule and performs a significant refactor across the explorer and indexer to use bytea database columns (represented via PgByteaString) for hex data. Key changes include the addition of the InjectedTransaction entity, a new ParseByteaPipe for hex validation, and the standardization of response DTOs using class-transformer. Feedback identifies a critical need to lowercase hex strings in toBytea for consistent PostgreSQL comparisons and points out a type mismatch for the nullable valueToReceive field. Additionally, the removal of the order field from PaginationDto is flagged as a breaking API change, and it is recommended that the ParseByteaPipe include explicit hex validation to prevent database errors.
| import { Transform } from 'class-transformer'; | ||
|
|
||
| // TODO: consider moving these functions to a separate `common` package | ||
| export const toBytea = (hex: string): PgByteaString => `\\x${hex.replace(/^0x/i, '')}` as PgByteaString; |
There was a problem hiding this comment.
The toBytea function should convert the hex string to lowercase. The indexer stores these values as lowercased hex strings in the bytea columns. Since bytea comparisons in PostgreSQL are binary, a case mismatch (e.g., \xABC vs \xabc) will result in failed lookups.
| export const toBytea = (hex: string): PgByteaString => `\\x${hex.replace(/^0x/i, '')}` as PgByteaString; | |
| export const toBytea = (hex: string): PgByteaString => "\\x" + hex.replace(/^0x/i, '').toLowerCase() as PgByteaString; |
| program?: Program; | ||
|
|
||
| @Column({ type: 'bigint', name: 'value_to_receive', nullable: true }) | ||
| valueToReceive: bigint; |
There was a problem hiding this comment.
The valueToReceive property is marked as nullable: true in the @column decorator, but the TypeScript type does not reflect this. It should be bigint | null to ensure type safety when handling null values from the database.
| valueToReceive: bigint; | |
| valueToReceive: bigint | null; |
| @IsOptional() | ||
| @IsIn(['asc', 'desc']) | ||
| order?: 'asc' | 'desc' = 'desc'; | ||
| } |
There was a problem hiding this comment.
The removal of the order field from PaginationDto is a breaking change for the API. It removes the ability for clients to specify a custom sort order (asc/desc), which was previously supported across multiple endpoints. If this was intentional, ensure that the API documentation is updated to reflect that sorting is now hardcoded to DESC.
| transform(value: string): PgByteaString { | ||
| return toBytea(value); | ||
| } |
There was a problem hiding this comment.
The ParseByteaPipe should validate that the input string is a valid hexadecimal string before calling toBytea. Passing an invalid hex string will result in a malformed bytea literal (e.g., \xZZZ), which will cause a database error and likely return a 500 Internal Server Error instead of a 400 Bad Request.
No description provided.