Skip to content
Snippets Groups Projects
Commit 3513a3f5 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

WIP multiple fixes

- export timestamp vs start timestamp
- initial monetary mass
- TODO treasury to collect ignored money
- membership expiration date
- warning if expired certs
parent 74ac707c
No related branches found
No related tags found
No related merge requests found
...@@ -11,11 +11,13 @@ def get_wallets_data(): ...@@ -11,11 +11,13 @@ def get_wallets_data():
# Get wallets balances data # Get wallets balances data
wallets_data = load_json_url("inputs/wallets.json") wallets_data = load_json_url("inputs/wallets.json")
wallets = {} wallets = {}
ignored_money = 0
for wallet in wallets_data: for wallet in wallets_data:
balance = wallet["value"]["balance"]
if "&&" in wallet["key"]: if "&&" in wallet["key"]:
ignored_money += balance
continue continue
pubkey = wallet["key"].split("(")[1].split(")")[0] pubkey = wallet["key"].split("(")[1].split(")")[0]
balance = wallet["value"]["balance"]
# Remove pubkeys > 32 bytes # Remove pubkeys > 32 bytes
# d2meevcahfts2gqmvmrw5hzi25jddikk4nc4u1fkwrau # d2meevcahfts2gqmvmrw5hzi25jddikk4nc4u1fkwrau
...@@ -27,25 +29,41 @@ def get_wallets_data(): ...@@ -27,25 +29,41 @@ def get_wallets_data():
pubkey_bytes = base58.b58decode(pubkey) pubkey_bytes = base58.b58decode(pubkey)
pubkey_lenght = len(pubkey_bytes) pubkey_lenght = len(pubkey_bytes)
if pubkey_lenght > 32 or balance == 0: if pubkey_lenght > 32 or balance == 0:
ignored_money += balance
continue continue
wallets.update({v1_pubkey_to_v2_address(pubkey): int(balance)}) wallets.update({v1_pubkey_to_v2_address(pubkey): int(balance)})
return wallets # add ignored money to treasury
# FIXME get treasury address
wallets["5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z"] = ignored_money
return wallets
def get_identities_and_wallets(start_timestamp): def get_membership_expiry():
"""get membership expiry from input file"""
# Get Dex membership data
membership_data = load_json_url("inputs/membership.json")
membership_expiry = {}
for membership in membership_data:
membership_expiry[membership["key"]] = membership["value"][0]["expires_on"]
return membership_expiry
def get_identities_and_wallets(last_block_time, start_timestamp):
"""get identities with certifications and wallets with their balance
last_block_time is the time of the last exported block
start_timestamp is the timestamp of the v2 genesis
used to estimate cert expiration in number of blocks
"""
# initialize # initialize
blocs = {} blocs = {}
identity_names = {} identity_names = {}
identities = {} identities = {}
# if no arguments, set start time to now
if start_timestamp == "":
start_timestamp = int(time())
# Get wallets data # Get wallets data
wallets = get_wallets_data() wallets = get_wallets_data()
# Get membership expiry
membership_expiry = get_membership_expiry()
# Get Dex idty data # Get Dex idty data
idty_data = load_json_url("inputs/idty.json") idty_data = load_json_url("inputs/idty.json")
# Get Dex certs data # Get Dex certs data
...@@ -57,21 +75,18 @@ def get_identities_and_wallets(start_timestamp): ...@@ -57,21 +75,18 @@ def get_identities_and_wallets(start_timestamp):
# Get custom identities # Get custom identities
custom_identities = load_json("custom/identities.json") custom_identities = load_json("custom/identities.json")
# TODO manage membership expiration
# TODO make sure that index respects order of arrival # TODO make sure that index respects order of arrival
# Get identities names by pubkey # Get identities names by pubkey
for i, idty in enumerate(idty_data): for idty in idty_data:
pubkey = idty["key"] pubkey = idty["key"]
address = v1_pubkey_to_v2_address(pubkey) address = v1_pubkey_to_v2_address(pubkey)
value = idty["value"][0] value = idty["value"][0]
index = value["wotb_id"] + 1
uid = value["uid"] uid = value["uid"]
is_member = value["member"]
identity_names[pubkey] = uid identity_names[pubkey] = uid
membership_expire_on = date_to_bloc_number(membership_expiry[pubkey], start_timestamp)
# FIXME if membership_expire_on < 0 : membership_expire_on = 0 # forget old expiry date
if value["member"]:
membership_expire_on = 666
else:
membership_expire_on = 0
# add address and balance to identity # add address and balance to identity
if address not in wallets: if address not in wallets:
...@@ -84,11 +99,11 @@ def get_identities_and_wallets(start_timestamp): ...@@ -84,11 +99,11 @@ def get_identities_and_wallets(start_timestamp):
# fill in identity entry # fill in identity entry
identities[uid] = { identities[uid] = {
"index": i, "index": index,
"owner_key": address, "owner_key": address,
"balance": balance, "balance": balance,
"membership_expire_on": membership_expire_on, "membership_expire_on": membership_expire_on if is_member else 0,
"next_cert_issuable_on": 0, "next_cert_issuable_on": 0, # initialized to zero, modified later
"certs_received": {}, "certs_received": {},
} }
...@@ -116,23 +131,34 @@ def get_identities_and_wallets(start_timestamp): ...@@ -116,23 +131,34 @@ def get_identities_and_wallets(start_timestamp):
i_address = v1_pubkey_to_v2_address(i_pubkey) i_address = v1_pubkey_to_v2_address(i_pubkey)
for cert in issuer["value"]["issued"]: for cert in issuer["value"]["issued"]:
# if certification expired, skip silently
if cert["expired_on"] != 0 :
continue
r_pubkey = cert["receiver"] r_pubkey = cert["receiver"]
r_uid = identity_names[r_pubkey] r_uid = identity_names[r_pubkey]
r_address = v1_pubkey_to_v2_address(r_pubkey) r_address = v1_pubkey_to_v2_address(r_pubkey)
# get expiration bloc number from cert written time # get expiration of certification
# ⚠️ cert expire based on creation date, not write date
# timestamp of cert creation # timestamp of cert creation
created_on = blocs[cert["created_on"]] created_at = blocs[cert["created_on"]]
# block of cert creation # block of cert creation
created_on = date_to_bloc_number(created_on, start_timestamp) created_on = date_to_bloc_number(created_at, start_timestamp)
# block of next issuable cert # block of next issuable cert
next_issuable_on = created_on + CERT_PERIOD next_issuable_on = created_on + CERT_PERIOD
# block of cert expiration # timestamp of cert expiration
cert_expire_on = created_on + CERT_VALIDITY_PERIOD cert_expire_at = cert["expires_on"]
cert_expire_on = date_to_bloc_number(cert_expire_at, start_timestamp)
# if certification is expired, skip # if certification expiration date is before export,
if cert_expire_on <= 0: # it is a renewed certification and can be ignored
if cert_expire_at < last_block_time:
continue
# certifications can also have expired between export and start_timestamp
# in this case we display a warning because these missing certification
# could lead to a genesis with not enough certifications received for some members
if cert_expire_at <= start_timestamp:
print(f"⚠️ {i_uid}{r_uid} cert expired between export and start")
continue continue
# bump the next issuable date if necessary # bump the next issuable date if necessary
elif next_issuable_on > identities[i_uid]["next_cert_issuable_on"]: elif next_issuable_on > identities[i_uid]["next_cert_issuable_on"]:
......
...@@ -13,6 +13,7 @@ def v1_pubkey_to_v2_address(pubkey): ...@@ -13,6 +13,7 @@ def v1_pubkey_to_v2_address(pubkey):
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 # get incomplete Substrate keypair (only public key) from public key bytes
# FIXME use correct prefix (not 42)
keypair = Keypair( keypair = Keypair(
public_key=pubkey_bytes, ss58_format=42, crypto_type=KeypairType.ED25519 public_key=pubkey_bytes, ss58_format=42, crypto_type=KeypairType.ED25519
) )
......
...@@ -30,7 +30,12 @@ print("Generate ĞTest genesis with up-to-date Ğ1 data") ...@@ -30,7 +30,12 @@ print("Generate ĞTest genesis with up-to-date Ğ1 data")
# Get optional arguments # Get optional arguments
opt1 = "" opt1 = ""
if len(sys.argv) > 1: if len(sys.argv) > 1:
opt1 = sys.argv[1] opt1 = int(sys.argv[1])
# define start timestamp
start_timestamp = opt1
# if not defined set start time to now
if start_timestamp == "": start_timestamp = int(time())
# Get ĞTest parameters # Get ĞTest parameters
print(" get ĞTest parameters...") print(" get ĞTest parameters...")
...@@ -40,12 +45,14 @@ sudo_key = "5Dq8xjvkmbz7q4g2LbZgyExD26VSCutfEc6n4W4AfQeVHZqz" ...@@ -40,12 +45,14 @@ sudo_key = "5Dq8xjvkmbz7q4g2LbZgyExD26VSCutfEc6n4W4AfQeVHZqz"
# Dump ĞTest parameters # Dump ĞTest parameters
print(" dump ĞTest parameters...") print(" dump ĞTest parameters...")
ud_data = load_json_url("inputs/ud_value.json") last_block = load_json_url("inputs/ud_value.json")[0]["value"]
FIRST_UD = ud_data[0]["value"]["dividend"] FIRST_UD = last_block["dividend"]
INITAL_MONETARY_MASS = last_block["mass"]
LAST_BLOCK_TIME = last_block["medianTime"]
# Add identities bloc # Add identities bloc
print(" parse identities...") print(" parse identities...")
identities_wallets = get_identities_and_wallets(opt1) (identities_wallets, other_wallets) = get_identities_and_wallets(LAST_BLOCK_TIME, start_timestamp)
# Add wallets bloc # Add wallets bloc
print(" add simple wallets...") print(" add simple wallets...")
...@@ -54,12 +61,12 @@ print(" add simple wallets...") ...@@ -54,12 +61,12 @@ print(" add simple wallets...")
gtest_genesis = { gtest_genesis = {
"first_ud": FIRST_UD, "first_ud": FIRST_UD,
"first_ud_reeval": FIRST_UD_REEVAL, "first_ud_reeval": FIRST_UD_REEVAL,
"initial_monetary_mass": 0, # TODO "initial_monetary_mass": INITAL_MONETARY_MASS,
"smiths": smiths, "smiths": smiths,
"technical_committee": technical_committee, "technical_committee": technical_committee,
"sudo_key": sudo_key, "sudo_key": sudo_key,
"identities": identities_wallets[0], "identities": identities_wallets,
"wallets": identities_wallets[1], "wallets": other_wallets,
} }
# Dump JSON to file # Dump JSON to file
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment