Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

record_rep_weights to py3 #2732

Merged
merged 1 commit into from
Apr 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions ci/record_rep_weights.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import requests
import argparse
import string
from binascii import unhexlify
from base64 import b32decode
from binascii import hexlify, unhexlify
Expand All @@ -17,49 +16,49 @@
p = r.json()

reps = [ ]
tbl = string.maketrans('13456789abcdefghijkmnopqrstuwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
tbl = bytes.maketrans(b'13456789abcdefghijkmnopqrstuwxyz', b'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
for acc in p["representatives"]:
reps.append({
'account': acc,
'weight': long(p["representatives"][acc])
'weight': int(p["representatives"][acc])
})

r = requests.post(args.rpc, data='{"action":"block_count"}')
p = r.json()
block_height = max(0, int(p["count"]) - args.cutoff)

print "cutoff block height is %d" % block_height
print("cutoff block height is %d" % block_height)

reps.sort(key=lambda x: x["weight"], reverse=True)

supplymax = long(0)
supplymax = int(0)
for rep in reps:
supplymax += rep["weight"]

supplymax /= long('1000000000000000000000000000000')
supplymax = long(supplymax * args.limit)
supplymax *= long('1000000000000000000000000000000')
supplymax /= int('1000000000000000000000000000000')
supplymax = int(supplymax * args.limit)
supplymax *= int('1000000000000000000000000000000')

with open(args.output, 'wb') as of:
of.write(unhexlify("%032X" % block_height))

total = long(0)
total = int(0)
count = 0
for rep in reps:
if rep["weight"] == 0:
break
acc_val = long(hexlify(b32decode(rep["account"].encode("utf-8").replace("nano_", "").translate(tbl) + "====")), 16)
acc_val = int(hexlify(b32decode(rep["account"].encode('utf-8').replace(b"nano_", b"").translate(tbl) + b"====")), 16)
acc_bytes = unhexlify("%064X" % (((acc_val >> 36) & ((1 << 256) - 1))))
weight_bytes = unhexlify("%032X" % rep["weight"])
of.write(acc_bytes)
of.write(weight_bytes)
total += rep["weight"]
count += 1
print rep["account"] + ": " + str(rep["weight"])
print(rep["account"] + ": " + str(rep["weight"]))
if total >= supplymax:
break

print "wrote %d rep weights" % count
print "max supply %d" % supplymax
print ("wrote %d rep weights" % count)
print ("max supply %d" % supplymax)

of.close()