-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquadratic-funding-calculator.py
82 lines (67 loc) · 2.44 KB
/
quadratic-funding-calculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import requests
import os
import time
import json as JSON
from Qf import Qf
server = "http://localhost:5279"
proposals = []
total_scaled = 0
support_count = 0
# Set these values
round_details = {
"LBC_pool": 50000,
"last_accepted_height": 99999999999,
"first_accepted_height": 1114569,
"min_subs": 100,
"min_tip": 0,
"max_contribution_amount": 2500 # set 0 if not used
}
claim_ids = [
"4b4012c5db509554b3fc3eb9145ecd5d75e70c67",
"fc4f7e318aa8a72abcaaa9ef7e68939ff810da95",
"2abd078151d4d7802be626497f8d38ca6b002d1c",
"49f1f0d64ba28180336c4014d138ff6e9785f49c",
"33a885a17a14399c4076bb2d97e8c52ee05fe77e",
"20b6a9decb74288178bc74bc58f1d1b5602d9213",
]
def getCurrentHeight():
return requests.post(server, json={"method": "status"}).json()["result"]["wallet"]["blocks"]
def createJSONfile(file_name, json):
json = JSON.dumps(json)
with open(file_name, 'w') as file:
file.write(f"""var qf_results = {json}
""")
def getAuthToken():
auth_token_file = os.path.dirname(__file__) + "/auth_token"
try:
with open(auth_token_file, "r") as file:
auth_token = file.readline()
response_error = requests.get("https://api.odysee.com/user/me?auth_token=%s" % auth_token).json()["error"]
if response_error != None:
# If auth_token expired or other error, just start from fresh
raise FileNotFoundError
print("Old auth_token found")
except FileNotFoundError:
with open(auth_token_file, "w") as file:
auth_token = requests.post("https://api.odysee.com/user/new").json()["data"]["auth_token"]
file.write(auth_token)
print("New auth_token created")
return auth_token
## Get auth token to check follows
auth_token = getAuthToken()
qf = Qf(claim_ids, round_details, server, auth_token)
createJSONfile("qf-result-json.js", qf.getJSON())
# Loop to update values
height = getCurrentHeight()
last_height = height
print("Block: %d" % height)
print("Supports found(includes view-rewards): %d" % qf.total_supports_found)
while height <= round_details["last_accepted_height"] or True:
if (last_height < height):
qf.update()
createJSONfile("qf-result-json.js", qf.getJSON())
print("Block: %d" % height)
print("Supports found(includes view-rewards): %d" % qf.total_supports_found)
time.sleep(15)
last_height = height
height = getCurrentHeight()