async def main():

    results = await asyncio.gather(*(check(ep, NETWORK_TYPE)
                                     for ep in ENDPOINTS))
    results.sort(key=lambda x: x[2], reverse=True)

    with client.MosaicHTTP(results[0][0], network_type=NETWORK_TYPE) as http:
        accounts = http.get_mosaic_richlist('402B2F579FAEBC59',
                                            params={'pageSize': str(1000)})

    print(f"Blockchain height: {results[0][1]}")
    print(
        f"        Timestamp: {datetime.datetime.now(datetime.timezone.utc).strftime('%b %d %Y %H:%M:%S %Z')}"
    )
    print(f"           Source: {results[0][0]}")
    print()

    top10 = 0
    top100 = 0
    top1000 = 0
    supply = 9000000000
    divisibility = 1000000
    i = 1

    for account in accounts:
        if (i <= 10):
            top10 += account.amount
        if (i <= 100):
            top100 += account.amount
        if (i <= 1000):
            top1000 += account.amount

        i += 1

    print(
        f'Top 10:   {int(top10 / divisibility):13,} XPX {top10 / supply / divisibility * 100:6.2f}%'
    )
    print(
        f'Top 100:  {int(top100 / divisibility):13,} XPX {top100 / supply / divisibility * 100:6.2f}%'
    )
    print(
        f'Top 1000: {int(top1000 / divisibility):13,} XPX {top1000 / supply / divisibility * 100:6.2f}%'
    )
    print()

    i = 1
    for account in accounts:
        print(
            f'{i:4}. {account.address.pretty()} {int(account.amount / divisibility):13,} {account.amount / supply / divisibility * 100:5.2f}%'
        )
        i += 1
def print_account_mosaics(account):
    print(f"Address: {account.address.address}")

    # Get the account info
    with client.AccountHTTP(endpoint) as http:
        account_info = http.get_account_info(account.address)

    # Get names and divisibility of all mosaics on the account
    for mosaic in account_info.mosaics:
        with client.MosaicHTTP(endpoint) as http:
            mosaic_info = http.get_mosaic(mosaic.id)
            mosaic_names = http.get_mosaic_names([mosaic.id])

        divisibility = 10**mosaic_info.properties.divisibility
        name = mosaic_names[0].names[0]
# Get network type
with client.NodeHTTP(endpoint) as http:
    node_info = http.get_node_info()
    network_type = node_info.network_identifier

# Get generation hash of this blockchain
with client.BlockchainHTTP(endpoint) as http:
    block_info = http.get_block_by_height(1)

# Get the XPX mosaic by its namespace alias. Mosaics don't have names, you can only asign an alias to them.
# Namespace will give us the mosaic id.
with client.NamespaceHTTP(endpoint) as http:
    namespace_info = http.get_namespace(models.NamespaceId('prx.xpx'))

# Get mosaic info by its id.
with client.MosaicHTTP(endpoint) as http:
    xpx = http.get_mosaic(namespace_info.alias.value)

alice = models.Account.create_from_private_key(
    "6b2a97945d0f318114215ee80c012a5ea2ad39a3cd472a9ff2caf7488c4c2ede",
    network_type)

# Ask for test XPX from the faucet
try:
    print(f"Requesting test XPX for {alice.address.address}")
    reply = requests.get(
        f"https://bctestnetfaucet.xpxsirius.io/api/faucet/GetXpx/{alice.address.address}"
    ).json()
    print(f"{reply}\n")

except:
    # Get generation hash and main mosaic
    with client.BlockchainHTTP(ENDPOINT) as http:
        block = http.get_block_by_height(1)
        gen_hash = block.generation_hash
        nemesis = block.signer

        receipts = http.get_block_receipts(2)
        for statement in receipts.transaction_statements:
            for receipt in statement.receipts:
                if (receipt.type == models.ReceiptType.VALIDATE_FEE):
                    mosaic_id = receipt.mosaic.id
                    break

    # Checking the divisibility
    with client.MosaicHTTP(ENDPOINT) as http:
        mosaic_info = http.get_mosaic(mosaic_id)
        divisibility = 10**mosaic_info.properties.divisibility

    # Prepare the testing account
    if (PRIVATE_KEY):
        account = models.Account.create_from_private_key(
            PRIVATE_KEY, network_type)
    else:
        account = models.Account.generate_new_account(
            network_type, entropy=lambda x: os.urandom(32))
        reply = requests.get(f"{FAUCET}{account.address.address}").json()
        if (reply != 'XPX sent!'):
            raise Exception(f"Error getting funds from faucet: {reply}")

    print()