Skip to content
Snippets Groups Projects
Select Git revision
  • 321b3013e8672c933d0815efbfb90e18f7692baf
  • main default protected
  • release/1.1
  • encrypt_comments
  • mnemonic_dewif
  • authors_rules
  • 0.14
  • rtd
  • 1.2.1 protected
  • 1.2.0 protected
  • 1.1.1 protected
  • 1.1.0 protected
  • 1.0.0 protected
  • 1.0.0rc1 protected
  • 1.0.0rc0 protected
  • 1.0.0-rc protected
  • 0.62.0 protected
  • 0.61.0 protected
  • 0.60.1 protected
  • 0.58.1 protected
  • 0.60.0 protected
  • 0.58.0 protected
  • 0.57.0 protected
  • 0.56.0 protected
  • 0.55.1 protected
  • 0.55.0 protected
  • 0.54.3 protected
  • 0.54.2 protected
28 results

request_ws2p.py

Blame
  • utility.py 1.31 KiB
    import json, base58
    from urllib.request import urlopen
    from custom.parameters import *
    from substrateinterface import Keypair, KeypairType
    
    
    def v1_pubkey_to_v2_address(pubkey):
        pubkey_bytes = base58.b58decode(pubkey)
        pubkey_length = len(pubkey_bytes)
    
        # Add 0 head byte to pubkey so as to reach 32 bytes
        if pubkey_length < 32:
            pubkey_bytes = bytes([0] * (32 - pubkey_length)) + pubkey_bytes
    
        # get incomplete Substrate keypair (only public key) from public key bytes
        keypair = Keypair(
            public_key=pubkey_bytes, ss58_format=42, crypto_type=KeypairType.ED25519
        )
    
        # return V2 address
        return keypair.ss58_address
    
    
    def date_to_bloc_number(date_timestamp: int, start_timestamp: int):
        "converts a unix timestamp to a block number in blockchain v2 based on estimated start timestamp"
        timestamp = date_timestamp - start_timestamp  # can be negative
        return b_seconds(timestamp) # lower approximation
    
    
    def load_json(data):
        get_data = open(data)
        return json.load(get_data)
    
    
    def load_json_url(url):
        with open(".env", "r") as file:
            env = file.read()
    
        if "prod=true" in env:
            path = "/home/axiom/dex-data/"
            f = open(path + url)
        else:
            website = "https://g1-migrator.axiom-team.fr/"
            f = urlopen(website + url)
        return json.load(f)