Skip to main content
MAIN CHAIN

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

EndpointDescriptionRPC Method Used
listproducerList all BPoS validators with vote rateslistproducers
producerstatusGet producer status by public keylistproducers
votestatusGet voting status for an addressInternal query
getdepositcoinGet producer deposit amountgetdepositcoin

Elastos Council Election Endpoints

EndpointDescriptionRPC Method Used
listcrcandidatesList all Elastos Council candidateslistcrcandidates
listcurrentcrsList elected Elastos Council memberslistcurrentcrs
getcrdepositcoinGet Elastos Council member deposit amountgetcrdepositcoin

DID Identity Endpoints

EndpointDescriptionStorage
adddidinfoCreate DID identity profileMySQL didinfo table
updatedidinfoUpdate DID identity profileMySQL didinfo table
getdidinfoRetrieve DID identity profileMySQL didinfo table

Authentication Endpoints

EndpointDescriptionStorage
jwtsaveSave DID-authenticated JWTMySQL didtoken table
jwtgetRetrieve saved JWTMySQL didtoken table

Utility Endpoints

EndpointDescription
getimageProxy 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.json with 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:

ColumnTypeDescription
didVARCHARPrimary key (Elastos DID)
nameVARCHARDisplay name
emailVARCHAREmail address
countryVARCHARCountry
social_accountsTEXTJSON of social media links

didtoken table:

ColumnTypeDescription
didVARCHARElastos DID
tokenTEXTJWT token
created_atTIMESTAMPToken creation time