SteemSnippets update : list_votes to get all active votes of an account.

in utopian-io •  last month

Hello,

If you are unfamiliar with steemsnippets I encourage you to read the genesis post : https://steemit.com/programming/@howo/introducting-steemsnippets

And to check out the repository : https://github.com/drov0/steemsnippets

With steemit inc continuously working on the cost cuts, we've seen quite a lot of api changes, the lastest is this one : https://steemit.com/steemit/@steemitdev/additional-public-api-change

get_account_votes will be deprecated in favor of list_votes. Which is an issue for some of the workflows with steempress. Basically we trail some trusted curation teams so I need to get a list of what they voted on.

Problems :

  • list_votes only gets 1000 entries at a time
  • You can't get them in the "new to old order"
  • It starts at the beginning of the account so if I look at "howo" I get my very first vote and then I need to build up 1000 votes per 1000 votes until I get to the votes that matter (the present). Which can be very very long on some old accounts that vote a lot (curie for instance)
  • If you want to speed up things you can give it a checkpoint to start searching from to not have to go from the beginning of the account but it has to be a post on which the account has voted, not a date.
  • Both steem-js and Dsteem (as of the writing of this post) don't support the function so I have to make direct calls to the steem api instead of using a lib.

So I knew it would prove to be a fun challenge to tackle.

solutions

I am looking for "active votes" aka votes that are on posts before payout. The point is to trail and add a vote on top of the ones that are already existing after all.

So here's the full code if you want to follow along on how I solved each problem :

https://github.com/drov0/steemsnippets/blob/master/dsteem/get_active_votes/get_active_votes.js

This is how the algorithm works :

If I have a cache, I start querying for votes from the cached post, if not I query from the beginning of the account. I get batches of 1000 posts.

At some point if you ask the api for 1000 votes from voter x but he can't find 1000 (because we got them all) he will start to fill the rest of the 1000 entries will random votes. So we query to get batches of 1000 until we hit that random vote moment, which means that we got them all.

Then we remove all the unactive votes (votes that are older than 7 days old). And store the older vote as a cache for future queries. As a note, I use on the snipper a cache system using files so that anyone can run the snippet without having to setup a whole db but on my production servers I use a database.

Then we check each individual posts to see if the post is still pending payout (younger than 7 days or not) and if the post is indeed pending payout, we add that to the list.

And at the end you get the list of inactive posts :)

This code has a bit of error handling but could use some more, for instance there is no retry in case of a timeout. In my workflow it's not that big of a deal but it might in your case. So if you do implement it please send a PR my way !

Commit related to this work : https://github.com/drov0/steemsnippets/commit/75e80aef56b3ccf43f8ed77a14443a92263576ef

@howo

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:  
  • Congratulations on completing this piece of the puzzle.
  • Don't hesitate to share some of the code in your article in the future.
  • Great comments throughout.

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]

·

Thank you for your review, @helo! Keep up the good work!

@howo You have received a 100% upvote from @botreporter because this post did not use any bidbots and you have not used bidbots in the last 30 days!

Upvoting this comment will help keep this service running.

·

Interesting stuff

Hi @howo!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Congratulations @howo! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 12000 upvotes. Your next target is to reach 13000 upvotes.

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

SteemWhales has officially moved to SteemitBoard Ranking

Support SteemitBoard's project! Vote for its witness and get one more award!

Hey, @howo!

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

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

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

Vote for Utopian Witness!