Recursive Algorithm to Get Proxy Votes on Steem Blockchain
- 时间:2020-09-09 13:08:38
- 分类:网络文摘
- 阅读:135 次
Regarding this tool: Get Proxy Votes on Steem Blockchain, 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.
Recursive Algorithms to Get Both Direct/Indirect Proxy Voters
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 (e.g. SQLite). Suppose you can use a SQL to obtain the direct proxy voters like this:
1 2 3 4 5 6 7 8 | 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 |
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 dataHere 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.
1 2 3 4 5 6 7 8 9 10 11 | def getProxy(account, depth = 99): 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 |
def getProxy(account, depth = 99):
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 dataHere, the default maximum recursion depth is 100, when it exceeds, it will stop further recursive calls and simply return empty array.
–EOF (The Ultimate Computing & Technology Blog) —
推荐阅读:转基因食品安全立法的不足和完善建议 食品添加剂过量对人体健康带来的危害 揭秘零食里面的食品添加剂及其危害 食品学专家解析转基因食品安全问题 最有利于秋季养生的果蔬食物大盘点 对眼睛视力保护最有好处的10种食物 多吃4类富含维生素的食物给眼睛补营养 人工营养素和天然营养素有何区别 红枣养生食疗:养肝排毒安神补血养颜 常吃些鲜枣可抑制癌细胞提高免疫力
- 评论列表
-
- 添加评论