Election Data API
Elastos.Service.Election
Repository: Elastos.Service.Election
This service acts as a middleware between the ELA blockchain and frontend applications, providing REST API access to election and governance data.
Architecture
┌──────────────────────────────────────────────────────┐
│ Elastos.Service.Election │
│ │
│ Express.js API │
│ Base path: /api/dposnoderpc/check/ │
│ │
│ ┌──────────┐ ┌──────────┐ ┌─────────────────┐ │
│ │ JSON-RPC │ │ MySQL │ │ Python Scripts │ │
│ │(ELA Node)│ │(crinfo) │ │(scheduled tasks)│ │
│ └──────────┘ └──────────┘ └─────────────────┘ │
│ │
│ Scheduled: Every 4 hours (0:01, 4:01, 8:01, ...) │
│ PM2 process management │
└──────────────────────────────────────────────────────┘
API Endpoints
All endpoints use POST method at base path /api/dposnoderpc/check/.
BPoS Validator Endpoints
| Endpoint | Description | RPC Method Used |
|---|---|---|
listproducer | List all BPoS validators with vote rates | listproducers |
producerstatus | Get producer status by public key | listproducers |
votestatus | Get voting status for an address | Internal query |
getdepositcoin | Get producer deposit amount | getdepositcoin |
Elastos Council Election Endpoints
| Endpoint | Description | RPC Method Used |
|---|---|---|
listcrcandidates | List all Elastos Council candidates | listcrcandidates |
listcurrentcrs | List elected Elastos Council members | listcurrentcrs |
getcrdepositcoin | Get Elastos Council member deposit amount | getcrdepositcoin |
DID Identity Endpoints
| Endpoint | Description | Storage |
|---|---|---|
adddidinfo | Create DID identity profile | MySQL didinfo table |
updatedidinfo | Update DID identity profile | MySQL didinfo table |
getdidinfo | Retrieve DID identity profile | MySQL didinfo table |
Authentication Endpoints
| Endpoint | Description | Storage |
|---|---|---|
jwtsave | Save DID-authenticated JWT | MySQL didtoken table |
jwtget | Retrieve saved JWT | MySQL didtoken table |
Utility Endpoints
| Endpoint | Description |
|---|---|
getimage | Proxy image downloads |
Vote Rate Calculation
The modifyOriginalData() function in routes/dposnodeCheck.js calculates vote rates:
1. totalVotes = sum of all producer votes (from listproducers RPC)
2. voterate = producerVotes / totalVotes (15 decimal precision)
3. blockCount = current block height
4. Exclude 8 special addresses (foundation, burn, etc.)
5. totalvoterate = elaUsed / (33M + blockHeight * 5.02283105 - excludedAmounts)
The 5.02283105 constant represents the approximate ELA issued per block during the pre-halving era (33M initial supply x 4% annual / 262,800 blocks per year). After each halving event, the per-block issuance decreases. Verify the current era's constant against the chain's actual block reward.
Scheduled Tasks
A Python script runs every 4 hours via schedule/timeTask.js:
- Generates
elaIndex.jsonwith aggregate statistics - Fields:
uniqueVoters,elaUsed,totalVotes - Schedule: 0:01, 4:01, 8:01, 12:01, 16:01, 20:01
Database Schema
MySQL database: crinfo
didinfo table:
| Column | Type | Description |
|---|---|---|
did | VARCHAR | Primary key (Elastos DID) |
name | VARCHAR | Display name |
email | VARCHAR | Email address |
country | VARCHAR | Country |
social_accounts | TEXT | JSON of social media links |
didtoken table:
| Column | Type | Description |
|---|---|---|
did | VARCHAR | Elastos DID |
token | TEXT | JWT token |
created_at | TIMESTAMP | Token creation time |