Skip to content

neeboo/demo-apps

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lottery App

How to use

App Design

Data Model

The lottery app will show following data when it once opens the webapp:

  • players collection.

    • Each doc of players collection will have fields: email, private_key, public_key, keys_notified, result_notified, session_id.
    • email (string) is the user email specified in the email and it's required to participate into the lottery.
    • private_key and public_key (string) is generated in web server. If the player also has email in our database, we can get the keys which we generated for them before.
    • keys_notified(bool) is whether we sent the user an email of keys he/she had for the current session of the lottery.
    • result_notified (bool) is whether we sent the user an email of the result of his/her participation session.
    • session_id (number) is the session_id of that entering to the lottery.
  • session collection.

    • Each doc will have fields: deadline, is_current, id.
    • deadline (string or time) is the time point when the session ends.
    • is_current (bool) is to specify if the session is the current session.
    • id (int) is the session id.
  • winners collection:

    • Each doc will have fields: session_id, winner_public_key, amount.
    • session_id (int) is the session id.
    • winner_public_key (string) is the public key of the winner.
    • mount (int) is how much the winner won.

REST API specs

  • /current_players
    • It will returns a list of public keys.
    • For example: ['fdklsafhl32lrj23', 'fdsfsfa']
  • /previous_winners
    • It will returns a list of winners, each represented by {public_key, sessions_id, amount}.
    • For example: [{public_key: '434fdsf', session_id: 1, amount: 3}, {public_key: '434fdsf', session_id: 1, amount: 3}, ]
  • /current_session
    • If receives error or empty, meaning there is no active session.
    • Else it should return {deadline, id} where deadline is a timestamp, id is an integer.
    • For example: {deadline: 4343434343, id: 2}
  • /enter?email=xxx@gmail.com
    • If receives error or empty, meaning there is no active session.
    • Else it should return {status, message} where status can be either success or failed.
    • When the status is failed then message will be Your email has been used in this session or There is no active session.
    • When the status is success then message will be You entered in the current lottery session.
    • For example: {status: 'success', message: 'You entered in the current lottery session' }.

Front End

The Front End will take user's email and generate private/pub keypairs and save them into firebase player db. The emailKey is set to false.

BackEnd

The backend will run in two different intervals.

  • Run every 10 seconds to find the new players. Send email to new player about their private/public keys. Set the emailKey to true after sending email.

  • Run every 5 minutes (pre-defined) to pick winner by sending /winner RPC call to blockchain node (leader). Before send pickWinner call, it needs to find all the current players in this session. And find all the balances of the players. After sending the pickWinner call, it checks all the balances again, and figure out who the winner is. Send email to the winner. Write the winner pubKey and email to winners database table, transaction_id, and time.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Vue 39.5%
  • Go 26.7%
  • JavaScript 25.7%
  • HTML 4.2%
  • CSS 2.9%
  • Shell 1.0%