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

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

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now