-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
area/apiAPI serverAPI serverarea/coreCore SDK integrationCore SDK integrationarea/infraInfrastructureInfrastructureenhancementNew feature or requestNew feature or requestpriority/p1High priorityHigh priority
Description
Overview
Implement persistent storage for transaction records and idempotency keys using SQLite.
Implementation Details
Files:
internal/storage/interface.go- Storage interfaceinternal/storage/sqlite.go- SQLite implementationinternal/middleware/idempotency.go- Idempotency middleware
Storage Interface
type Storage interface {
// Transactions
CreateTransaction(ctx, tx *TransactionRecord) error
UpdateTransaction(ctx, id string, updates map[string]interface{}) error
GetTransaction(ctx, id string) (*TransactionRecord, error)
GetTransactionByHash(ctx, txHash string) (*TransactionRecord, error)
ListTransactions(ctx, filters map[string]interface{}, limit, offset int) ([]*TransactionRecord, error)
// Idempotency
GetIdempotencyKey(ctx, key string) (*IdempotencyRecord, error)
SetIdempotencyKey(ctx, record *IdempotencyRecord) error
CleanupExpiredIdempotencyKeys(ctx) error
// Lifecycle
Close() error
Migrate(ctx) error
}Data Models
TransactionRecord:
- ID, Network, TxHash, From, To, Amount, Asset
- Status (pending, confirmed, failed)
- CreatedAt, ConfirmedAt, ErrorMessage
IdempotencyRecord:
- Key, Response, CreatedAt, ExpiresAt
SQLite Setup
- WAL mode for better concurrency
- Parameterized queries (prevent SQL injection)
- Indexes on tx_hash, status, expires_at
Idempotency Middleware
- Check
Idempotency-Keyheader on POST requests - Return cached response if key exists
- Store response after successful processing
- Set
X-Idempotency-Replayed: trueheader on replay
Acceptance Criteria
- Storage interface defined
- SQLite implementation with migrations
- Parameterized queries (no SQL injection)
- Idempotency middleware
- Cleanup job for expired keys
- Unit tests for storage operations
- Integration tests
Dependencies
- [Feature 03] API Server #22 API Server
Branch
feature/storage
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/apiAPI serverAPI serverarea/coreCore SDK integrationCore SDK integrationarea/infraInfrastructureInfrastructureenhancementNew feature or requestNew feature or requestpriority/p1High priorityHigh priority