Select Git revision
request_ws2p.py
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)