diff --git a/custom/parameters.py b/custom/parameters.py index 067e7d50d8191ff78b9fd8875502db5cba75ea5a..c9a050094e9d84fab6c64d01f01109f4eabee733 100644 --- a/custom/parameters.py +++ b/custom/parameters.py @@ -2,6 +2,7 @@ from lib.utility_param import * # Global parameters FIRST_UD_REEVAL = b_months(6) # 6 months +# FIXME UD reeval should be set 6 month after blockchain v1 last reeval # Genesis parameters GENESIS_CERTS_EXPIRE_ON = 15 @@ -13,7 +14,7 @@ GENESIS_SMITH_MEMBERSHIPS_EXPIRE_ON = b_months(12) # Parameters BABE_EPOCH_DURATION = 600 -CERT_PERIOD = b_days(1) # 1 day +CERT_PERIOD = b_days(5) # 5 days CERT_MAX_BY_ISSUER = 100 CERT_MIN_RECEIVED_CERT_TO_ISSUE_CERT = 5 CERT_VALIDITY_PERIOD = b_months(24) @@ -23,7 +24,7 @@ MEMBERSHIP_PERIOD = b_months(12) PENDING_MEMBERSHIP_PERIOD = b_months(1) UD_CREATION_PERIOD = b_days(1) UD_REEVAL_PERIOD = b_months(6) -SMITH_CERT_PERIOD = b_days(1) +SMITH_CERT_PERIOD = b_days(5) SMITH_CERT_MAX_BY_ISSUER = 15 SMITH_CERT_MIN_RECEIVED_CERT_TO_ISSUE_CERT = 3 SMITH_CERT_VALIDITY_PERIOD = b_months(24) diff --git a/lib/functions.py b/lib/functions.py index 57881d90ba45ca7040c5d4dbd3dcf81ad934bd2f..2ac90b5c123ce4fd6d06030b4820ce1edf25b978 100644 --- a/lib/functions.py +++ b/lib/functions.py @@ -40,6 +40,10 @@ def get_identities_and_wallets(start_timestamp): 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 @@ -100,11 +104,12 @@ def get_identities_and_wallets(start_timestamp): # get info from block for bloc in blocs_data: - blocs.update({bloc["key"]: bloc["value"]["medianTime"]}) + 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] @@ -115,21 +120,26 @@ def get_identities_and_wallets(start_timestamp): r_uid = identity_names[r_pubkey] r_address = v1_pubkey_to_v2_address(r_pubkey) - # if no arguments, set start time to now - if start_timestamp == "": - start_timestamp = int(time()) - # get expiration bloc number from cert written time - cert_expire_on_bloc = date_to_bloc_number( - blocs[str(cert["writtenOn"])], start_timestamp - ) + # ⚠️ 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_bloc <= 0: + 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_bloc + identities[r_uid]["certs_received"][i_uid] = cert_expire_on return [identities, wallets] diff --git a/lib/utility.py b/lib/utility.py index 74dd8df67ee9fe762c3535960cf3fde6cf42d92c..6e275e0faa3a645f4d695f03e69a7d06d38bae31 100644 --- a/lib/utility.py +++ b/lib/utility.py @@ -3,38 +3,43 @@ 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 - + 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) + 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(cert_timestamp, start_timestamp): - cert_duration = int(start_timestamp) - cert_timestamp - cert_duration_bloc_number = b_minutes(cert_duration / 60) - return CERT_VALIDITY_PERIOD - cert_duration_bloc_number + +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/' + path = "/home/axiom/dex-data/" f = open(path + url) else: - website= 'https://g1-migrator.axiom-team.fr/' + website = "https://g1-migrator.axiom-team.fr/" f = urlopen(website + url) return json.load(f) - diff --git a/lib/utility_param.py b/lib/utility_param.py index 5b267b3b74feef219e5ffb984501f481902b2461..ffb45b263ac9a4086692d72a299d1f8eaf9a684d 100644 --- a/lib/utility_param.py +++ b/lib/utility_param.py @@ -1,5 +1,26 @@ -# Utility -def b_minutes(minutes): return int(minutes * 60 / 6) -def b_hours(hours): return int(b_minutes(hours) * 60) -def b_days(days): return int(b_hours(days) * 24) -def b_months(months): return int(b_days(months) * 30) +# Utility params + + +def b_seconds(seconds: int) -> int: + """converts a number of seconds to a number of 6-seconds blocs + use lower approximation + example : 2 seconds will be block 0 + example : 7 seconds will be block 1 + """ + return int(seconds / 6) + + +def b_minutes(minutes: int) -> int: + return b_seconds(minutes * 60) + + +def b_hours(hours: int) -> int: + return b_minutes(hours) * 60 + + +def b_days(days: int) -> int: + return b_hours(days) * 24 + + +def b_months(months: int) -> int: + return b_days(months) * 30