Skip to content
Snippets Groups Projects
Select Git revision
  • a4adb75bfda5febaa7de916f2af8ce34f69f3a26
  • master default protected
  • fix_picked_up_file_in_runtime_release
  • network/gtest-1000 protected
  • upgradable-multisig
  • runtime/gtest-1000
  • network/gdev-800 protected
  • cgeek/issue-297-cpu
  • gdev-800-tests
  • update-docker-compose-rpc-squid-names
  • fix-252
  • 1000i100-test
  • hugo/tmp-0.9.1
  • network/gdev-803 protected
  • hugo/endpoint-gossip
  • network/gdev-802 protected
  • hugo/distance-precompute
  • network/gdev-900 protected
  • tuxmain/anonymous-tx
  • debug/podman
  • hugo/195-doc
  • gtest-1000-0.11.1 protected
  • gtest-1000-0.11.0 protected
  • gtest-1000 protected
  • gdev-900-0.10.1 protected
  • gdev-900-0.10.0 protected
  • gdev-900-0.9.2 protected
  • gdev-800-0.8.0 protected
  • gdev-900-0.9.1 protected
  • gdev-900-0.9.0 protected
  • gdev-803 protected
  • gdev-802 protected
  • runtime-801 protected
  • gdev-800 protected
  • runtime-800-bis protected
  • runtime-800 protected
  • runtime-800-backup protected
  • runtime-701 protected
  • runtime-700 protected
  • runtime-600 protected
  • runtime-500 protected
41 results

upgrade-substrate.md

Blame
  • functions.py 5.05 KiB
    from lib.utility import *
    from time import time
    
    
    def load_json_url(path):
        with open(path, "r") as fd:
            return json.load(fd)
    
    
    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):
        # initialize
        blocs = {}
        identity_names = {}
        identities = {}
    
        # if no arguments, set start time to now
        if start_timestamp == "":
            start_timestamp = int(time())
    
        # Get wallets data
        wallets = get_wallets_data()
        # Get Dex idty data
        idty_data = load_json_url("inputs/idty.json")
        # 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")
        # Get identities switches
        addresses_switches = load_json("custom/addresses_switches.json")
        # Get custom identities
        custom_identities = load_json("custom/identities.json")
    
        # TODO manage membership expiration
        # TODO make sure that index respects order of arrival
        # Get identities names by pubkey
        for i, idty in enumerate(idty_data):
            pubkey = idty["key"]
            address = v1_pubkey_to_v2_address(pubkey)
            value = idty["value"][0]
            uid = value["uid"]
            identity_names[pubkey] = uid
    
            # FIXME
            if value["member"]:
                membership_expire_on = 666
            else:
                membership_expire_on = 0
    
            # add address and balance to identity
            if address not in wallets:
                balance = 0
            else:
                balance = wallets[address]
                # remove identity from wallet
                # (only let simple wallets)
                del wallets[address]
    
            # fill in identity entry
            identities[uid] = {
                "index": i,
                "owner_key": address,
                "balance": balance,
                "membership_expire_on": membership_expire_on,
                "next_cert_issuable_on": 0,
                "certs_received": {},
            }
    
            # Switch address to custom if exist
            if uid in addresses_switches.keys():
                identities[uid]["owner_key"] = addresses_switches[uid]["v2"]
                identities[uid]["old_owner_key"] = v1_pubkey_to_v2_address(
                    addresses_switches[uid]["v1"]
                )
    
        # Add custom identities
        identities.update(custom_identities)
    
        # get info from block
        for bloc in blocs_data:
            blocs[int(bloc["key"])] = bloc["value"]["medianTime"]
    
        # Generate identities Ğ1v2 genesis json bloc
        # certs are stored per issuer in input file
        # certs are stored per receiver in output file
        print("    parse certification...")
        for issuer in certs_data:
            i_pubkey = issuer["key"]
            i_uid = identity_names[i_pubkey]
            i_address = v1_pubkey_to_v2_address(i_pubkey)
    
            for cert in issuer["value"]["issued"]:
                r_pubkey = cert["receiver"]
                r_uid = identity_names[r_pubkey]
                r_address = v1_pubkey_to_v2_address(r_pubkey)
    
                # get expiration bloc number from cert written time
                # ⚠️ cert expire based on creation date, not write date
                # timestamp of cert creation
                created_on = blocs[cert["created_on"]]
                # block of cert creation
                created_on = date_to_bloc_number(created_on, start_timestamp)
                # block of next issuable cert
                next_issuable_on = created_on + CERT_PERIOD
                # block of cert expiration
                cert_expire_on = created_on + CERT_VALIDITY_PERIOD
    
                # if certification is expired, skip
                if cert_expire_on <= 0:
                    continue
                # bump the next issuable date if necessary
                elif next_issuable_on > identities[i_uid]["next_cert_issuable_on"]:
                    identities[i_uid]["next_cert_issuable_on"] = next_issuable_on
    
                # add received certification to identity
                identities[r_uid]["certs_received"][i_uid] = cert_expire_on
    
        return [identities, 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")