Skip to content
Snippets Groups Projects
Select Git revision
  • d89a2ce94cac3dd7fa4ce54b0fcdecddf72dcd9c
  • 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

setup.md

Blame
  • functions.py 6.14 KiB
    import base58
    
    from adapters.duniter_v18.blocks import LevelDBBlocksRepository
    from adapters.duniter_v18.certifications import LevelDBCertificationsRepository
    from adapters.duniter_v18.identities import LevelDBIdentitiesRepository
    from adapters.duniter_v18.memberships import LevelDBMembershipsRepository
    from adapters.duniter_v18.wallets import LevelDBWalletsRepository
    from adapters.duniter_v18.ud_value import LevelDBUDValueRepository
    from custom.parameters import CERT_PERIOD, CERT_MIN_RECEIVED_CERT_TO_ISSUE_CERT
    from lib.utility import load_json
    
    
    def get_wallets_data(leveldb_path: str) -> tuple:
        """
        Get wallets data,
        return a tuple with wallets, total_money, ignored_money
    
        :param leveldb_path: LevelDB folder path
        :return:
        """
        # Get wallets balances data
        wallets_repository = LevelDBWalletsRepository(leveldb_path)
        wallets = {}
        total_money = 0  # counter
        ignored_money = 0  # counter
        for unlock_expression, wallet in wallets_repository:
            balance = wallet["balance"]
            if "&&" in unlock_expression:
                print(f"⚠️ wallet {unlock_expression} ignored (balance {balance})")
                ignored_money += balance
                continue
            pubkey = unlock_expression.split("(")[1].split(")")[0]
    
            if balance == 0:
                continue
    
            wallets.update({pubkey: int(balance)})
            total_money += balance
    
        return wallets, total_money, ignored_money
    
    
    def get_identities_and_wallets(start_timestamp: int, leveldb_path: str) -> tuple:
        """
        Get identities with certifications and wallets with their balance
        start_timestamp is the timestamp of the v2 genesis
        used to estimate cert expiration in number of blocks
    
        :param start_timestamp: Import start timestamp
        :param leveldb_path: LevelDB folder path
        :return:
        """
        # initialize
        identity_names = {}
        identities = {}
        treasury = 0
    
        # Get last block info
        ud_value_repository = LevelDBUDValueRepository(leveldb_path)
        last_block = ud_value_repository.get_last()
        initial_monetary_mass = last_block["mass"]
        last_block_time = last_block["medianTime"]
    
        print("    parse Identities...")
        # Get leveldb indices as Dex data
        memberships_repository = LevelDBMembershipsRepository(leveldb_path)
        identities_repository = LevelDBIdentitiesRepository(leveldb_path)
        certifications_repository = LevelDBCertificationsRepository(leveldb_path)
        blocks_repository = LevelDBBlocksRepository(leveldb_path)
    
        # Get custom identities
        custom_identities = load_json("custom/identities.json")
    
        # Get wallets data
        print("    parse Wallets...")
        (wallets, total_money, ignored_money) = get_wallets_data(leveldb_path)
        # add ignored money to treasury and check initial monetary mass
        treasury += ignored_money  # add ignored money to treasury
        wallet_sum = total_money + ignored_money
        missing_money = initial_monetary_mass - wallet_sum
        if missing_money != 0:
            print(f"⚠️ initial monetary mass {initial_monetary_mass:,} does not equal wallet sum {wallet_sum:,}")
            print(f"money on the wallets: {total_money:,}")
            print(f"money from ignored sources: {ignored_money:,}")
            print(f"missing money (added to treasury): {missing_money:,}")
            # add missing money to treasury
            treasury += missing_money
        # FIXME get real treasury address
        # wallets["5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z"] = treasury
    
        # TODO make sure that index respects order of arrival
        # Get identities names by pubkey
        for pubkey, identity in identities_repository:
            index = identity["wotb_id"] + 1
            uid = identity["uid"]
            is_member = identity["member"]
            identity_names[pubkey] = uid
            membership_expire_on = memberships_repository.get(pubkey)["expires_on"]
            if membership_expire_on < 0:
                membership_expire_on = 0  # forget old expiry date
    
            # add address and balance to identity
            if pubkey not in wallets:
                balance = 0
            else:
                balance = wallets[pubkey]
                # remove identity from wallet
                # (only let simple wallets)
                del wallets[pubkey]
    
            # fill in identity entry
            identities[uid] = {
                "index": index,
                "owner_pubkey": pubkey,
                "balance": balance,
                "membership_expire_on": membership_expire_on if is_member else 0,
                "next_cert_issuable_on": 0,  # initialized to zero, modified later
                "certs_received": {},
            }
    
        # Add custom identities
        identities.update(custom_identities)
    
        # Generate identities Ğ1v2 genesis json bloc
        # certs are stored per issuer in input file
        # certs are stored per receiver in output file
        print("    parse certifications...")
        # get certifications updated to their last state
        for i_pubkey, issuer in certifications_repository:
            i_uid = identity_names[i_pubkey]
    
            # get certifications updated to their last state
            for cert in issuer["issued"]:
                # if certification expired, skip silently
                if cert["expired_on"] != 0:
                    continue
    
                r_pubkey = cert["receiver"]
                r_uid = identity_names[r_pubkey]
    
                # get expiration of certification
                # timestamp of cert creation
                created_at = blocks_repository.get(cert["created_on"])["medianTime"]
                # block of next issuable cert
                next_issuable_on = created_at + CERT_PERIOD
                # timestamp of cert expiration
                cert_expire_at = cert["expires_on"]
                cert_expire_on = cert_expire_at
    
                if 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")