From 3448e41d5b7ecfbb148065fbf086cc8f96613a7b Mon Sep 17 00:00:00 2001 From: nolash Date: Thu, 8 Apr 2021 09:54:39 +0200 Subject: [PATCH] WIP add phone pointer import --- apps/cic-meta/src/assets/phone.ts | 2 +- .../scripts/cic_meta/import_meta.js | 1 + .../scripts/create_import_users.py | 2 +- .../scripts/eth/import_users.py | 26 ++++++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/apps/cic-meta/src/assets/phone.ts b/apps/cic-meta/src/assets/phone.ts index e786265e..9b6a0a3f 100644 --- a/apps/cic-meta/src/assets/phone.ts +++ b/apps/cic-meta/src/assets/phone.ts @@ -18,7 +18,7 @@ class Phone extends Syncable implements Addressable { } public static async toKey(msisdn:number) { - return await toKey(msisdn.toString(), ':cic.msisdn'); + return await toKey(msisdn.toString(), ':cic.phone'); } public key(): string { diff --git a/apps/contract-migration/scripts/cic_meta/import_meta.js b/apps/contract-migration/scripts/cic_meta/import_meta.js index 56c754f3..28cf5f7d 100644 --- a/apps/contract-migration/scripts/cic_meta/import_meta.js +++ b/apps/contract-migration/scripts/cic_meta/import_meta.js @@ -101,6 +101,7 @@ function importMeta(keystore) { const file = files[i]; if (file.substr(-5) != '.json') { console.debug('skipping file', file); + continue; } const filePath = path.join(workDir, file); doOne(keystore, filePath); diff --git a/apps/contract-migration/scripts/create_import_users.py b/apps/contract-migration/scripts/create_import_users.py index 11a0eae9..0d27a852 100644 --- a/apps/contract-migration/scripts/create_import_users.py +++ b/apps/contract-migration/scripts/create_import_users.py @@ -85,7 +85,7 @@ random.seed() def genPhoneIndex(phone): h = hashlib.new('sha256') h.update(phone.encode('utf-8')) - h.update(b'cic.phone') + h.update(b':cic.phone') return h.digest().hex() diff --git a/apps/contract-migration/scripts/eth/import_users.py b/apps/contract-migration/scripts/eth/import_users.py index be4ecbf8..821468dc 100644 --- a/apps/contract-migration/scripts/eth/import_users.py +++ b/apps/contract-migration/scripts/eth/import_users.py @@ -7,6 +7,7 @@ import argparse import uuid import datetime import time +import phonenumbers from glob import glob # external imports @@ -67,6 +68,9 @@ os.makedirs(user_new_dir) meta_dir = os.path.join(args.user_dir, 'meta') os.makedirs(meta_dir) +phone_dir = os.path.join(args.user_dir, 'phone') +os.makedirs(os.path.join(phone_dir, 'meta')) + user_old_dir = os.path.join(args.user_dir, 'old') os.stat(user_old_dir) @@ -166,10 +170,30 @@ if __name__ == '__main__': f.write(json.dumps(o)) f.close() - meta_key = generate_metadata_pointer(bytes.fromhex(new_address_clean), 'cic.person') + meta_key = generate_metadata_pointer(bytes.fromhex(new_address_clean), ':cic.person') meta_filepath = os.path.join(meta_dir, '{}.json'.format(new_address_clean.upper())) os.symlink(os.path.realpath(filepath), meta_filepath) + phone_object = phonenumbers.parse(u.tel) + phone = phonenumbers.format_number(phone_object, phonenumbers.PhoneNumberFormat.E164) + meta_phone_key = generate_metadata_pointer(phone.encode('utf-8'), ':cic.phone') + meta_phone_filepath = os.path.join(phone_dir, 'meta', meta_phone_key) + + filepath = os.path.join( + phone_dir, + 'new', + meta_phone_key[:2].upper(), + meta_phone_key[2:4].upper(), + meta_phone_key.upper(), + ) + os.makedirs(os.path.dirname(filepath), exist_ok=True) + + f = open(filepath, 'w') + f.write(to_checksum_address(new_address_clean)) + f.close() + + os.symlink(os.path.realpath(filepath), meta_phone_filepath) + i += 1 sys.stdout.write('imported {} {}'.format(i, u).ljust(200) + "\r")