[Development - ivoted] First commit of the @ivoted bot

in utopian-io •  3 months ago

Repository

https://github.com/algo-coder/ivoted-bot
This contribution applies to all commits in the repository.

Introduction to the #ivoted project

#ivoted is an initiative created by @sebbbl and @algo.coder.
It aims to act as a democracy incentive. The goal is to encourage people to vote for witnesses, rewarding them with lifetime weekly upvotes from the account @ivoted.
The code submitted here is the bot running 24/7 on the @ivoted account.

Its goals are :

  • to allow people to enter the program, by detecting @ivoted mentions or #ivoted tags,
  • and then upvote them weekly, according to the number of witness votes they casted.

Details

This is the initial commit of the bot.

The bot is based on a perpetual loop on the main thread that launches other threads with specific tasks :

  1. Every second, it will check for new blocks to treat them by launching a new thread executing the get_block() function (looking for the use of the tags or mentions of the account).
  2. Every hour, it updates the participants' informations with a new thread executing update_users().
  3. Every minute, it will print a sum up of what happened in the last minute, for debugging purposes.


Main functions

get_block()

This function gets the last irreversible block available, and then launches a thread for each block that hasn't yet been scanned. The 0.1 second time sleep is there to make sure there won't be two threads launched with the same block, thanks to the redundant check implemented in the treat_block() function.

treat_block()

This function first adds the block it will treat in a list to avoid running several threads scanning the same block. It also checks that all blocks have been scanned. If there's a gap between the last block treated and the block now treated (and the blocks in the gap aren't currently being scanned), it launches new threads to close the gap.


Then it extracts all operations for said block to check if there's a post with the #ivoted tag or the @ivoted mention. It also checks if in this block, we've been proxied votes.


If any of these conditions is fullfilled, it launches the treat_post() function, that will insert the author of the post / comment in the database, validating its subscription to the program.

update_users()

Every hour, informations (amount of Steem Power and witness votes) about the participants are updated in the database.


Once updated, the get_accounts() function is launched to extract all participants from the database, putting all informations needed for the upvoting side of the bot in a list.

vote_loop()

This is a perpertual loop, whose task is to upvote weekly all participants in the program.

1 > It checks if the current Voting Power of the account is superior to the limit fixed by the Policy of the account (here 95%, in the vp_limit variable)


2 > If the VP is above that limit, then:

3 > It loops through all the accounts to find the first that have not been voted in the last 7 days. It retrieves the history of this account to find the last post. If there is no post in the last 7 days, it will try to find the last comment posted. If there is none, it goes on to the next account.


4 > If a post or comment has been found, it upvotes it with a power percentage determined by the calculation described in the Policy.


5 > Then it record the vote casted in the database, and updates the information in the ACCOUNTS table, so the user is not upvoted in the next seven days.


Secondary functions

get_voting_power()

This function is used to get the real Voting Power of the account.


calculate_shares()

This function is used to get some values of the Steem Blockchain used for calculation (especially Steem per MVests).


How to contribute ?

You can contribute by creating pull requests on the repository mainly:

  • By correcting errors you might see in the code,
  • By optimizing it,
  • By any way you would see fit.

Links

Governance and policy
Introduction of @ivoted, a witness voting incentive bot
Official launch of the #ivoted initiative
Complete list of witnesses
Vote for witnesses and get engaged in the #ivoted initiative - Howto
The ivoted website

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
  • Very well documented, could be used as a model for a tutorial on bots.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

·

Thanks a lot for the review, it means a lot to me !

For the tutorial on bots, I don't know if it already exist its or not (in Python), but I could work on describing the steps a bit more precisely to make it understandable by any layperson.

As I also have other bots, I could make something more general, explaining the core of the bot (they all have the same foundation) and then describing the different applications any one could add on this core to make its own bot.

This is really a very useful tool in order to promote the witness voting process. Really the most important task of any steemian.
Steem on!

·

Thanks a lot for your support. It is this type of comment that motivates us.
We're still having some difficulties making the project known to a large audience, but it's our priority from now on.

merci pour ses explications, t'es un king dans ton domaine. Chapeau Monsieur

·

Je te remercie, même s'il y a bien meilleur que moi !
Après il y a encore un travail d'optimisation à faire, pour l'instant avec 75 participants à peu près ça ne pose pas de problème, mais peut-être qu'il faudra revoir certaines portions du code quand on aura plusieurs milliers de participants. Mais bon, chaque chose en son temps :D

·
·

c'est bien t'es modeste et optimiste. Je te souhaite d'avoir des milliers de participants, à plus

Hey @algo.coder
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

·

Wow ! Thanks a lot for your support.
I will think about other ways I can contribute.
Thanks again !