🗳️ WinVote API

Cloudflare Worker API for managing WinVote proposals using D1 database.

✨ New: Automatic Block-to-Time Conversion
The API now automatically converts Ethereum block numbers to timestamps when creating proposals. It fetches the current block from eth.llamarpc.com and calculates time_start/time_end based on 12-second block times. You can still override with manual timestamps if needed.

Available Endpoints

GET /health
Health check endpoint
GET /api/winvote/proposals
Get all proposals with computed fields (time_left_seconds, is_active, progress_percent).
Query params: ?status=active, ?limit=50, ?offset=0
POST /api/winvote/proposals requires x-api-key
Create or update a proposal. The API automatically converts start_block and end_block to timestamps.

Required fields: proposal_id, title, proposer, start_block, end_block

Optional: You can override automatic time calculation by providing time_start and time_end in ISO format.
POST /api/winvote/archive requires x-api-key
Archive proposals older than 7 days. Optionally specify {"beforeDate": "2025-01-01"}
POST /create-tables requires x-api-key
Create database tables (winvote_proposals, winvote_archive) with indexes and triggers.
Add ?test=true to insert test data with realistic block numbers.

Authentication

POST endpoints require an x-api-key header with the correct API key.

Response Format

All endpoints return JSON responses with success: true/false and relevant data.