feat: create schema and service for managing UTXOs#504
feat: create schema and service for managing UTXOs#504GabrielTozatti wants to merge 2 commits intostagingfrom
Conversation
| ): Promise<GaslessUtxo | null> => { | ||
| const { reservedBy, ttlSeconds = DEFAULT_TTL_SECONDS } = options; | ||
|
|
||
| return collection.findOneAndUpdate( |
There was a problem hiding this comment.
🟡 IMPORTANT: Missing TTL cleanup mechanism
Problem: Reserved UTXOs with expired TTL will remain stuck in 'reserved' status forever, causing resource leaks. The reservedAt timestamp is set but never used for cleanup.
Suggestion: Add a cleanup method that finds expired reservations: { status: 'reserved', reservedAt: { $lt: new Date(Date.now() - ttlSeconds * 1000) } } and sets them back to 'available'.
| utxoId: string, | ||
| spentTxHash: string | ||
| ): Promise<GaslessUtxo | null> => { | ||
| return collection.findOneAndUpdate( |
There was a problem hiding this comment.
🟡 IMPORTANT: Missing input validation
Problem: utxoId and spentTxHash parameters are not validated. Empty strings or invalid formats could cause issues.
Suggestion: Add validation: if (!utxoId?.trim() || !spentTxHash?.trim()) throw new Error('Invalid parameters');
| }); | ||
|
|
||
| export * from './types'; | ||
| export * from './constants'; No newline at end of file |
There was a problem hiding this comment.
🔵 SUGGESTION: Missing newline at end of file
Problem: File should end with a newline character for consistency.
Suggestion: Add a newline at the end of the file.
guimroque
left a comment
There was a problem hiding this comment.
Code Review
Summary
This PR creates a well-structured UTXO management service for gasless transactions with proper atomic operations and clear separation of concerns. The implementation follows Worker standards and includes comprehensive CRUD operations.
Strengths
- Atomic operations using findOneAndUpdate prevent race conditions
- Clean separation of concerns with utils functions
- Proper TypeScript interfaces and exports
- Comprehensive stats aggregation functionality
Issues
- 0 critical, 2 important, 1 suggestion
guimroque
left a comment
There was a problem hiding this comment.
LGTM! ✅
Previous issues have been fixed. Code approved.
Description
Create schema and service for managing gasless UTXOs in the Worker. This includes the collection, interface, and all required atomic methods.
Summary
Checklist