Skip to content
Snippets Groups Projects
Commit 5ac6830d authored by poka's avatar poka
Browse files

refacto: clean script code

parent 6ab17503
No related branches found
No related tags found
No related merge requests found
import json, csv import json
from symbol import parameters from symbol import parameters
import sys
from urllib.request import urlopen from urllib.request import urlopen
import base58 import base58
from substrateinterface import Keypair, KeypairType from substrateinterface import Keypair, KeypairType
from currency_parameters import *
from bs4 import BeautifulSoup
def get_g1stats_data():
f = urlopen("https://g1-stats.axiom-team.fr/data/forbes.json")
return json.load(f)
def username_to_number(username, datajune_usernames):
if username in datajune_usernames:
return datajune_usernames.index(username) + 1
else:
return 9999999
def number_to_username(number, datajune_usernames):
return datajune_usernames[number - 1]
def get_datajune_usernames():
return urlopen("https://files.datajune.coinduf.eu/global/pseudos.txt").read().decode().split()
def v1PubkeyToV2Address(pubkey):
pubkey_bytes = base58.b58decode(pubkey)
pubkey_lenght = len(pubkey_bytes)
# Add 0 head byte to pubkey so as to reach 32 bytes
if pubkey_lenght < 32:
pubkey_bytes = bytes([0]*(32-pubkey_lenght)) + pubkey_bytes
# get incomplete Substrate keypair (only public key) from public key bytes
keypair = Keypair(public_key=pubkey_bytes, ss58_format=42, crypto_type=KeypairType.ED25519)
# return V2 address def get_identities_bloc():
return keypair.ss58_address # Get Dex idty data
idty_data = load_json('idty.json')
def get_genesis_parameters():
return {
'genesis_certs_expire_on': GENESIS_CERTS_EXPIRE_ON,
'genesis_certs_min_received': GENESIS_CERTS_MIN_RECEIVED,
'genesis_memberships_expire_on': GENESIS_MEMBERSHIPS_EXPIRE_ON,
'genesis_smith_certs_expire_on': GENESIS_SMITH_CERTS_EXPIRE_ON,
'genesis_smith_certs_min_received': GENESIS_SMITH_CERTS_MIN_RECEIVED,
'genesis_smith_memberships_expire_on': GENESIS_SMITH_MEMBERSHIPS_EXPIRE_ON,
}
def get_parameters():
return {
'babe_epoch_duration': BABE_EPOCH_DURATION,
'cert_period': CERT_PERIOD,
'cert_max_by_issuer': CERT_MAX_BY_ISSUER,
'cert_min_received_cert_to_issue_cert': CERT_MIN_RECEIVED_CERT_TO_ISSUE_CERT,
'cert_validity_period': CERT_VALIDITY_PERIOD,
'idty_confirm_period': IDTY_CONFIRM_PERIOD,
'idty_creation_period': IDTY_CREATION_PERIOD,
'membership_period': MEMBERSHIP_PERIOD,
'pending_membership_period': PENDING_MEMBERSHIP_PERIOD,
'ud_creation_period': UD_CREATION_PERIOD,
'ud_reeval_period': UD_REEVAL_PERIOD,
'smith_cert_period': SMITH_CERT_PERIOD,
'smith_cert_max_by_issuer': SMITH_CERT_MAX_BY_ISSUER,
'smith_cert_min_received_cert_to_issue_cert': SMITH_CERT_MIN_RECEIVED_CERT_TO_ISSUE_CERT,
'smith_cert_validity_period': SMITH_CERT_VALIDITY_PERIOD,
'smith_membership_period': SMITH_MEMBERSHIP_PERIOD,
'smith_pending_membership_period': SMITH_PENDING_MEMBERSHIP_PERIOD,
'smiths_wot_first_cert_issuable_on': SMITHS_WOT_FIRST_CERT_ISSUABLE_ON,
'smiths_wot_min_cert_for_membership': SMITHS_WOT_MIN_CERT_FOR_MEMBERSHIP,
'wot_first_cert_issuable_on': WOT_FIRST_CERT_ISSUABLE_ON,
'wot_min_cert_for_create_idty_right': WOT_MIN_CERT_FOR_CREATE_IDTY_RIGHT,
'wot_min_cert_for_membership': WOT_MIN_CERT_FOR_MEMBERSHIP,
}
def get_smiths():
smiths = {}
smiths.update({'poka': {'certs': ['elois', 'HugoTrentesaux', 'vit', 'tuxmain']}})
smiths.update({'elois': {'certs': ['HugoTrentesaux', 'vit', 'tuxmain', 'poka']}})
smiths.update({'HugoTrentesaux': {'certs': ['elois', 'vit', 'tuxmain', 'poka']}})
smiths.update({'vit': {'certs': ['elois', 'HugoTrentesaux', 'tuxmain', 'poka']}})
smiths.update({'tuxmain': {'certs': ['elois', 'HugoTrentesaux', 'vit', 'poka']}})
smiths.update({'1000i100': {'certs': ['elois', 'HugoTrentesaux', 'vit', 'poka']}})
return smiths
def get_technical_committee():
return ['poka', 'elois', 'HugoTrentesaux', 'vit', 'tuxmain']
import sys
def progressbar(it, prefix="", size=60, out=sys.stdout): # Python3.3+
count = len(it)
def show(j):
x = int(size*j/count)
print("{}[{}{}] {}/{}".format(prefix, "#"*x, "."*(size-x), j, count),
end='\r', file=out, flush=True)
show(0)
for i, item in enumerate(it):
yield item
show(i+1)
print("\n", flush=True, file=out)
def transform_dex_data():
# load idty data
f = open('idty.json')
idty_data = json.load(f)
# Get identities names by pubkey
identity_names = {} identity_names = {}
for l in idty_data: for l in idty_data:
pubkey = l['key'] pubkey = l['key']
for m in l['value']: for m in l['value']:
identity_names.update({pubkey: m['uid']}) identity_names.update({pubkey: m['uid']})
# Get g1stats data # Get g1stats balances data
g1stats_data = get_g1stats_data() g1stats_data = load_json("https://g1-stats.axiom-team.fr/data/forbes.json", True)
idty_balance = {} idty_balance = {}
for k in g1stats_data: for k in g1stats_data:
pubkey = k['pubkey'] pubkey = k['pubkey']
...@@ -125,11 +24,11 @@ def transform_dex_data(): ...@@ -125,11 +24,11 @@ def transform_dex_data():
if balance < 0: balance = 0 if balance < 0: balance = 0
idty_balance.update({pubkey: int(balance)}) idty_balance.update({pubkey: int(balance)})
# Get Dex certs data
certs_data = load_json('certs.json')
# Generate identities Ğ1v2 genesis json bloc
identities = {} identities = {}
ff = open('certs.json')
certs_data = json.load(ff)
for i in certs_data: for i in certs_data:
pubkey = i['key'] pubkey = i['key']
if pubkey not in identity_names: continue if pubkey not in identity_names: continue
...@@ -148,44 +47,39 @@ def transform_dex_data(): ...@@ -148,44 +47,39 @@ def transform_dex_data():
identities[idty_name].update({'certs': certs_received}) identities[idty_name].update({'certs': certs_received})
identities[idty_name].update({'pubkey': v1PubkeyToV2Address(pubkey)}) identities[idty_name].update({'pubkey': v1PubkeyToV2Address(pubkey)})
# print(json.dumps(identities))
return identities return identities
# Deprecated # Utility
def get_datajune_certs(): def v1PubkeyToV2Address(pubkey):
list_certs = {} pubkey_bytes = base58.b58decode(pubkey)
certsIndex = urlopen("https://files.datajune.coinduf.eu/graphs.lg").read().decode() pubkey_lenght = len(pubkey_bytes)
soup = BeautifulSoup(certsIndex, features="lxml")
for chunks in soup.find_all('a'):
pass
lastChunk = int(chunks.string.split('.')[0])
print('Getting certifications in progress, this could take ~5 minutes...')
for i in progressbar(range(1, lastChunk)):
# print(i)
paddedNbr = str(i).rjust(4, '0')
graphData = urlopen("https://files.datajune.coinduf.eu/graphs.lg/" + paddedNbr + ".lg")
for j in graphData.readlines():
data = j.decode()
if 'simplegraph' in data: continue
cert_data = data.replace('\n', '').split(',')
issuer = int(cert_data[0])
receiver = int(cert_data[1])
if receiver not in list_certs: list_certs.update({receiver: []}) # Add 0 head byte to pubkey so as to reach 32 bytes
if issuer not in list_certs[receiver]: list_certs[receiver].append(issuer) if pubkey_lenght < 32:
pubkey_bytes = bytes([0]*(32-pubkey_lenght)) + pubkey_bytes
list_certs_json = json.dumps(list_certs).encode() # get incomplete Substrate keypair (only public key) from public key bytes
list_certs_json_file = open('certs.json', 'wb') keypair = Keypair(public_key=pubkey_bytes, ss58_format=42, crypto_type=KeypairType.ED25519)
list_certs_json_file.write(list_certs_json)
# print(list_certs[1])
# sys.exit(0)
return list_certs # return V2 address
return keypair.ss58_address
def get_datajune_certs_local(): def load_json(data, isUrl = False):
f = open('certs.json') if isUrl:
return json.load(f) get_data = urlopen(data)
\ No newline at end of file else:
get_data = open(data)
return json.load(get_data)
# def progressbar(it, prefix="", size=60, out=sys.stdout):
# count = len(it)
# def show(j):
# x = int(size*j/count)
# print("{}[{}{}] {}/{}".format(prefix, "#"*x, "."*(size-x), j, count),
# end='\r', file=out, flush=True)
# show(0)
# for i, item in enumerate(it):
# yield item
# show(i+1)
# print("\n", flush=True, file=out)
from currency_parameters import *
def get_genesis_parameters():
return {
'genesis_certs_expire_on': GENESIS_CERTS_EXPIRE_ON,
'genesis_certs_min_received': GENESIS_CERTS_MIN_RECEIVED,
'genesis_memberships_expire_on': GENESIS_MEMBERSHIPS_EXPIRE_ON,
'genesis_smith_certs_expire_on': GENESIS_SMITH_CERTS_EXPIRE_ON,
'genesis_smith_certs_min_received': GENESIS_SMITH_CERTS_MIN_RECEIVED,
'genesis_smith_memberships_expire_on': GENESIS_SMITH_MEMBERSHIPS_EXPIRE_ON,
}
def get_parameters():
return {
'babe_epoch_duration': BABE_EPOCH_DURATION,
'cert_period': CERT_PERIOD,
'cert_max_by_issuer': CERT_MAX_BY_ISSUER,
'cert_min_received_cert_to_issue_cert': CERT_MIN_RECEIVED_CERT_TO_ISSUE_CERT,
'cert_validity_period': CERT_VALIDITY_PERIOD,
'idty_confirm_period': IDTY_CONFIRM_PERIOD,
'idty_creation_period': IDTY_CREATION_PERIOD,
'membership_period': MEMBERSHIP_PERIOD,
'pending_membership_period': PENDING_MEMBERSHIP_PERIOD,
'ud_creation_period': UD_CREATION_PERIOD,
'ud_reeval_period': UD_REEVAL_PERIOD,
'smith_cert_period': SMITH_CERT_PERIOD,
'smith_cert_max_by_issuer': SMITH_CERT_MAX_BY_ISSUER,
'smith_cert_min_received_cert_to_issue_cert': SMITH_CERT_MIN_RECEIVED_CERT_TO_ISSUE_CERT,
'smith_cert_validity_period': SMITH_CERT_VALIDITY_PERIOD,
'smith_membership_period': SMITH_MEMBERSHIP_PERIOD,
'smith_pending_membership_period': SMITH_PENDING_MEMBERSHIP_PERIOD,
'smiths_wot_first_cert_issuable_on': SMITHS_WOT_FIRST_CERT_ISSUABLE_ON,
'smiths_wot_min_cert_for_membership': SMITHS_WOT_MIN_CERT_FOR_MEMBERSHIP,
'wot_first_cert_issuable_on': WOT_FIRST_CERT_ISSUABLE_ON,
'wot_min_cert_for_create_idty_right': WOT_MIN_CERT_FOR_CREATE_IDTY_RIGHT,
'wot_min_cert_for_membership': WOT_MIN_CERT_FOR_MEMBERSHIP,
}
def get_smiths():
smiths = {}
smiths.update({'poka': {'certs': ['elois', 'HugoTrentesaux', 'vit', 'tuxmain']}})
smiths.update({'elois': {'certs': ['HugoTrentesaux', 'vit', 'tuxmain', 'poka']}})
smiths.update({'HugoTrentesaux': {'certs': ['elois', 'vit', 'tuxmain', 'poka']}})
smiths.update({'vit': {'certs': ['elois', 'HugoTrentesaux', 'tuxmain', 'poka']}})
smiths.update({'tuxmain': {'certs': ['elois', 'HugoTrentesaux', 'vit', 'poka']}})
smiths.update({'1000i100': {'certs': ['elois', 'HugoTrentesaux', 'vit', 'poka']}})
return smiths
def get_technical_committee():
return ['poka', 'elois', 'HugoTrentesaux', 'vit', 'tuxmain']
...@@ -3,17 +3,16 @@ ...@@ -3,17 +3,16 @@
import base58 import base58
from lib.functions import * from lib.functions import *
from currency_parameters import * from currency_parameters import *
from lib.get_parameters import *
from lib.get_smiths_and_techs import *
# Get arguments # Get optional arguments
opt1 = '' # opt1 = ''
if len(sys.argv) > 1: opt1=sys.argv[1] # if len(sys.argv) > 1: opt1=sys.argv[1]
# Final ĞTest genesis JSON # Final ĞTest genesis JSON
gtest_genesis = {} gtest_genesis = {}
identities = transform_dex_data()
# sys.exit(0)
# Get ĞTest parameters # Get ĞTest parameters
genesis_parameters = get_genesis_parameters() genesis_parameters = get_genesis_parameters()
parameters = get_parameters() parameters = get_parameters()
...@@ -30,12 +29,11 @@ gtest_genesis.update({'smiths': smiths}) ...@@ -30,12 +29,11 @@ gtest_genesis.update({'smiths': smiths})
gtest_genesis.update({'technical_committee': technical_committee}) gtest_genesis.update({'technical_committee': technical_committee})
gtest_genesis.update({'sudo_key': sudo_key}) gtest_genesis.update({'sudo_key': sudo_key})
# Add identities # Add identities bloc
identities = get_identities_bloc()
gtest_genesis.update({'identities': identities}) gtest_genesis.update({'identities': identities})
# Transform data to JSON
gtest_genesis_json = json.dumps(gtest_genesis, indent=2).encode()
# Dump JSON to file # Dump JSON to file
gtest_genesis_json = json.dumps(gtest_genesis, indent=2).encode()
gtest_json = open('gtest.json', 'wb') gtest_json = open('gtest.json', 'wb')
gtest_json.write(gtest_genesis_json) gtest_json.write(gtest_genesis_json)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment