# Disp41r Super Voting System ## call functions * new(title : String,time : u32): the new function can start a voting, you need to input the title of voting and deadline of voting, time means how many minutes will the voting over. ``` near call disv.testnet new '{"title":",most creative","time":30}' --accountId disv.testnet ``` * add_candidate(candidate): this function is to add the candidate ``` root@iZbp1i18irje02nxov4qfsZ:~# near call disv.testnet add_candidate '{"candidate":"Disp41r"}' --accountId dispa1r.testnet Scheduling a call: disv.testnet.add_candidate({"candidate":"Disp41r"}) Doing account.functionCall() Transaction Id 9xkwKZ7oUbvPWPFLtrtJJn9hJzUzwnM9XGnbSwe777xs To see the transaction in the transaction explorer, please open this url in your browser https://explorer.testnet.near.org/transactions/9xkwKZ7oUbvPWPFLtrtJJn9hJzUzwnM9XGnbSwe777xs 'Success to add the candidate!' ``` * vote_without_near(name):this funtion is to vote without deposit near, and it can add 1 count for the candidate, of course each people only have one chance to vote. ``` oot@iZbp1i18irje02nxov4qfsZ:~# near call disv.testnet vote_without_near '{"name":"Disp41r"}' --accountId dispa1r.testnet Scheduling a call: disv.testnet.vote_without_near({"name":"Disp41r"}) Doing account.functionCall() Transaction Id FZaU3BYq4aJWvgjgyU4PbgqyH2mvzP4XMpeH37x4KrTJ To see the transaction in the transaction explorer, please open this url in your browser https://explorer.testnet.near.org/transactions/FZaU3BYq4aJWvgjgyU4PbgqyH2mvzP4XMpeH37x4KrTJ 'success to vote!' root@iZbp1i18irje02nxov4qfsZ:~# near call disv.testnet vote_without_near '{"name":"Disp41r"}' --accountId dispa1r.testnet Scheduling a call: disv.testnet.vote_without_near({"name":"Disp41r"}) Doing account.functionCall() Transaction Id DPoNRaLSxURxkByFa5qf8Ni8mR6oXJAMkfV4rpmG4jT3 To see the transaction in the transaction explorer, please open this url in your browser https://explorer.testnet.near.org/transactions/DPoNRaLSxURxkByFa5qf8Ni8mR6oXJAMkfV4rpmG4jT3 'you have voted, anyone only have one time' ``` * vote_with_near(name): this function allow people to vote with near, one near for one extra count :) ``` root@iZbp1i18irje02nxov4qfsZ:~# near call disv.testnet vote_with_near '{"name":"Disp41r"}' --accountId dis.testnet --amount 3 Scheduling a call: disv.testnet.vote_with_near({"name":"Disp41r"}) with attached 3 NEAR Doing account.functionCall() Transaction Id HWCBWLMozwemhxuL2y2PEGV4JJ4kfE3r2cfzZAxNkidy To see the transaction in the transaction explorer, please open this url in your browser https://explorer.testnet.near.org/transactions/HWCBWLMozwemhxuL2y2PEGV4JJ4kfE3r2cfzZAxNkidy 'thx for your near, your candidate will get more support :)' ``` * check_my_vote(): you can check who you have voted for, for privacy, everyone could only check their selves voting :) ``` root@iZbp1i18irje02nxov4qfsZ:~# near call disv.testnet check_my_vote '' --accountId dispa1r.testnet Scheduling a call: disv.testnet.check_my_vote() Doing account.functionCall() Transaction Id 3gWDsaAVKeUvjdJdpXxkhwtsno93qBY4Qf7q8vhp41FT To see the transaction in the transaction explorer, please open this url in your browser https://explorer.testnet.near.org/transactions/3gWDsaAVKeUvjdJdpXxkhwtsno93qBY4Qf7q8vhp41FT 'Disp41r' ``` * lock():lock is a dangerous function! it will end the voting, and it can only be called by the contract owner, after call the lock function, the voting will end no matter whether the time exceeds or not, and will generate the winner and evenly split the pool of funds to the people who vote for the winner!(you can see that 3 near is split, and transfer to the people who vote for Disp41r) ``` root@iZbp1i18irje02nxov4qfsZ:~# near call disv.testnet lock '' --accountId disv.testnet Scheduling a call: disv.testnet.lock() Doing account.functionCall() Retrying transaction disv.testnet:D1a6zdDsP1hWPYnCVkjjXTmQX5WC3fo5ackcS2qPzPVf with new nonce. Retrying request to broadcast_tx_commit as it has Transaction Id AQ15UVFb5yn3zNNxfwKwwfLYzMSFoKqpy9SAARAUvmZZ To see the transaction in the transaction explorer, please open this url in your browser https://explorer.testnet.near.org/transactions/AQ15UVFb5yn3zNNxfwKwwfLYzMSFoKqpy9SAARAUvmZZ '' ``` ![](https://hackmd.summershrimp.com/uploads/upload_fa2a3c81e9814197cdb7d758200ce1fc.png) * restart: restart will end the voting now and start a new voting, also only can be called by the contract owner. ``` root@iZbp1i18irje02nxov4qfsZ:~# near call dispa1r_vote.testnet restart '{"title":",most creative","time":30000}' --accountId dispa1r_vote.testnet Scheduling a call: dispa1r_vote.testnet.restart({"title":",most creative","time":30000}) Doing account.functionCall() Transaction Id G16q1bXKvFdpUB4273N6eaf5Pcoq1m8CMfDjMMp7tv2u To see the transaction in the transaction explorer, please open this url in your browser https://explorer.testnet.near.org/transactions/G16q1bXKvFdpUB4273N6eaf5Pcoq1m8CMfDjMMp7tv2u '' ``` ## view function * get_tmp_winner: it is a view function also, you can see who owns most votes now. ``` root@iZbp1i18irje02nxov4qfsZ:~# near view disv.testnet get_tmp_winner '' --accountId dispa1r.testnet View call: disv.testnet.get_tmp_winner() 'Disp41r' ``` * get_total_votes_for(name): this function can get the votes of the candidate(you can see that because of 3 near deposit, the total is 1+1+3=5) ``` root@iZbp1i18irje02nxov4qfsZ:~# near view disv.testnet get_total_votes_for '{"name":"Disp41r"}' --accountId dispa1r.testnet View call: disv.testnet.get_total_votes_for({"name":"Disp41r"}) 5 ``` * get_title: this is a view funtion, you can get the title of voting. ``` root@iZbp1i18irje02nxov4qfsZ:~# near view disv.testnet get_title '{}' --accountId disv.testnet View call: disv.testnet.get_title({}) ',most creative' ``` * get_candidates: this is a view function, and it will return all the candidates and total number of their votes * get_voters: this is a view function, it will all the voters who have voted, but will not return the candidate they voted for privacy. ## internal function * transfer_winner: There is a funtion only can contract interal call, it is transfer_winner function, it only be called when the vote is over :), this function wil ldivide all the near in the pool evenly among users who voted for the winner。 * check_out_of_time: This method will be called every time the contract is called, to check whether the voting is over, if it exceeds the set time, this funtion will automaticly lock the voting.
{}