Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
py-g1-migrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tools
py-g1-migrator
Commits
abd140c3
Commit
abd140c3
authored
2 years ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
WIP fix cert period
and black formatting
parent
98127adb
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
custom/parameters.py
+3
-2
3 additions, 2 deletions
custom/parameters.py
lib/functions.py
+20
-10
20 additions, 10 deletions
lib/functions.py
lib/utility.py
+17
-12
17 additions, 12 deletions
lib/utility.py
lib/utility_param.py
+26
-5
26 additions, 5 deletions
lib/utility_param.py
with
66 additions
and
29 deletions
custom/parameters.py
+
3
−
2
View file @
abd140c3
...
@@ -2,6 +2,7 @@ from lib.utility_param import *
...
@@ -2,6 +2,7 @@ from lib.utility_param import *
# Global parameters
# Global parameters
FIRST_UD_REEVAL
=
b_months
(
6
)
# 6 months
FIRST_UD_REEVAL
=
b_months
(
6
)
# 6 months
# FIXME UD reeval should be set 6 month after blockchain v1 last reeval
# Genesis parameters
# Genesis parameters
GENESIS_CERTS_EXPIRE_ON
=
15
GENESIS_CERTS_EXPIRE_ON
=
15
...
@@ -13,7 +14,7 @@ GENESIS_SMITH_MEMBERSHIPS_EXPIRE_ON = b_months(12)
...
@@ -13,7 +14,7 @@ GENESIS_SMITH_MEMBERSHIPS_EXPIRE_ON = b_months(12)
# Parameters
# Parameters
BABE_EPOCH_DURATION
=
600
BABE_EPOCH_DURATION
=
600
CERT_PERIOD
=
b_days
(
1
)
#
1
day
CERT_PERIOD
=
b_days
(
5
)
#
5
day
s
CERT_MAX_BY_ISSUER
=
100
CERT_MAX_BY_ISSUER
=
100
CERT_MIN_RECEIVED_CERT_TO_ISSUE_CERT
=
5
CERT_MIN_RECEIVED_CERT_TO_ISSUE_CERT
=
5
CERT_VALIDITY_PERIOD
=
b_months
(
24
)
CERT_VALIDITY_PERIOD
=
b_months
(
24
)
...
@@ -23,7 +24,7 @@ MEMBERSHIP_PERIOD = b_months(12)
...
@@ -23,7 +24,7 @@ MEMBERSHIP_PERIOD = b_months(12)
PENDING_MEMBERSHIP_PERIOD
=
b_months
(
1
)
PENDING_MEMBERSHIP_PERIOD
=
b_months
(
1
)
UD_CREATION_PERIOD
=
b_days
(
1
)
UD_CREATION_PERIOD
=
b_days
(
1
)
UD_REEVAL_PERIOD
=
b_months
(
6
)
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_MAX_BY_ISSUER
=
15
SMITH_CERT_MIN_RECEIVED_CERT_TO_ISSUE_CERT
=
3
SMITH_CERT_MIN_RECEIVED_CERT_TO_ISSUE_CERT
=
3
SMITH_CERT_VALIDITY_PERIOD
=
b_months
(
24
)
SMITH_CERT_VALIDITY_PERIOD
=
b_months
(
24
)
...
...
This diff is collapsed.
Click to expand it.
lib/functions.py
+
20
−
10
View file @
abd140c3
...
@@ -40,6 +40,10 @@ def get_identities_and_wallets(start_timestamp):
...
@@ -40,6 +40,10 @@ def get_identities_and_wallets(start_timestamp):
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 Dex idty data
# Get Dex idty data
...
@@ -100,11 +104,12 @@ def get_identities_and_wallets(start_timestamp):
...
@@ -100,11 +104,12 @@ def get_identities_and_wallets(start_timestamp):
# get info from block
# get info from block
for
bloc
in
blocs_data
:
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
# Generate identities Ğ1v2 genesis json bloc
# certs are stored per issuer in input file
# certs are stored per issuer in input file
# certs are stored per receiver in output file
# certs are stored per receiver in output file
print
(
"
parse certification...
"
)
for
issuer
in
certs_data
:
for
issuer
in
certs_data
:
i_pubkey
=
issuer
[
"
key
"
]
i_pubkey
=
issuer
[
"
key
"
]
i_uid
=
identity_names
[
i_pubkey
]
i_uid
=
identity_names
[
i_pubkey
]
...
@@ -115,21 +120,26 @@ def get_identities_and_wallets(start_timestamp):
...
@@ -115,21 +120,26 @@ def get_identities_and_wallets(start_timestamp):
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
)
# if no arguments, set start time to now
if
start_timestamp
==
""
:
start_timestamp
=
int
(
time
())
# get expiration bloc number from cert written time
# get expiration bloc number from cert written time
cert_expire_on_bloc
=
date_to_bloc_number
(
# ⚠️ cert expire based on creation date, not write date
blocs
[
str
(
cert
[
"
writtenOn
"
])],
start_timestamp
# 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 certification is expired, skip
if
cert_expire_on
_bloc
<=
0
:
if
cert_expire_on
<=
0
:
continue
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
# 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
]
return
[
identities
,
wallets
]
...
...
This diff is collapsed.
Click to expand it.
lib/utility.py
+
17
−
12
View file @
abd140c3
...
@@ -3,6 +3,7 @@ from urllib.request import urlopen
...
@@ -3,6 +3,7 @@ from urllib.request import urlopen
from
custom.parameters
import
*
from
custom.parameters
import
*
from
substrateinterface
import
Keypair
,
KeypairType
from
substrateinterface
import
Keypair
,
KeypairType
def
v1_pubkey_to_v2_address
(
pubkey
):
def
v1_pubkey_to_v2_address
(
pubkey
):
pubkey_bytes
=
base58
.
b58decode
(
pubkey
)
pubkey_bytes
=
base58
.
b58decode
(
pubkey
)
pubkey_length
=
len
(
pubkey_bytes
)
pubkey_length
=
len
(
pubkey_bytes
)
...
@@ -12,29 +13,33 @@ def v1_pubkey_to_v2_address(pubkey):
...
@@ -12,29 +13,33 @@ 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
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 V2 address
return
keypair
.
ss58_address
return
keypair
.
ss58_address
def
date_to_bloc_number
(
cert_timestamp
,
start_timestamp
):
cert_duration
=
int
(
start_timestamp
)
-
cert_timestamp
def
date_to_bloc_number
(
date_timestamp
:
int
,
start_timestamp
:
int
):
cert_duration_bloc_number
=
b_minutes
(
cert_duration
/
60
)
"
converts a unix timestamp to a block number in blockchain v2 based on estimated start timestamp
"
return
CERT_VALIDITY_PERIOD
-
cert_duration_bloc_number
timestamp
=
date_timestamp
-
start_timestamp
# can be negative
return
b_seconds
(
timestamp
)
# lower approximation
def
load_json
(
data
):
def
load_json
(
data
):
get_data
=
open
(
data
)
get_data
=
open
(
data
)
return
json
.
load
(
get_data
)
return
json
.
load
(
get_data
)
def
load_json_url
(
url
):
def
load_json_url
(
url
):
with
open
(
"
.env
"
,
"
r
"
)
as
file
:
with
open
(
"
.env
"
,
"
r
"
)
as
file
:
env
=
file
.
read
()
env
=
file
.
read
()
if
"
prod=true
"
in
env
:
if
"
prod=true
"
in
env
:
path
=
'
/home/axiom/dex-data/
'
path
=
"
/home/axiom/dex-data/
"
f
=
open
(
path
+
url
)
f
=
open
(
path
+
url
)
else
:
else
:
website
=
'
https://g1-migrator.axiom-team.fr/
'
website
=
"
https://g1-migrator.axiom-team.fr/
"
f
=
urlopen
(
website
+
url
)
f
=
urlopen
(
website
+
url
)
return
json
.
load
(
f
)
return
json
.
load
(
f
)
This diff is collapsed.
Click to expand it.
lib/utility_param.py
+
26
−
5
View file @
abd140c3
# Utility
# Utility params
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_seconds
(
seconds
:
int
)
->
int
:
def
b_months
(
months
):
return
int
(
b_days
(
months
)
*
30
)
"""
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment