Skip to content

Commit

Permalink
refactor names of ClanDom and CastDoms Add Castage becasue need to sp…
Browse files Browse the repository at this point in the history
…ecify keyword paramter when casting
  • Loading branch information
SmithSamuelM committed Apr 12, 2024
1 parent f909152 commit 8160ded
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
14 changes: 7 additions & 7 deletions src/keri/core/serdering.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

from .counting import GenDex, AllTags, Counter, SealDex_2_0

from .structing import Sealer, ClanDom
from .structing import Sealer, SClanDom



Expand Down Expand Up @@ -365,12 +365,12 @@ class Serder:

# map seal clan names to seal counter code for grouping seals in anchor list
ClanCodes = dict()
ClanCodes[ClanDom.SealDigest.__name__] = SealDex_2_0.DigestSealSingles
ClanCodes[ClanDom.SealRoot.__name__] = SealDex_2_0.MerkleRootSealSingles
ClanCodes[ClanDom.SealBacker.__name__] = SealDex_2_0.BackerRegistrarSealCouples
ClanCodes[ClanDom.SealLast.__name__] = SealDex_2_0.SealSourceLastSingles
ClanCodes[ClanDom.SealTrans.__name__] = SealDex_2_0.SealSourceCouples
ClanCodes[ClanDom.SealEvent.__name__] = SealDex_2_0.SealSourceTriples
ClanCodes[SClanDom.SealDigest.__name__] = SealDex_2_0.DigestSealSingles
ClanCodes[SClanDom.SealRoot.__name__] = SealDex_2_0.MerkleRootSealSingles
ClanCodes[SClanDom.SealBacker.__name__] = SealDex_2_0.BackerRegistrarSealCouples
ClanCodes[SClanDom.SealLast.__name__] = SealDex_2_0.SealSourceLastSingles
ClanCodes[SClanDom.SealTrans.__name__] = SealDex_2_0.SealSourceCouples
ClanCodes[SClanDom.SealEvent.__name__] = SealDex_2_0.SealSourceTriples

# map seal counter code to seal clan name for parsing seal groups in anchor list
CodeClans = { val: key for key, val in ClanCodes.items()} # invert dict
Expand Down
28 changes: 18 additions & 10 deletions src/keri/core/structing.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@
StateEvent = namedtuple("StateEvent", 's t d')


# Cast conversion: duple (c, k)
# s = cast as appropriate namedtuple with values as primitive classes
# k = keyword parameter name to use when casting
Castage = namedtuple('Castage', "c k")


@dataclass(frozen=True)
class EmptyClanCodex(MapDom):
class EmptyClanDom(MapDom):
"""
SealClanDom is dataclass of namedtuple seal class references (clans) each
indexed by its class name.
Expand All @@ -103,11 +109,11 @@ class EmptyClanCodex(MapDom):
def __iter__(self):
return iter(astuple(self)) # enables value not key inclusion test with "in"

EmptyClanDex = EmptyClanCodex() # create instance
EClanDom = EmptyClanDom() # create instance


@dataclass(frozen=True)
class EmptyCastCodex(MapDom):
class EmptyCastDom(MapDom):
"""
SealCastCodex is dataclass of namedtuple instances (seal casts) whose values
are named primitive class references
Expand All @@ -126,7 +132,7 @@ class EmptyCastCodex(MapDom):
def __iter__(self):
return iter(astuple(self)) # enables value not key inclusion test with "in"

EmptyCastDex = EmptyCastCodex() # create instance
ECastDom = EmptyCastDom() # create instance


@dataclass(frozen=True)
Expand All @@ -153,7 +159,9 @@ class SealClanDom(MapDom):
def __iter__(self):
return iter(astuple(self)) # enables value not key inclusion test with "in"

ClanDom = SealClanDom() # create instance
SClanDom = SealClanDom() # create instance




@dataclass(frozen=True)
Expand Down Expand Up @@ -182,7 +190,7 @@ class SealCastDom(MapDom):
def __iter__(self):
return iter(astuple(self)) # enables value not key inclusion test with "in"

CastDom = SealCastDom() # create instance
SCastDom = SealCastDom() # create instance



Expand Down Expand Up @@ -252,8 +260,8 @@ class Structor:
"""
Clans = EmptyClanDex # known namedtuple clans. Override in subclass with non-empty
Casts = EmptyCastDex # known namedtuple casts. Override in subclass with non-empty
Clans = EClanDom # known namedtuple clans. Override in subclass with non-empty
Casts = ECastDom # known namedtuple casts. Override in subclass with non-empty
# Create .Names dict that maps tuple of clan/cast fields names to its namedtuple
# class type name so can look up a know clan or cast given a matching tuple
# of either field names from a namedtuple or keys from a dict. The tuple of
Expand Down Expand Up @@ -563,8 +571,8 @@ class Sealer(Structor):
"""
Clans = ClanDom # known namedtuple clans. Override in subclass with non-empty
Casts = CastDom # known namedtuple casts. Override in subclass with non-empty
Clans = SClanDom # known namedtuple clans. Override in subclass with non-empty
Casts = SCastDom # known namedtuple casts. Override in subclass with non-empty
# Create .Names dict that maps clan/cast fields names to its namedtuple
# class type name so can look up a know clan or cast given a matching set
# of either field names from a namedtuple or keys from a dict.
Expand Down
16 changes: 8 additions & 8 deletions tests/core/test_structing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
from keri.core import structing
from keri.core.structing import (SealDigest, SealRoot, SealBacker, SealEvent,
SealLast, SealTrans)
from keri.core.structing import (Structor, EmptyClanDex, EmptyCastDex,
Sealer, ClanDom, CastDom, )
from keri.core.structing import (Structor, EClanDom, ECastDom,
Sealer, SClanDom, SCastDom, )


def test_structor_class():
"""
test Structor class variables etc
"""
assert Structor.Clans == EmptyClanDex
assert Structor.Casts == EmptyCastDex
assert Structor.Clans == EClanDom
assert Structor.Casts == ECastDom
assert Structor.Names == {}

"""End Test"""
Expand Down Expand Up @@ -447,7 +447,7 @@ def test_seal_dexes():
test Seal Codexes
"""

assert asdict(ClanDom) == \
assert asdict(SClanDom) == \
{
'SealDigest': SealDigest,
'SealRoot': SealRoot,
Expand All @@ -457,7 +457,7 @@ def test_seal_dexes():
'SealEvent': SealEvent,
}

assert asdict(CastDom) == \
assert asdict(SCastDom) == \
{
'SealDigest': SealDigest(d=Diger),
'SealRoot': SealRoot(rd=Diger),
Expand All @@ -471,8 +471,8 @@ def test_sealer_class():
"""
test sealer class variables etc
"""
assert Sealer.Clans == ClanDom
assert Sealer.Casts == CastDom
assert Sealer.Clans == SClanDom
assert Sealer.Casts == SCastDom
assert Sealer.Names == \
{
('d',): 'SealDigest',
Expand Down

0 comments on commit 8160ded

Please sign in to comment.