Select Git revision
functions.py
poka authored
functions.py 5.09 KiB
from lib.utility import *
from time import time
def get_wallets_data():
# Get wallets balances data
wallets_data = load_json_url('inputs/wallets.json')
wallets = {}
for wallet in wallets_data:
if "&&" in wallet['key']: continue
pubkey = wallet['key'].split('(')[1].split(')')[0]
balance = wallet['value']['balance']
# Remove pubkeys > 32 bytes
# d2meevcahfts2gqmvmrw5hzi25jddikk4nc4u1fkwrau
# afv1d5xa7fcdhcta1bqfq3pwvwem16gw67qj37obgnsv
# dyvfr3fqbs6g1yrktbstzxdkj3n7c5hrqf9buddzne4o
# 11111111111111111111111111111111111111111111
# jUPLL2BgY2QpheWEY3R13edV2Y4tvQMCXjJVM8PGDvyd
# gatrpfmgsuez193bja5snivz3dsvsqn5kcm4ydtpknsy
pubkey_bytes = base58.b58decode(pubkey)
pubkey_lenght = len(pubkey_bytes)
if pubkey_lenght > 32 or balance == 0: continue
wallets.update({v1_pubkey_to_v2_address(pubkey): int(balance)})
return wallets
def get_identities_and_wallets(start_timestamp):
# Get wallets data
wallets = get_wallets_data()
# Get Dex idty data
idty_data = load_json_url('inputs/idty.json')
# Get identities switches
addresses_switches = load_json('custom/addresses_switches.json')
# Get identities names by pubkey
identity_names = {}
for l in idty_data:
pubkey = l['key']
for m in l['value']:
if m['member']:
identity_names.update({pubkey: m['uid']})
# Get Dex certs data
certs_data = load_json_url('inputs/certs.json')
# Get blocs number with dates
blocs_data = load_json_url('inputs/blocs.json')
blocs = {}
for bloc in blocs_data:
blocs.update({bloc['key']: bloc['value']['medianTime']})
# Generate identities Ğ1v2 genesis json bloc
identities = {}
list_idty = set()
for i in certs_data:
pubkey = i['key']
if pubkey not in identity_names: continue
address = v1_pubkey_to_v2_address(pubkey)
if address not in wallets: continue
idty_name = identity_names[pubkey]
if idty_name == None: continue
# received_certs = {}
for cert in i['value']['issued']:
r_pubkey = cert['receiver']
r_address = v1_pubkey_to_v2_address(r_pubkey)
# If not a member, continue
if r_pubkey not in identity_names: continue
r_username = identity_names[r_pubkey]
if r_username == None: continue
# if no arguments, set start time to now
if start_timestamp == '': start_timestamp = int(time())
# get expiration bloc number from cert written time
cert_expire_on_bloc = date_to_bloc_number(blocs[str(cert['writtenOn'])], start_timestamp)
# if certification is expired, skip
if cert_expire_on_bloc <= 0: continue
# add address and balance to identity
if r_username not in identities: identities.update({r_username: {}})
if r_address not in wallets:
r_balance = 0
else:
r_balance = wallets[r_address]
# Switch address to custom if exist
for switches in addresses_switches:
if r_username == switches['username']: r_address = switches['v2']
identities[r_username].update({'balance': r_balance})
identities[r_username].update({'pubkey': r_address})
if 'certs' not in identities[r_username]:
identities[r_username].update({'certs': []})
else:
# keep only latest certification
inc=0
for now_cert in identities[r_username]['certs']:
if now_cert[0] == idty_name:
if now_cert[1] < cert_expire_on_bloc:
del identities[r_username]['certs'][inc]
inc=inc+1
# add received certification to identity
identities[r_username]['certs'].append([idty_name, cert_expire_on_bloc])
list_idty.add(address)
# Add custom identities
custom_identities = load_json('custom/identities.json')
identities.update(custom_identities)
# Remove isolate certs
for profile_check, value_check in identities.items():
a=0
for cert_check in value_check['certs']:
if cert_check[0] not in identities:
del identities[profile_check]['certs'][a]
a=a+1
# Add simple wallets
final_wallets = {}
for wallet in wallets:
if wallet not in list_idty:
final_wallets.update({wallet: wallets[wallet]})
return [identities, final_wallets]
def get_smiths():
final_smiths = {}
smiths_brut = load_json('custom/smiths.json')
for smith in smiths_brut:
final_smiths.update(smith)
return final_smiths
def get_technical_committee():
return load_json('custom/technical_committee.json')