Git Product home page Git Product logo

survey_money's Introduction

Survey Money

APIs of the application

Functions

createSurvey(string question, string[] answers, uint256 expiration_time, uint256 response_cap, uint256 pooled_reward)

Creates a survey and adds the survey to the survey list. Returns true if the survey creation was successful and false otherwise.

register(String username)

Registers the caller if they are not already a registered user. If the username or address is already registered, return false. Returns true if the user was successfully registered.

surveyRespond(int surveyId, int answer)

People who wish to partipate in a survey do so using surveyRespond(). They input the surveyId of the survey they wish to respond to, as well as one of the numerical options they can respond with. The survey records the answer and increments the corresponding value in the survey's list of response counts. Each user can only respond to a survey once.

If someone successfully responds to a survey, return true. Else, if the user has already responded to the survey, the survey is not active, or the user did not input a valid response, return false.

getOwnSurveys()

As long as a registered user is logged in, they can call this function. getOwnSurveys() returns a list of survey IDs for each survey they own.

getActiveSurveys()

Gets a list of all survey IDs for currently active surveys.

getAnswerOptions(int surveyId)

Returns a string of all the answer options for the survey corresponding to the surveyId.

getSurveyQuestion(uint256 surveyId)

Returns the question of the survey that corresponds to the surveyId.

closeSurvey(int surveyId)

Closes survey, which is only allowed if the survey belongs to the caller and is not already closed, returns true if successfully closed. Return false if the survey does not successfully close.

addBalance()

Can only be called by a registered user. This function allows a user to deposit ETH from their personal balance into the global balance mapping of their address. This ETH is used to pay for creating surveys. The minimum deposit amount is 1 ether. Returns true if successful.

withdraw()

This withdraws all ETH from the global balance mapping of their address and deposits it back to their personal balance.

Global data

mapping(address => account): registeredUsers

Returns the account associated with the address of a registered user

mapping(uint256 => survey): surveyById

Returns the survey associated with its survey ID

mapping(address=>bool) isRegistered

Returns whether or not an address belongs to a registered user

mapping(string=>bool) isNameTaken

Returns whether or not a username is already taken

Survey[]: activeSurveys

The list of currently active surveys

uint256: HOST_CUT

The constant amount that the admin takes for each created survey.

Security notes

We also added various checks in place to ensure that participants can not exploit the survey reward system by voting multiple times, voting in their own surveys, unauthorized withdraw of balances, and more. A more comprehensive depiction of our security measures can be found in our security test cases.

How to set up the environment and initialize the application

In order to run this application, the user must have Foundry installed, which can be done by following the steps here. The user can run the tests written for the application in a Linux environment by going to the directory that contains this program, then running

$forge test

What kinds of components there are, and what they do

Account

When a user registers for an account, the application creates an Account data structure that contains their address, account name, and a list of IDs of all currently active surveys they have created.

Survey

Each survey is managed by its own survey data structure, which contains the address of the survey owner, the survey ID, its question and answer options, the maximum time and responses, and the pooled reward the survey owner has set. Each survey also keeps track of which blockchain addresses have responded, and how many votes each answer option has gotten.

What kinds of roles users can play, and what they can do

Anyone with a blockchain address can vote in surveys, but without being a registered user, they can not create any. Survey participants will also receive a reward of ETH for participating in a survey. The amount they receive is determined by the survey owner. Registered users can create surveys as well as vote in them. Users can also determine how much ETH they intend to reward participants of their survey.

survey_money's People

Contributors

cantbelieveimshook avatar r0ckwav3 avatar rytuose avatar blakerandle 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.