Code Monkey home page Code Monkey logo

demo-apps's Introduction

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}
  • /[email protected]
    • 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.

demo-apps's People

Contributors

0xqd avatar alajko avatar chaosma avatar daywednes avatar katienza avatar leland-kwong avatar lzl124631x avatar mikedoan avatar pr2a avatar rlan35 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.