Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Griffin <[email protected]>
  • Loading branch information
m00sey committed Aug 22, 2024
1 parent 87c74cb commit 0c1984f
Showing 1 changed file with 62 additions and 37 deletions.
99 changes: 62 additions & 37 deletions src/keria/app/cli/commands/sig-fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""
import argparse
from collections import defaultdict

from hio import help
from hio.base import doing
Expand All @@ -23,22 +22,11 @@
transferable=True)
parser.add_argument('--base', '-b', help='additional optional prefix to file location of KERI keystore',
required=False, default="")
parser.add_argument('--force', action="store_true", required=False,
help='True means perform fix without prompting the user')
parser.add_argument('--force', action="store_true", required=False, default=False,
help='Perform update')


def handler(args):
if not args.force:
print()
print("This command will copy data from existing HabitatRecords to the corresponding SignifyGroupHab.")
print("This action cannot be undone.")
print()
yn = input("Are you sure you want to continue? [y|N]: ")

if yn not in ("y", "Y"):
print("...exiting")
return []

kwa = dict(args=args)
return [doing.doify(fix, **kwa)]

Expand All @@ -47,10 +35,24 @@ def fix(tymth, tock=0.0, **opts):
_ = (yield tock)
args = opts["args"]

prefix_by_public_key = dict()
prefix_by_next_key_digest = dict()

adb = abase.AgencyBaser(name="TheAgency", base=args.base, reopen=True, temp=False)

caids = []
for ((caid,), _) in adb.agnt.getItemIter():
print(f"{caid}")
caids.append(caid)

signify_group_habs = dict()
for caid in caids:
with existing.existingHby(name=caid, base=args.base) as hby:
for pre, hab in hby.habs.items():
if type(hab) is habbing.SignifyGroupHab:
signify_group_habs[pre] = hab.name

# create caches of existing public keys and next key digests and the associated prefixes
for caid in caids:
db = basing.Baser(name=caid,
base=args.base,
temp=False,
Expand All @@ -60,9 +62,6 @@ def fix(tymth, tock=0.0, **opts):
except kering.DatabaseError:
return -1

prefix_by_public_key = dict()
prefix_by_next_key_digest = dict()

for pre, fn, dig in db.getFelItemAllPreIter(key=b''):
dgkey = dbing.dgKey(pre, dig)
if not (raw := db.getEvt(key=dgkey)):
Expand All @@ -73,17 +72,41 @@ def fix(tymth, tock=0.0, **opts):
verfers = serder.verfers or []
ndigers = serder.ndigers or []

if val[0].qb64 in signify_group_habs:
continue

for verfer in verfers:
prefix_by_public_key[verfer.qb64] = val

for diger in ndigers:
prefix_by_next_key_digest[diger.qb64] = val

# pretty
pre_name_cache = dict()
for caid in caids:
with existing.existingHby(name=caid, base=args.base) as hby:
for pre, hab in hby.habs.items():
print(f"checking {pre}")
pre_name_cache[pre] = hab.name

# Arby's
# update existing hab records with the correct smids and rmids
for caid in caids:
with existing.existingHby(name=caid, base=args.base) as hby:
print()
print(f"Hby {hby.name}")

if not hasattr(hab, "smids") and not hasattr(hab, "rmids"):
for pre, hab in hby.habs.items():
if type(hab) is not habbing.SignifyGroupHab:
print(f"\t skipping {pre} - {type(hab)}")
continue

print()
print(f"\t {hab.name} - {pre} - {type(hab)}")
print()

if not hasattr(hab, "smids") and not hasattr(hab, "rmids") or \
hab.smids is None and hab.rmids is None:
print()
smids = set()
rmids = set()
for v in hab.kever.verfers:
Expand All @@ -94,20 +117,22 @@ def fix(tymth, tock=0.0, **opts):
if v.qb64 in prefix_by_next_key_digest:
rmids.add(prefix_by_next_key_digest[v.qb64][0].qb64)

hab.smids = list(smids)
hab.rmids = list(rmids)
else:
print("already has smids and rmids")
print(f"{hab.smids} {hab.rmids}")

print("done with hab")
print()
print()

with existing.existingHby(name=caid, base=args.base) as hby:
for pre, hab in hby.habs.items():
print(f"post update {pre} {type(hab)}")
if isinstance(hab, habbing.SignifyHab):
continue
print(hab.smids)
print(hab.rmids)
print(f"\t Proposed smids and rmids updates for {hab.name} - {pre}:")
print(f"\t\t smids: {smids}")
for smid in smids:
print(f"\t\t\t -> {smid} {pre_name_cache.get(smid)}")
print(f"\t\t rmids: {rmids}")
for rmid in rmids:
print(f"\t\t\t -> {rmid} {pre_name_cache.get(rmid)}")

if args.force:
habr = hab.db.habs.get(keys=(hab.pre,))
habr.smids = list(smids)
habr.rmids = list(rmids)
print(f"\t Updating {habr}")
hab.db.habs.pin(keys=(hab.pre,), val=habr)
print()
else:
print()
print("no updates performed, use --force to apply changes")
print()

0 comments on commit 0c1984f

Please sign in to comment.