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

generated genesis should be OK

parent aacb9011
No related branches found
No related tags found
No related merge requests found
import json import json, csv
from symbol import parameters from symbol import parameters
import sys
from urllib.request import urlopen from urllib.request import urlopen
from substrateinterface import Keypair, KeypairType from substrateinterface import Keypair, KeypairType
from currency_parameters import * from currency_parameters import *
from bs4 import BeautifulSoup
def get_input_data(): def get_g1stats_data():
f = urlopen("https://g1-stats.axiom-team.fr/data/forbes.json") f = urlopen("https://g1-stats.axiom-team.fr/data/forbes.json")
return json.load(f) return json.load(f)
def get_datajune_certs():
list_certs = {}
certsIndex = urlopen("https://files.datajune.coinduf.eu/graphs.lg").read().decode()
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 issuer not in list_certs: list_certs.update({issuer: []})
if receiver not in list_certs[issuer]: list_certs[issuer].append(receiver)
# if i == 20: break
list_certs_json = json.dumps(list_certs).encode()
list_certs_json_file = open('certs.json', 'wb')
list_certs_json_file.write(list_certs_json)
# print(list_certs[1])
# sys.exit(0)
return list_certs
def get_datajune_certs_local():
f = open('certs.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): def v1PubkeyToV2Address(pubkey):
# get incomplete Substrate keypair (only public key) from public key bytes # get incomplete Substrate keypair (only public key) from public key bytes
keypair = Keypair(public_key=pubkey, ss58_format=42, crypto_type=KeypairType.ED25519) keypair = Keypair(public_key=pubkey, ss58_format=42, crypto_type=KeypairType.ED25519)
...@@ -64,3 +120,17 @@ def get_technical_committee(): ...@@ -64,3 +120,17 @@ def get_technical_committee():
return ['poka', 'elois', 'HugoTrentesaux' 'vit', 'tuxmain'] 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)
\ No newline at end of file
...@@ -7,8 +7,11 @@ from currency_parameters import * ...@@ -7,8 +7,11 @@ from currency_parameters import *
# Final ĞTest genesis JSON # Final ĞTest genesis JSON
gtest_genesis = {} gtest_genesis = {}
# Get input data from g1-stats # Get inputs data
inputData = get_input_data() g1stats_data = get_g1stats_data()
datajune_usernames = get_datajune_usernames()
# datajune_certs = get_datajune_certs()
datajune_certs = get_datajune_certs_local()
# Get ĞTest parameters # Get ĞTest parameters
genesis_parameters = get_genesis_parameters() genesis_parameters = get_genesis_parameters()
...@@ -29,7 +32,7 @@ gtest_genesis.update({'sudo_key': sudo_key}) ...@@ -29,7 +32,7 @@ gtest_genesis.update({'sudo_key': sudo_key})
# Add identities # Add identities
gtest_genesis.update({'identities': {}}) gtest_genesis.update({'identities': {}})
i=0 i=0
for profile in inputData: for profile in g1stats_data:
i=i+1 i=i+1
# skip 11111111111111111111111111111111111111111111 invalid pubkey, don't know why # skip 11111111111111111111111111111111111111111111 invalid pubkey, don't know why
...@@ -50,10 +53,35 @@ for profile in inputData: ...@@ -50,10 +53,35 @@ for profile in inputData:
# Get username if exist # Get username if exist
if profile['id'] != None: if profile['id'] != None:
username = profile['id']['username'] username = profile['id']['username']
# if username != 'poka': continue
# Get certs for this identity
# sent_certs = set()
username_number = username_to_number(username, datajune_usernames)
# print(username)
# for j in datajune_certs:
# cert_data = j.split(',')
# issuer = int(cert_data[0])
# receiver = int(cert_data[1])
# if issuer == username_number:
# receiver_username = number_to_username(receiver, datajune_usernames)
# sent_certs.add(receiver_username)
# # print(receiver_username)
sent_certs = []
if str(username_number) not in datajune_certs:
print(username + " doesn't exist !")
continue
for idty in datajune_certs[str(username_number)]:
username_receiver = number_to_username(idty, datajune_usernames)
sent_certs.append(username_receiver)
# Format identities genesis JSON # Format identities genesis JSON
gtest_genesis['identities'].update({username: {'balance': balance,'certs': [],'pubkey': address_v2}}) # print(sent_certs)
gtest_genesis['identities'].update({username: {'balance': balance,'certs': sent_certs,'pubkey': address_v2}})
# TODO: get certs by identities
# Transform data to JSON # Transform data to JSON
gtest_genesis_json = json.dumps(gtest_genesis, indent=2).encode() gtest_genesis_json = json.dumps(gtest_genesis, indent=2).encode()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment