Recursive Algorithm to Get Proxy Votes

in #witness-category4 years ago (edited)

Regarding this tool: https://steemyy.com/proxy/
In case you might not notice, this tool also returns the indirect proxy supporters.
For example,

danielhuhservice proxies to der-prophet, who sets proxy to steemchiller.

Recursion

If you perform real-time scan backwards on the steem blockchain, it is hard to obtain the indirect proxy because for each direct proxy, you have to spawn new thread search their account history.

Real-time processing is slow, and thus we process and sync the blocks into a database. Suppose you can use a SQL to obtain the direct proxy voters like this:

def getProxy(account):
   sql = "select account from proxy where proxy=" + account;
   con.exec(sql)
  data = []
   for row in cur.fetchall():
    # recursive 
     data.append({"account": row[0], "voters": getProxy(row[0])
  return data

Here it is the beauty of the recursion. We call the function itself to fill the voters array of the current proxy.

Terminating the Recursion

Usually, for recursion to work, you have to set a terminal condition, otherwise, the recursive calls might go forever which causes the infamous "Stack Overflow".

But in our case, the steem blockchain, this might be ok without it. As you can't broadcast a proxy vote to someone who proxies you back, or even proxies to someone who proxies to you - which causes a loop.

You can, however, pass a maximum depth value (as a second parameter), as a safety check.

def getProxy(account, depth = 5):
  if depth == 0:
      # max depth exceeded, just return empty array
      return []
   sql = "select account from proxy where proxy=" + account;
   con.exec(sql)
  data = []
   for row in cur.fetchall():
    # recursive 
     data.append({"account": row[0], "voters": getProxy(row[0], depth - 1)
  return data

I hope this helps!
Reposted to the blog

Steem On!~

If you like my work, please consider voting for me, thanks!
https://steemit.com/~witnesses type in justyy and click VOTE



Alternatively, you could proxy to me if you are too lazy to vote!

Also: you can vote me at the tool I made: https://steemyy.com/witness-voting/?witness=justyy

Visit me at: https://steemyy.com

Sort:  

image.png

I need all the Proxy Votes I can get...
My Posts deserve more views...
May 30, 2020... 14.7 Hollywood Time...

great.. it is informative and knowledgable for the brilliant minded person. keep it up.
https://steemit.com/anxiety/@faiz.rehman/avoid-anxiety-depression-and-stress-for-mental-health

Hi @justyy

I want to ask a little about the proxy.
What are the advantages or disadvantages of using a proxy? When compared with not using a proxy.
Thank

advantage of using proxy is that you don't need to vote manually (maximum 30 votes) yourself.
disadvantage is that you don't get to pick. :P

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.032
BTC 63042.11
ETH 3047.49
USDT 1.00
SBD 3.91