From dcad23c8185275a752c7b1071c3ad3e4b013e70b Mon Sep 17 00:00:00 2001 From: timotheyca Date: Sat, 18 Jun 2022 18:35:01 +0300 Subject: [PATCH] less of direct .resolve() calls --- .../abstractreductionchainmetafactory.py | 2 +- rainbowadn/chain/block.py | 14 ++--- rainbowadn/chain/blockchain.py | 30 +++++----- rainbowadn/chain/blockchainprotocol.py | 4 +- rainbowadn/chain/blockcollectioninterface.py | 16 ++--- rainbowadn/chain/chaincollectionfactory.py | 2 +- rainbowadn/chain/chaincollectioninterface.py | 2 +- rainbowadn/chain/reduction/reduced.py | 2 +- rainbowadn/chain/reduction/reduction.py | 12 ++-- .../reduction/reductionchainmetafactory.py | 2 +- .../chain/reduction/reductionchainprotocol.py | 4 +- .../chain/reduction/reductionprotocol.py | 4 +- .../chain/reduction/reductionstageprotocol.py | 8 +-- .../stages/derivation/activestageprotocol.py | 14 ++--- .../derivation/activestagestateprotocol.py | 6 +- .../chain/stages/derivation/derivedstage.py | 2 +- .../chain/stages/derivation/derivedstate.py | 2 +- rainbowadn/chain/stages/stage.py | 26 ++++---- rainbowadn/chain/stages/stageprotocol.py | 4 +- rainbowadn/chain/stages/stagestateprotocol.py | 4 +- .../chain/states/activestateprotocol.py | 4 +- .../states/metareductionstateprotocol.py | 8 +-- rainbowadn/chain/states/stateprotocol.py | 4 +- rainbowadn/{hashing => core}/__init__.py | 0 .../{hashing => core}/hash_point_format.py | 4 +- rainbowadn/{hashing => core}/hashpoint.py | 8 +-- rainbowadn/{hashing => core}/hashresolver.py | 0 .../{hashing => core}/localmetaorigin.py | 8 +-- rainbowadn/{hashing => core}/localorigin.py | 4 +- rainbowadn/{hashing => core}/mentionable.py | 2 +- rainbowadn/{hashing => core}/metaorigin.py | 6 +- .../{hashing => core}/nullability/__init__.py | 0 .../{hashing => core}/nullability/notnull.py | 2 +- .../{hashing => core}/nullability/null.py | 2 +- .../{hashing => core}/nullability/nullable.py | 0 .../nullability/nullablereference.py | 60 +++++++++++-------- rainbowadn/{hashing => core}/origin.py | 2 +- .../{hashing => core}/rainbow_factory.py | 2 +- .../{hashing => core}/recursivementionable.py | 4 +- .../{hashing => core}/resolvermetaorigin.py | 15 +++-- .../{hashing => core}/resolverorigin.py | 10 ++-- rainbowadn/{hashing => core}/static.py | 6 +- rainbowadn/data/atomic/atomic.py | 6 +- rainbowadn/data/collection/array/array.py | 12 ++-- .../collectioninterface.py | 2 +- rainbowadn/data/collection/keyed.py | 4 +- rainbowadn/data/collection/keymetadata.py | 10 ++-- rainbowadn/data/collection/keyvalue.py | 8 +-- rainbowadn/data/collection/pair.py | 12 ++-- rainbowadn/data/collection/stack/stack.py | 20 +++---- .../trees/binary/actions/compareaction.py | 2 +- .../trees/binary/activebinarytree.py | 16 ++--- .../data/collection/trees/binary/avl.py | 2 +- .../binary/balancedtreecreationprotocol.py | 2 +- .../collection/trees/binary/binarytree.py | 14 ++--- .../binary/binarytreebalancingprotocol.py | 2 +- .../binary/binarytreecreationprotocol.py | 2 +- .../trees/binary/binarytreesplit.py | 2 +- .../collection/trees/comparison/comparator.py | 2 +- .../trees/comparison/hashcomparator.py | 2 +- .../trees/comparison/keyedcomparator.py | 2 +- .../trees/comparison/plaincomparator.py | 2 +- rainbowadn/encryption/encrypted.py | 14 ++--- rainbowadn/testing/dictresolver.py | 8 +-- rainbowadn/testing/failresolver.py | 2 +- rainbowadn/testing/test_all.py | 16 ++--- rainbowadn/toplevel/__init__.py | 0 rainbowadn/toplevel/thresholdprotocol.py | 10 ++++ rainbowadn/toplevel/validreference.py | 48 +++++++++++++++ rainbowadn/v13/bankchain.py | 4 +- rainbowadn/v13/bankprotocol.py | 16 +++-- rainbowadn/v13/bankstate.py | 24 ++++---- rainbowadn/v13/signature.py | 2 +- rainbowadn/v13/transaction.py | 51 ++++++++++------ .../wrisbt/weakreferenceindexsetbtree.py | 30 ++++++---- rainbowadn/wrisbt/wrisbtchainprotocol.py | 4 +- rainbowadn/wrisbt/wrisbtindex.py | 12 ++-- rainbowadn/wrisbt/wrisbtprotocol.py | 2 +- rainbowadn/wrisbt/wrisbtroot.py | 27 +++++---- 79 files changed, 392 insertions(+), 313 deletions(-) rename rainbowadn/{hashing => core}/__init__.py (100%) rename rainbowadn/{hashing => core}/hash_point_format.py (80%) rename rainbowadn/{hashing => core}/hashpoint.py (89%) rename rainbowadn/{hashing => core}/hashresolver.py (100%) rename rainbowadn/{hashing => core}/localmetaorigin.py (72%) rename rainbowadn/{hashing => core}/localorigin.py (79%) rename rainbowadn/{hashing => core}/mentionable.py (84%) rename rainbowadn/{hashing => core}/metaorigin.py (78%) rename rainbowadn/{hashing => core}/nullability/__init__.py (100%) rename rainbowadn/{hashing => core}/nullability/notnull.py (89%) rename rainbowadn/{hashing => core}/nullability/null.py (87%) rename rainbowadn/{hashing => core}/nullability/nullable.py (100%) rename rainbowadn/{hashing => core}/nullability/nullablereference.py (51%) rename rainbowadn/{hashing => core}/origin.py (82%) rename rainbowadn/{hashing => core}/rainbow_factory.py (85%) rename rainbowadn/{hashing => core}/recursivementionable.py (81%) rename rainbowadn/{hashing => core}/resolvermetaorigin.py (64%) rename rainbowadn/{hashing => core}/resolverorigin.py (81%) rename rainbowadn/{hashing => core}/static.py (86%) create mode 100644 rainbowadn/toplevel/__init__.py create mode 100644 rainbowadn/toplevel/thresholdprotocol.py create mode 100644 rainbowadn/toplevel/validreference.py diff --git a/rainbowadn/chain/abstractreductionchainmetafactory.py b/rainbowadn/chain/abstractreductionchainmetafactory.py index fdf8b8d..f9089e1 100644 --- a/rainbowadn/chain/abstractreductionchainmetafactory.py +++ b/rainbowadn/chain/abstractreductionchainmetafactory.py @@ -2,7 +2,7 @@ from typing import Generic, TypeVar from rainbowadn.chain.chaincollectionfactory import ChainCollectionFactory from rainbowadn.chain.reduction.reductionprotocol import ReductionProtocol -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('AbstractReductionChainMetaFactory',) diff --git a/rainbowadn/chain/block.py b/rainbowadn/chain/block.py index 33c2bae..5fa67d3 100644 --- a/rainbowadn/chain/block.py +++ b/rainbowadn/chain/block.py @@ -1,12 +1,12 @@ from typing import Generic, Iterable, TypeVar -from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin __all__ = ('Block', 'BlockFactory',) diff --git a/rainbowadn/chain/blockchain.py b/rainbowadn/chain/blockchain.py index d881ec2..7155b98 100644 --- a/rainbowadn/chain/blockchain.py +++ b/rainbowadn/chain/blockchain.py @@ -4,10 +4,10 @@ from rainbowadn.chain.block import Block, BlockFactory from rainbowadn.chain.blockchainprotocol import BlockChainProtocol from rainbowadn.chain.chaincollectionfactory import ChainCollectionFactory from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.null import Null -from rainbowadn.hashing.nullability.nullablereference import NullableReference -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.null import Null +from rainbowadn.core.nullability.nullablereference import NullableReference +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('BlockChain', 'BlockChainFactory',) @@ -75,16 +75,13 @@ class BlockChain( ) -> NullableReference[ StateType ]: - if self.reference.reference.null(): + if self.reference.null(): return NullableReference( Null(), self.protocol.state_factory ) else: - block: Block[ - HeaderType, - StateType - ] = self.reference.reference.resolve().resolve() + block: Block[HeaderType, StateType] = self.reference.resolve() assert isinstance(block, Block) return NullableReference.of(block.state) @@ -115,21 +112,21 @@ class BlockChain( HeaderType, ActualStateType ]: - assert not self.reference.reference.null() + assert not self.reference.null() block: Block[ HeaderType, StateType - ] = self.reference.reference.resolve().resolve() + ] = self.reference.resolve() assert isinstance(block, Block) return self.factory().from_reference(block.previous) def verify(self) -> bool: - if self.reference.reference.null(): + if self.reference.null(): return True else: - return self.verify_link( - self.previous().reference - ) and self.previous().verify() + assert self.verify_link(self.previous().reference) + assert self.previous().verify() + return True def _verify_link( self, @@ -149,11 +146,12 @@ class BlockChain( assert block.previous == previous previous_chain = self.factory().from_reference(previous) assert isinstance(previous_chain, BlockChain) - return self.protocol.state_protocol.verify( + assert self.protocol.state_protocol.verify( previous_chain.state(), block.header, block.state, ) + return True def _actual_state_factory(self) -> RainbowFactory[ActualStateType]: return self.protocol.actual_state_factory() diff --git a/rainbowadn/chain/blockchainprotocol.py b/rainbowadn/chain/blockchainprotocol.py index 76095b2..77e93c5 100644 --- a/rainbowadn/chain/blockchainprotocol.py +++ b/rainbowadn/chain/blockchainprotocol.py @@ -1,8 +1,8 @@ from typing import Generic, TypeVar from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('BlockChainProtocol',) diff --git a/rainbowadn/chain/blockcollectioninterface.py b/rainbowadn/chain/blockcollectioninterface.py index e5a4a9c..d47b1a9 100644 --- a/rainbowadn/chain/blockcollectioninterface.py +++ b/rainbowadn/chain/blockcollectioninterface.py @@ -1,10 +1,10 @@ from typing import Generic, TypeVar from rainbowadn.data.collection.collection_interface.collectioninterface import CollectionInterface -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.null import Null -from rainbowadn.hashing.nullability.nullablereference import NullableReference -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.null import Null +from rainbowadn.core.nullability.nullablereference import NullableReference +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('BlockCollectionInterface',) @@ -38,11 +38,11 @@ class BlockCollectionInterface( previous: NullableReference[BlockType] ) -> bool: assert isinstance(previous, NullableReference) - if self.reference.reference.null(): + if self.reference.null(): return True else: return self._verify_link( - self.reference.reference.resolve().resolve(), + self.reference.resolve(), previous ) @@ -53,10 +53,10 @@ class BlockCollectionInterface( raise NotImplementedError def actual_state(self) -> NullableReference[ActualStateType]: - if self.reference.reference.null(): + if self.reference.null(): return NullableReference(Null(), self._actual_state_factory()) else: - return NullableReference.of(self._actual_state(self.reference.reference.resolve().resolve())) + return NullableReference.of(self._actual_state(self.reference.resolve())) def add( self, diff --git a/rainbowadn/chain/chaincollectionfactory.py b/rainbowadn/chain/chaincollectionfactory.py index 032cee1..ab4a84c 100644 --- a/rainbowadn/chain/chaincollectionfactory.py +++ b/rainbowadn/chain/chaincollectionfactory.py @@ -1,7 +1,7 @@ from typing import Generic, TypeVar from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface -from rainbowadn.hashing.nullability.nullablereference import NullableReference +from rainbowadn.core.nullability.nullablereference import NullableReference __all__ = ('ChainCollectionFactory',) diff --git a/rainbowadn/chain/chaincollectioninterface.py b/rainbowadn/chain/chaincollectioninterface.py index 7d4e9fc..0cde9a8 100644 --- a/rainbowadn/chain/chaincollectioninterface.py +++ b/rainbowadn/chain/chaincollectioninterface.py @@ -2,7 +2,7 @@ import abc from typing import Generic, TypeVar from rainbowadn.chain.blockcollectioninterface import BlockCollectionInterface -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('ChainCollectionInterface',) diff --git a/rainbowadn/chain/reduction/reduced.py b/rainbowadn/chain/reduction/reduced.py index 8fe9a8c..8bc0642 100644 --- a/rainbowadn/chain/reduction/reduced.py +++ b/rainbowadn/chain/reduction/reduced.py @@ -1,7 +1,7 @@ from typing import Generic, TypeVar from rainbowadn.chain.reduction.reductionresult import ReductionResult -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('Reduced',) diff --git a/rainbowadn/chain/reduction/reduction.py b/rainbowadn/chain/reduction/reduction.py index cae6a86..6258018 100644 --- a/rainbowadn/chain/reduction/reduction.py +++ b/rainbowadn/chain/reduction/reduction.py @@ -1,12 +1,12 @@ from typing import Generic, Iterable, TypeVar from rainbowadn.chain.reduction.reductionresult import ReductionResult -from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin __all__ = ('Reduction', 'ReductionFactory',) diff --git a/rainbowadn/chain/reduction/reductionchainmetafactory.py b/rainbowadn/chain/reduction/reductionchainmetafactory.py index 817b368..1f39a3f 100644 --- a/rainbowadn/chain/reduction/reductionchainmetafactory.py +++ b/rainbowadn/chain/reduction/reductionchainmetafactory.py @@ -8,7 +8,7 @@ from rainbowadn.chain.reduction.reduction import Reduction from rainbowadn.chain.reduction.reductionchainprotocol import ReductionChainProtocol from rainbowadn.chain.reduction.reductionprotocol import ReductionProtocol from rainbowadn.chain.stages.stage import StateStage -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('ReductionChainMetaFactory',) diff --git a/rainbowadn/chain/reduction/reductionchainprotocol.py b/rainbowadn/chain/reduction/reductionchainprotocol.py index d8b3ac1..9dde6f9 100644 --- a/rainbowadn/chain/reduction/reductionchainprotocol.py +++ b/rainbowadn/chain/reduction/reductionchainprotocol.py @@ -7,8 +7,8 @@ from rainbowadn.chain.reduction.reductionstageprotocol import ReductionStageProt from rainbowadn.chain.stages.derivation.activestageprotocol import ActiveStageProtocol from rainbowadn.chain.stages.derivation.activestagestateprotocol import ActiveStageStateProtocol from rainbowadn.chain.stages.stage import StateStage, StateStageFactory -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('ReductionChainProtocol',) diff --git a/rainbowadn/chain/reduction/reductionprotocol.py b/rainbowadn/chain/reduction/reductionprotocol.py index eb2284d..a34a398 100644 --- a/rainbowadn/chain/reduction/reductionprotocol.py +++ b/rainbowadn/chain/reduction/reductionprotocol.py @@ -2,8 +2,8 @@ from typing import Generic, TypeVar from rainbowadn.chain.reduction.reduction import Reduction from rainbowadn.chain.reduction.reductionresult import ReductionResult -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('ReductionProtocol',) diff --git a/rainbowadn/chain/reduction/reductionstageprotocol.py b/rainbowadn/chain/reduction/reductionstageprotocol.py index 2457d3e..d8863dc 100644 --- a/rainbowadn/chain/reduction/reductionstageprotocol.py +++ b/rainbowadn/chain/reduction/reductionstageprotocol.py @@ -8,8 +8,8 @@ from rainbowadn.chain.stages.derivation.activestageprotocol import ActiveStagePr from rainbowadn.chain.stages.derivation.derived import Derived from rainbowadn.chain.stages.derivation.derivedstage import DerivedStage from rainbowadn.chain.stages.derivation.derivedstate import DerivedState -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.nullablereference import NullableReference +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.nullablereference import NullableReference __all__ = ('ReductionStageProtocol',) @@ -31,10 +31,10 @@ class ReductionStageProtocol( previous: NullableReference[AccumulatorType], ) -> HashPoint[AccumulatorType]: assert isinstance(previous, NullableReference) - if previous.reference.null(): + if previous.null(): return self.protocol.initial(previous.factory) else: - return self.protocol.header_filter(previous.reference.resolve()) + return self.protocol.header_filter(previous.hashpoint()) def derive_header( self, diff --git a/rainbowadn/chain/stages/derivation/activestageprotocol.py b/rainbowadn/chain/stages/derivation/activestageprotocol.py index 8f28050..802d837 100644 --- a/rainbowadn/chain/stages/derivation/activestageprotocol.py +++ b/rainbowadn/chain/stages/derivation/activestageprotocol.py @@ -5,10 +5,10 @@ from rainbowadn.chain.stages.derivation.derivedstage import DerivedStage from rainbowadn.chain.stages.derivation.derivedstate import DerivedState from rainbowadn.chain.stages.stage import StageStage, StageStageFactory, StateStage from rainbowadn.chain.stages.stageprotocol import StageProtocol -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.null import Null -from rainbowadn.hashing.nullability.nullablereference import NullableReference -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.null import Null +from rainbowadn.core.nullability.nullablereference import NullableReference +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('ActiveStageProtocol',) @@ -42,12 +42,10 @@ class ActiveStageProtocol( ) -> NullableReference[BaseStateType]: assert isinstance(previous_reference, NullableReference) assert isinstance(base_state_factory, RainbowFactory) - if previous_reference.reference.null(): + if previous_reference.null(): return NullableReference(Null(), base_state_factory) else: - previous_state_stage: StateStage[HeaderType, BaseStateType, StageType] = ( - previous_reference.reference.resolve().resolve() - ) + previous_state_stage: StateStage[HeaderType, BaseStateType, StageType] = previous_reference.resolve() assert isinstance(previous_state_stage, StateStage) return NullableReference.of(previous_state_stage.state) diff --git a/rainbowadn/chain/stages/derivation/activestagestateprotocol.py b/rainbowadn/chain/stages/derivation/activestagestateprotocol.py index f0a13fb..7d5a71d 100644 --- a/rainbowadn/chain/stages/derivation/activestagestateprotocol.py +++ b/rainbowadn/chain/stages/derivation/activestagestateprotocol.py @@ -3,9 +3,9 @@ from typing import TypeVar from rainbowadn.chain.stages.derivation.activestageprotocol import ActiveStageProtocol from rainbowadn.chain.stages.stage import StateStage from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.nullablereference import NullableReference -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.nullablereference import NullableReference +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('ActiveStageStateProtocol',) diff --git a/rainbowadn/chain/stages/derivation/derivedstage.py b/rainbowadn/chain/stages/derivation/derivedstage.py index cf8aead..6fe9f81 100644 --- a/rainbowadn/chain/stages/derivation/derivedstage.py +++ b/rainbowadn/chain/stages/derivation/derivedstage.py @@ -1,7 +1,7 @@ from typing import Generic, TypeVar from rainbowadn.chain.stages.derivation.derived import Derived -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('DerivedStage',) diff --git a/rainbowadn/chain/stages/derivation/derivedstate.py b/rainbowadn/chain/stages/derivation/derivedstate.py index a7d2f9e..36e8a2f 100644 --- a/rainbowadn/chain/stages/derivation/derivedstate.py +++ b/rainbowadn/chain/stages/derivation/derivedstate.py @@ -1,7 +1,7 @@ from typing import Generic, TypeVar from rainbowadn.chain.stages.derivation.derived import Derived -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('DerivedState',) diff --git a/rainbowadn/chain/stages/stage.py b/rainbowadn/chain/stages/stage.py index a9692f3..af5fc4e 100644 --- a/rainbowadn/chain/stages/stage.py +++ b/rainbowadn/chain/stages/stage.py @@ -1,14 +1,14 @@ from typing import Generic, Iterable, TypeVar from rainbowadn.chain.stages.stageprotocol import StageProtocol -from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.nullability.null import Null -from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.nullability.null import Null +from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin __all__ = ( 'StageStage', @@ -54,10 +54,10 @@ class StageStage( ) -> NullableReference[BaseStateType]: assert isinstance(previous, NullableReference) assert isinstance(base_factory, RainbowFactory) - if previous.reference.null(): + if previous.null(): return NullableReference(Null(), base_factory) else: - state_stage: StateStage[HeaderType, BaseStateType, StageType] = previous.reference.resolve().resolve() + state_stage: StateStage[HeaderType, BaseStateType, StageType] = previous.resolve() assert isinstance(state_stage, StateStage) return NullableReference.of(state_stage.state) @@ -70,16 +70,14 @@ class StageStage( assert isinstance(previous, NullableReference) assert isinstance(header, HashPoint) assert isinstance(base_factory, RainbowFactory) - if self.previous.reference.null(): + if self.previous.null(): return self.protocol.verify_header( self._previous_state(previous, base_factory), header, self.stage ) else: - previous_stage: StageStage[HeaderType, BaseStateType, StageType] = ( - self.previous.reference.resolve().resolve() - ) + previous_stage: StageStage[HeaderType, BaseStateType, StageType] = self.previous.resolve() assert isinstance(previous_stage, StageStage) return self.protocol.verify_stage( previous_stage.stage, diff --git a/rainbowadn/chain/stages/stageprotocol.py b/rainbowadn/chain/stages/stageprotocol.py index 75bd1e7..7366998 100644 --- a/rainbowadn/chain/stages/stageprotocol.py +++ b/rainbowadn/chain/stages/stageprotocol.py @@ -1,7 +1,7 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.nullablereference import NullableReference +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.nullablereference import NullableReference __all__ = ('StageProtocol',) diff --git a/rainbowadn/chain/stages/stagestateprotocol.py b/rainbowadn/chain/stages/stagestateprotocol.py index a5bd4cd..73abff7 100644 --- a/rainbowadn/chain/stages/stagestateprotocol.py +++ b/rainbowadn/chain/stages/stagestateprotocol.py @@ -2,8 +2,8 @@ from typing import Generic, TypeVar from rainbowadn.chain.stages.stage import StateStage from rainbowadn.chain.states.stateprotocol import StateProtocol -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.nullablereference import NullableReference +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.nullablereference import NullableReference __all__ = ('StageStateProtocol',) diff --git a/rainbowadn/chain/states/activestateprotocol.py b/rainbowadn/chain/states/activestateprotocol.py index 09f3167..656db59 100644 --- a/rainbowadn/chain/states/activestateprotocol.py +++ b/rainbowadn/chain/states/activestateprotocol.py @@ -1,8 +1,8 @@ from typing import TypeVar from rainbowadn.chain.states.stateprotocol import StateProtocol -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.nullablereference import NullableReference +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.nullablereference import NullableReference __all__ = ('ActiveStateProtocol',) diff --git a/rainbowadn/chain/states/metareductionstateprotocol.py b/rainbowadn/chain/states/metareductionstateprotocol.py index b541226..7a5858c 100644 --- a/rainbowadn/chain/states/metareductionstateprotocol.py +++ b/rainbowadn/chain/states/metareductionstateprotocol.py @@ -1,8 +1,8 @@ from typing import TypeVar from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.nullablereference import NullableReference +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.nullablereference import NullableReference __all__ = ('MetaReductionStateProtocol',) @@ -40,9 +40,9 @@ class MetaReductionStateProtocol(ActiveStateProtocol[HeaderType, StateType]): ) -> HashPoint[StateType]: assert isinstance(previous, NullableReference) assert isinstance(header, HashPoint) - if previous.reference.null(): + if previous.null(): previous_state: HashPoint[StateType] = self._initial_state() else: - previous_state: HashPoint[StateType] = previous.reference.resolve() + previous_state: HashPoint[StateType] = previous.hashpoint() assert isinstance(previous_state, HashPoint) return self._derive(previous_state, header) diff --git a/rainbowadn/chain/states/stateprotocol.py b/rainbowadn/chain/states/stateprotocol.py index 81b3fe4..aefb6a4 100644 --- a/rainbowadn/chain/states/stateprotocol.py +++ b/rainbowadn/chain/states/stateprotocol.py @@ -1,7 +1,7 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.nullablereference import NullableReference +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.nullablereference import NullableReference __all__ = ('StateProtocol',) diff --git a/rainbowadn/hashing/__init__.py b/rainbowadn/core/__init__.py similarity index 100% rename from rainbowadn/hashing/__init__.py rename to rainbowadn/core/__init__.py diff --git a/rainbowadn/hashing/hash_point_format.py b/rainbowadn/core/hash_point_format.py similarity index 80% rename from rainbowadn/hashing/hash_point_format.py rename to rainbowadn/core/hash_point_format.py index 80ff52c..2d989bc 100644 --- a/rainbowadn/hashing/hash_point_format.py +++ b/rainbowadn/core/hash_point_format.py @@ -1,5 +1,5 @@ -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.recursivementionable import RecursiveMentionable +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.recursivementionable import RecursiveMentionable __all__ = ('hash_point_format', 'tabulate',) diff --git a/rainbowadn/hashing/hashpoint.py b/rainbowadn/core/hashpoint.py similarity index 89% rename from rainbowadn/hashing/hashpoint.py rename to rainbowadn/core/hashpoint.py index 88d6095..c50f102 100644 --- a/rainbowadn/hashing/hashpoint.py +++ b/rainbowadn/core/hashpoint.py @@ -1,10 +1,10 @@ import hashlib from typing import Generic, TypeVar -from rainbowadn.hashing.localorigin import LocalOrigin -from rainbowadn.hashing.mentionable import Mentionable -from rainbowadn.hashing.origin import Origin -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.localorigin import LocalOrigin +from rainbowadn.core.mentionable import Mentionable +from rainbowadn.core.origin import Origin +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('HashPoint',) diff --git a/rainbowadn/hashing/hashresolver.py b/rainbowadn/core/hashresolver.py similarity index 100% rename from rainbowadn/hashing/hashresolver.py rename to rainbowadn/core/hashresolver.py diff --git a/rainbowadn/hashing/localmetaorigin.py b/rainbowadn/core/localmetaorigin.py similarity index 72% rename from rainbowadn/hashing/localmetaorigin.py rename to rainbowadn/core/localmetaorigin.py index b43c523..3ae4d0f 100644 --- a/rainbowadn/hashing/localmetaorigin.py +++ b/rainbowadn/core/localmetaorigin.py @@ -1,9 +1,9 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.metaorigin import MetaOrigin -from rainbowadn.hashing.origin import Origin -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.metaorigin import MetaOrigin +from rainbowadn.core.origin import Origin +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('LocalMetaOrigin',) diff --git a/rainbowadn/hashing/localorigin.py b/rainbowadn/core/localorigin.py similarity index 79% rename from rainbowadn/hashing/localorigin.py rename to rainbowadn/core/localorigin.py index d1ff834..f92e236 100644 --- a/rainbowadn/hashing/localorigin.py +++ b/rainbowadn/core/localorigin.py @@ -1,7 +1,7 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.mentionable import Mentionable -from rainbowadn.hashing.origin import Origin +from rainbowadn.core.mentionable import Mentionable +from rainbowadn.core.origin import Origin __all__ = ('LocalOrigin',) diff --git a/rainbowadn/hashing/mentionable.py b/rainbowadn/core/mentionable.py similarity index 84% rename from rainbowadn/hashing/mentionable.py rename to rainbowadn/core/mentionable.py index 986d51e..6e05d21 100644 --- a/rainbowadn/hashing/mentionable.py +++ b/rainbowadn/core/mentionable.py @@ -1,6 +1,6 @@ from typing import TypeVar -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('Mentionable',) diff --git a/rainbowadn/hashing/metaorigin.py b/rainbowadn/core/metaorigin.py similarity index 78% rename from rainbowadn/hashing/metaorigin.py rename to rainbowadn/core/metaorigin.py index cdb0d4a..01e306a 100644 --- a/rainbowadn/hashing/metaorigin.py +++ b/rainbowadn/core/metaorigin.py @@ -1,8 +1,8 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.origin import Origin -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.origin import Origin +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('MetaOrigin',) diff --git a/rainbowadn/hashing/nullability/__init__.py b/rainbowadn/core/nullability/__init__.py similarity index 100% rename from rainbowadn/hashing/nullability/__init__.py rename to rainbowadn/core/nullability/__init__.py diff --git a/rainbowadn/hashing/nullability/notnull.py b/rainbowadn/core/nullability/notnull.py similarity index 89% rename from rainbowadn/hashing/nullability/notnull.py rename to rainbowadn/core/nullability/notnull.py index 6748b4b..d9044d3 100644 --- a/rainbowadn/hashing/nullability/notnull.py +++ b/rainbowadn/core/nullability/notnull.py @@ -1,6 +1,6 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.nullability.nullable import Nullable +from rainbowadn.core.nullability.nullable import Nullable __all__ = ('NotNull',) diff --git a/rainbowadn/hashing/nullability/null.py b/rainbowadn/core/nullability/null.py similarity index 87% rename from rainbowadn/hashing/nullability/null.py rename to rainbowadn/core/nullability/null.py index a472cba..690f9e1 100644 --- a/rainbowadn/hashing/nullability/null.py +++ b/rainbowadn/core/nullability/null.py @@ -1,6 +1,6 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.nullability.nullable import Nullable +from rainbowadn.core.nullability.nullable import Nullable __all__ = ('Null',) diff --git a/rainbowadn/hashing/nullability/nullable.py b/rainbowadn/core/nullability/nullable.py similarity index 100% rename from rainbowadn/hashing/nullability/nullable.py rename to rainbowadn/core/nullability/nullable.py diff --git a/rainbowadn/hashing/nullability/nullablereference.py b/rainbowadn/core/nullability/nullablereference.py similarity index 51% rename from rainbowadn/hashing/nullability/nullablereference.py rename to rainbowadn/core/nullability/nullablereference.py index 696e562..2f4bce2 100644 --- a/rainbowadn/hashing/nullability/nullablereference.py +++ b/rainbowadn/core/nullability/nullablereference.py @@ -1,38 +1,38 @@ from typing import Generic, Iterable, TypeVar -from rainbowadn.hashing.hash_point_format import hash_point_format -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.nullability.notnull import NotNull -from rainbowadn.hashing.nullability.null import Null -from rainbowadn.hashing.nullability.nullable import Nullable -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hash_point_format import hash_point_format +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.nullability.notnull import NotNull +from rainbowadn.core.nullability.null import Null +from rainbowadn.core.nullability.nullable import Nullable +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin __all__ = ('NullableReference', 'NullableReferenceFactory',) -ReferencedType = TypeVar('ReferencedType') +Referenced = TypeVar('Referenced') -class NullableReference(RecursiveMentionable, Generic[ReferencedType]): - def __factory__(self) -> RainbowFactory['NullableReference[ReferencedType]']: +class NullableReference(RecursiveMentionable, Generic[Referenced]): + def __factory__(self) -> RainbowFactory['NullableReference[Referenced]']: return NullableReferenceFactory(self.factory) def points(self) -> Iterable[HashPoint]: - if self.reference.null(): + if self.null(): return [] else: - return [self.reference.resolve()] + return [self.hashpoint()] def __bytes__(self): - if self.reference.null(): + if self.null(): return HashPoint.NULL_HASH else: - return self.reference.resolve().point + return self.hashpoint().point def __init__( - self, reference: Nullable[HashPoint[ReferencedType]], factory: RainbowFactory[ReferencedType] + self, reference: Nullable[HashPoint[Referenced]], factory: RainbowFactory[Referenced] ): assert isinstance(reference, Nullable) assert isinstance(factory, RainbowFactory) @@ -40,19 +40,19 @@ class NullableReference(RecursiveMentionable, Generic[ReferencedType]): self.factory = factory @classmethod - def of(cls, hash_point: HashPoint[ReferencedType]) -> 'NullableReference[ReferencedType]': + def of(cls, hash_point: HashPoint[Referenced]) -> 'NullableReference[Referenced]': assert isinstance(hash_point, HashPoint) return cls(NotNull(hash_point), hash_point.factory) @classmethod - def off(cls, value: ReferencedType) -> 'NullableReference[ReferencedType]': + def off(cls, value: Referenced) -> 'NullableReference[Referenced]': return cls.of(HashPoint.of(value)) def str(self, tab: int) -> str: - if self.reference.null(): + if self.null(): return f'-' else: - return f'{hash_point_format(self.reference.resolve(), tab)}' + return f'{hash_point_format(self.hashpoint(), tab)}' def __eq__(self, other): if isinstance(other, NullableReference): @@ -60,16 +60,24 @@ class NullableReference(RecursiveMentionable, Generic[ReferencedType]): else: return NotImplemented + def null(self) -> bool: + return self.reference.null() -FReferencedType = TypeVar('FReferencedType') + def hashpoint(self) -> HashPoint[Referenced]: + assert not self.null() + return self.reference.resolve() + + def resolve(self) -> Referenced: + assert not self.null() + return self.hashpoint().resolve() -class NullableReferenceFactory(RainbowFactory[NullableReference[FReferencedType]], Generic[FReferencedType]): - def __init__(self, factory: RainbowFactory[FReferencedType]): +class NullableReferenceFactory(RainbowFactory[NullableReference[Referenced]], Generic[Referenced]): + def __init__(self, factory: RainbowFactory[Referenced]): assert isinstance(factory, RainbowFactory) self.factory = factory - def from_bytes(self, source: bytes, resolver: HashResolver) -> NullableReference[FReferencedType]: + def from_bytes(self, source: bytes, resolver: HashResolver) -> NullableReference[Referenced]: assert isinstance(source, bytes) assert isinstance(resolver, HashResolver) if source == HashPoint.NULL_HASH: @@ -79,5 +87,5 @@ class NullableReferenceFactory(RainbowFactory[NullableReference[FReferencedType] ResolverOrigin(self.factory, source, resolver).hash_point() ) - def loose(self) -> RainbowFactory[NullableReference[FReferencedType]]: + def loose(self) -> RainbowFactory[NullableReference[Referenced]]: return self diff --git a/rainbowadn/hashing/origin.py b/rainbowadn/core/origin.py similarity index 82% rename from rainbowadn/hashing/origin.py rename to rainbowadn/core/origin.py index d96ee87..1429e64 100644 --- a/rainbowadn/hashing/origin.py +++ b/rainbowadn/core/origin.py @@ -1,6 +1,6 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('Origin',) diff --git a/rainbowadn/hashing/rainbow_factory.py b/rainbowadn/core/rainbow_factory.py similarity index 85% rename from rainbowadn/hashing/rainbow_factory.py rename to rainbowadn/core/rainbow_factory.py index d6441fb..688b73e 100644 --- a/rainbowadn/hashing/rainbow_factory.py +++ b/rainbowadn/core/rainbow_factory.py @@ -1,6 +1,6 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.hashresolver import HashResolver +from rainbowadn.core.hashresolver import HashResolver __all__ = ('RainbowFactory',) diff --git a/rainbowadn/hashing/recursivementionable.py b/rainbowadn/core/recursivementionable.py similarity index 81% rename from rainbowadn/hashing/recursivementionable.py rename to rainbowadn/core/recursivementionable.py index dd66886..60eaab5 100644 --- a/rainbowadn/hashing/recursivementionable.py +++ b/rainbowadn/core/recursivementionable.py @@ -1,8 +1,8 @@ import abc from typing import Iterable -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.mentionable import Mentionable +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.mentionable import Mentionable __all__ = ('RecursiveMentionable',) diff --git a/rainbowadn/hashing/resolvermetaorigin.py b/rainbowadn/core/resolvermetaorigin.py similarity index 64% rename from rainbowadn/hashing/resolvermetaorigin.py rename to rainbowadn/core/resolvermetaorigin.py index 391431c..322d6dc 100644 --- a/rainbowadn/hashing/resolvermetaorigin.py +++ b/rainbowadn/core/resolvermetaorigin.py @@ -1,11 +1,11 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.metaorigin import MetaOrigin -from rainbowadn.hashing.origin import Origin -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.metaorigin import MetaOrigin +from rainbowadn.core.origin import Origin +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.resolverorigin import ResolverOrigin __all__ = ('ResolverMetaOrigin',) @@ -26,3 +26,6 @@ class ResolverMetaOrigin(MetaOrigin[Mentioned], Generic[Mentioned]): def migrate(self, hash_point: HashPoint[Mentioned]) -> HashPoint[Mentioned]: assert isinstance(hash_point, HashPoint) return self.hash_point(hash_point.factory, hash_point.point) + + def migrate_resolved(self, mentioned: Mentioned) -> Mentioned: + return self.migrate(HashPoint.of(mentioned)).resolve() diff --git a/rainbowadn/hashing/resolverorigin.py b/rainbowadn/core/resolverorigin.py similarity index 81% rename from rainbowadn/hashing/resolverorigin.py rename to rainbowadn/core/resolverorigin.py index d01b5a0..1aa067c 100644 --- a/rainbowadn/hashing/resolverorigin.py +++ b/rainbowadn/core/resolverorigin.py @@ -1,10 +1,10 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.mentionable import Mentionable -from rainbowadn.hashing.origin import Origin -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.mentionable import Mentionable +from rainbowadn.core.origin import Origin +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('ResolverOrigin',) diff --git a/rainbowadn/hashing/static.py b/rainbowadn/core/static.py similarity index 86% rename from rainbowadn/hashing/static.py rename to rainbowadn/core/static.py index 8ffa110..bbbda75 100644 --- a/rainbowadn/hashing/static.py +++ b/rainbowadn/core/static.py @@ -1,9 +1,9 @@ import abc from typing import Generic, Type, TypeVar -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.mentionable import Mentionable -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.mentionable import Mentionable +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('StaticMentionable', 'StaticFactory',) diff --git a/rainbowadn/data/atomic/atomic.py b/rainbowadn/data/atomic/atomic.py index 885e5d3..cef4da8 100644 --- a/rainbowadn/data/atomic/atomic.py +++ b/rainbowadn/data/atomic/atomic.py @@ -1,9 +1,9 @@ import abc from typing import Type, TypeVar -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.static import StaticMentionable +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.static import StaticMentionable __all__ = ('Atomic',) diff --git a/rainbowadn/data/collection/array/array.py b/rainbowadn/data/collection/array/array.py index 1921810..cdf45d5 100644 --- a/rainbowadn/data/collection/array/array.py +++ b/rainbowadn/data/collection/array/array.py @@ -1,11 +1,11 @@ from typing import Generic, Iterable, TypeVar -from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin __all__ = ('Array', 'ArrayFactory',) diff --git a/rainbowadn/data/collection/collection_interface/collectioninterface.py b/rainbowadn/data/collection/collection_interface/collectioninterface.py index a072687..e0d9356 100644 --- a/rainbowadn/data/collection/collection_interface/collectioninterface.py +++ b/rainbowadn/data/collection/collection_interface/collectioninterface.py @@ -1,6 +1,6 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.nullability.nullablereference import NullableReference +from rainbowadn.core.nullability.nullablereference import NullableReference __all__ = ('CollectionInterface',) diff --git a/rainbowadn/data/collection/keyed.py b/rainbowadn/data/collection/keyed.py index 3df2ac4..bf942c5 100644 --- a/rainbowadn/data/collection/keyed.py +++ b/rainbowadn/data/collection/keyed.py @@ -1,8 +1,8 @@ import abc from typing import Generic, TypeVar -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.recursivementionable import RecursiveMentionable +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.recursivementionable import RecursiveMentionable __all__ = ('Keyed',) diff --git a/rainbowadn/data/collection/keymetadata.py b/rainbowadn/data/collection/keymetadata.py index 20e8d44..82bafe2 100644 --- a/rainbowadn/data/collection/keymetadata.py +++ b/rainbowadn/data/collection/keymetadata.py @@ -1,11 +1,11 @@ from typing import Generic, Iterable, TypeVar from rainbowadn.data.collection.keyed import Keyed -from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.resolverorigin import ResolverOrigin __all__ = ('KeyMetadata', 'KeyMetadataFactory',) diff --git a/rainbowadn/data/collection/keyvalue.py b/rainbowadn/data/collection/keyvalue.py index 56ab033..d61423f 100644 --- a/rainbowadn/data/collection/keyvalue.py +++ b/rainbowadn/data/collection/keyvalue.py @@ -1,10 +1,10 @@ from typing import Generic, Iterable, TypeVar from rainbowadn.data.collection.keyed import Keyed -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.resolverorigin import ResolverOrigin __all__ = ('KeyValue', 'KeyValueFactory',) diff --git a/rainbowadn/data/collection/pair.py b/rainbowadn/data/collection/pair.py index 7af3dad..1b805ff 100644 --- a/rainbowadn/data/collection/pair.py +++ b/rainbowadn/data/collection/pair.py @@ -1,11 +1,11 @@ from typing import Generic, Iterable, TypeVar -from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin __all__ = ('Pair', 'PairFactory',) diff --git a/rainbowadn/data/collection/stack/stack.py b/rainbowadn/data/collection/stack/stack.py index f85578b..f5702bb 100644 --- a/rainbowadn/data/collection/stack/stack.py +++ b/rainbowadn/data/collection/stack/stack.py @@ -1,13 +1,13 @@ from typing import Generic, Iterable, TypeVar -from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.nullability.null import Null -from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.nullability.null import Null +from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin __all__ = ('Stack', 'StackFactory',) @@ -74,10 +74,10 @@ class Stack(RecursiveMentionable, Generic[ElementType]): reference: NullableReference['Stack[ElementType]'] ) -> Iterable[HashPoint[ElementType]]: assert isinstance(reference, NullableReference) - if reference.reference.null(): + if reference.null(): pass else: - stack: Stack[ElementType] = reference.reference.resolve().resolve() + stack: Stack[ElementType] = reference.resolve() yield stack.element yield from cls.iter(stack.previous) diff --git a/rainbowadn/data/collection/trees/binary/actions/compareaction.py b/rainbowadn/data/collection/trees/binary/actions/compareaction.py index e8e1255..897e01b 100644 --- a/rainbowadn/data/collection/trees/binary/actions/compareaction.py +++ b/rainbowadn/data/collection/trees/binary/actions/compareaction.py @@ -4,7 +4,7 @@ from typing import Generic, TypeVar from rainbowadn.data.collection.trees.binary.actions.binarytreeaction import BinaryTreeAction from rainbowadn.data.collection.trees.binary.binarytreecase import BinaryTreeCase from rainbowadn.data.collection.trees.comparison.comparator import Comparison, Equal, Left, Right -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('CompareAction',) diff --git a/rainbowadn/data/collection/trees/binary/activebinarytree.py b/rainbowadn/data/collection/trees/binary/activebinarytree.py index f032017..6213c2d 100644 --- a/rainbowadn/data/collection/trees/binary/activebinarytree.py +++ b/rainbowadn/data/collection/trees/binary/activebinarytree.py @@ -8,10 +8,10 @@ from rainbowadn.data.collection.trees.binary.binarytree import BinaryTree, Binar from rainbowadn.data.collection.trees.binary.binarytreebalancingprotocol import BinaryTreeBalancingProtocol from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol from rainbowadn.data.collection.trees.binary.binarytreesplit import BinaryTreeSplit -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.null import Null -from rainbowadn.hashing.nullability.nullablereference import NullableReference -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.null import Null +from rainbowadn.core.nullability.nullablereference import NullableReference +from rainbowadn.core.rainbow_factory import RainbowFactory __all__ = ('ActiveBinaryTree',) @@ -101,14 +101,10 @@ class ActiveCreationProtocol( ] ]: assert isinstance(tree, ActiveBinaryTree) - if tree.reference.reference.null(): + if tree.reference.null(): return None else: - hash_point: HashPoint[ - BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]] - ] = tree.reference.reference.resolve() - assert isinstance(hash_point, HashPoint) - resolved: BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]] = hash_point.resolve() + resolved: BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]] = tree.reference.resolve() assert isinstance(resolved, BinaryTree) key_metadata: KeyMetadata[ActiveKeyType, MetaDataType] = resolved.key.resolve() assert isinstance(key_metadata, KeyMetadata) diff --git a/rainbowadn/data/collection/trees/binary/avl.py b/rainbowadn/data/collection/trees/binary/avl.py index 95a533a..7579891 100644 --- a/rainbowadn/data/collection/trees/binary/avl.py +++ b/rainbowadn/data/collection/trees/binary/avl.py @@ -3,7 +3,7 @@ from typing import TypeVar from rainbowadn.data.atomic.integer import Integer from rainbowadn.data.collection.trees.binary.binarytreebalancingprotocol import BinaryTreeBalancingProtocol from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('AVLBTBP',) diff --git a/rainbowadn/data/collection/trees/binary/balancedtreecreationprotocol.py b/rainbowadn/data/collection/trees/binary/balancedtreecreationprotocol.py index ba9062e..f72e2b4 100644 --- a/rainbowadn/data/collection/trees/binary/balancedtreecreationprotocol.py +++ b/rainbowadn/data/collection/trees/binary/balancedtreecreationprotocol.py @@ -3,7 +3,7 @@ from typing import Generic, TypeVar from rainbowadn.data.collection.trees.binary.binarytreebalancingprotocol import BinaryTreeBalancingProtocol from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('BalancedTreeCreationProtocol',) diff --git a/rainbowadn/data/collection/trees/binary/binarytree.py b/rainbowadn/data/collection/trees/binary/binarytree.py index 751f32a..b8b76fd 100644 --- a/rainbowadn/data/collection/trees/binary/binarytree.py +++ b/rainbowadn/data/collection/trees/binary/binarytree.py @@ -1,12 +1,12 @@ from typing import Generic, Iterable, TypeVar -from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin __all__ = ('BinaryTree', 'BinaryTreeFactory',) diff --git a/rainbowadn/data/collection/trees/binary/binarytreebalancingprotocol.py b/rainbowadn/data/collection/trees/binary/binarytreebalancingprotocol.py index 80cc48d..eb13ada 100644 --- a/rainbowadn/data/collection/trees/binary/binarytreebalancingprotocol.py +++ b/rainbowadn/data/collection/trees/binary/binarytreebalancingprotocol.py @@ -2,7 +2,7 @@ from typing import Generic, TypeVar from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol from rainbowadn.data.collection.trees.comparison.comparator import Comparator -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('BinaryTreeBalancingProtocol',) diff --git a/rainbowadn/data/collection/trees/binary/binarytreecreationprotocol.py b/rainbowadn/data/collection/trees/binary/binarytreecreationprotocol.py index f4e9d81..84f2b6f 100644 --- a/rainbowadn/data/collection/trees/binary/binarytreecreationprotocol.py +++ b/rainbowadn/data/collection/trees/binary/binarytreecreationprotocol.py @@ -2,7 +2,7 @@ from typing import Generic, Optional, TypeVar from rainbowadn.data.collection.trees.binary.binarytreesplit import BinaryTreeSplit from rainbowadn.data.collection.trees.comparison.comparator import Comparator -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('BinaryTreeCreationProtocol',) diff --git a/rainbowadn/data/collection/trees/binary/binarytreesplit.py b/rainbowadn/data/collection/trees/binary/binarytreesplit.py index f908812..4ccee6d 100644 --- a/rainbowadn/data/collection/trees/binary/binarytreesplit.py +++ b/rainbowadn/data/collection/trees/binary/binarytreesplit.py @@ -1,6 +1,6 @@ from typing import Generic, TypeVar -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('BinaryTreeSplit',) diff --git a/rainbowadn/data/collection/trees/comparison/comparator.py b/rainbowadn/data/collection/trees/comparison/comparator.py index 3f58def..536d294 100644 --- a/rainbowadn/data/collection/trees/comparison/comparator.py +++ b/rainbowadn/data/collection/trees/comparison/comparator.py @@ -1,7 +1,7 @@ import abc from typing import Generic, TypeVar -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ( 'Comparison', diff --git a/rainbowadn/data/collection/trees/comparison/hashcomparator.py b/rainbowadn/data/collection/trees/comparison/hashcomparator.py index 307393d..155e568 100644 --- a/rainbowadn/data/collection/trees/comparison/hashcomparator.py +++ b/rainbowadn/data/collection/trees/comparison/hashcomparator.py @@ -2,7 +2,7 @@ from typing import Generic, TypeVar from rainbowadn.data.collection.trees.comparison.comparator import Comparison, Left, Right from rainbowadn.data.collection.trees.comparison.protocolcomparator import ProtocolComparator -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('HashComparator',) diff --git a/rainbowadn/data/collection/trees/comparison/keyedcomparator.py b/rainbowadn/data/collection/trees/comparison/keyedcomparator.py index 4fdc739..ffe1d07 100644 --- a/rainbowadn/data/collection/trees/comparison/keyedcomparator.py +++ b/rainbowadn/data/collection/trees/comparison/keyedcomparator.py @@ -2,7 +2,7 @@ from typing import Generic, TypeVar from rainbowadn.data.collection.keyed import Keyed from rainbowadn.data.collection.trees.comparison.comparator import Comparator, Comparison -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('KeyedComparator',) diff --git a/rainbowadn/data/collection/trees/comparison/plaincomparator.py b/rainbowadn/data/collection/trees/comparison/plaincomparator.py index 4f5bd3e..c4fb381 100644 --- a/rainbowadn/data/collection/trees/comparison/plaincomparator.py +++ b/rainbowadn/data/collection/trees/comparison/plaincomparator.py @@ -1,7 +1,7 @@ from rainbowadn.data.atomic.plain import Plain from rainbowadn.data.collection.trees.comparison.comparator import Comparison, Left, Right from rainbowadn.data.collection.trees.comparison.protocolcomparator import ProtocolComparator -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint __all__ = ('PlainComparator',) diff --git a/rainbowadn/encryption/encrypted.py b/rainbowadn/encryption/encrypted.py index 7e3cb28..ba23ab3 100644 --- a/rainbowadn/encryption/encrypted.py +++ b/rainbowadn/encryption/encrypted.py @@ -3,13 +3,13 @@ from typing import Generic, Iterable, TypeVar from nacl.bindings import crypto_hash_sha256 from nacl.secret import SecretBox -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.mentionable import Mentionable -from rainbowadn.hashing.origin import Origin -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.mentionable import Mentionable +from rainbowadn.core.origin import Origin +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin __all__ = ('Encrypted', 'EncryptedFactory') diff --git a/rainbowadn/testing/dictresolver.py b/rainbowadn/testing/dictresolver.py index b9a9d97..b73a5d2 100644 --- a/rainbowadn/testing/dictresolver.py +++ b/rainbowadn/testing/dictresolver.py @@ -1,10 +1,10 @@ from collections import OrderedDict from typing import MutableMapping -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.mentionable import Mentionable -from rainbowadn.hashing.recursivementionable import RecursiveMentionable +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.mentionable import Mentionable +from rainbowadn.core.recursivementionable import RecursiveMentionable class DictResolver(HashResolver): diff --git a/rainbowadn/testing/failresolver.py b/rainbowadn/testing/failresolver.py index 6a6e957..6aed26f 100644 --- a/rainbowadn/testing/failresolver.py +++ b/rainbowadn/testing/failresolver.py @@ -1,4 +1,4 @@ -from rainbowadn.hashing.hashresolver import HashResolver +from rainbowadn.core.hashresolver import HashResolver class FailResolver(HashResolver): diff --git a/rainbowadn/testing/test_all.py b/rainbowadn/testing/test_all.py index 294f19c..05dad8a 100644 --- a/rainbowadn/testing/test_all.py +++ b/rainbowadn/testing/test_all.py @@ -17,10 +17,10 @@ from rainbowadn.data.collection.trees.binary.avl import AVLBTBP from rainbowadn.data.collection.trees.comparison.comparator import Replace from rainbowadn.data.collection.trees.comparison.plaincomparator import PlainComparator from rainbowadn.encryption.encrypted import Encrypted -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.notnull import NotNull -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.resolvermetaorigin import ResolverMetaOrigin +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.notnull import NotNull +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.resolvermetaorigin import ResolverMetaOrigin from rainbowadn.testing.dictresolver import DictResolver from rainbowadn.testing.instrumentation import Counter from rainbowadn.v13.algo import MINT_CONST @@ -69,7 +69,7 @@ class TestAll(unittest.TestCase): with self.subTest('recover'): dr.save(HashPoint.of(bank.reference)) bank = BankChain.from_reference( - ReductionChainMetaFactory(), ResolverMetaOrigin(dr).migrate(HashPoint.of(bank.reference)).resolve() + ReductionChainMetaFactory(), ResolverMetaOrigin(dr).migrate_resolved(bank.reference) ) print(bank) with self.subTest('verify'): @@ -104,7 +104,7 @@ class TestAll(unittest.TestCase): dr.save(HashPoint.of(btree)) measure('save') with self.subTest('resolve and iterate'): - btree = ResolverMetaOrigin(dr).migrate(HashPoint.of(btree)).resolve() + btree = ResolverMetaOrigin(dr).migrate_resolved(btree) assert len(btree.keys()) == n print(btree.height) measure('resolve and iterate') @@ -154,7 +154,7 @@ class TestAll(unittest.TestCase): ) for i in range(250): tree = tree.add(HashPoint.of(Plain(os.urandom(16)))) - print(tree.loose().reference.reference.resolve().resolve().key.resolve().metadata.resolve().integer) + print(tree.loose().reference.resolve().key.resolve().metadata.resolve().integer) def test_encryption(self): instrumentation = Counter(Encrypted, 'encrypt') @@ -186,7 +186,7 @@ class TestAll(unittest.TestCase): eeed = Encrypted.encrypt(target, key) print(instrumentation.counter) dr.save(HashPoint.of(eeed)) - print(ResolverMetaOrigin(dr).migrate(HashPoint.of(eeed)).resolve().decrypted.str(0)) + print(ResolverMetaOrigin(dr).migrate_resolved(eeed).decrypted.str(0)) with self.subTest('re-encrypt'): new_key = b'b' * 32 target = eeed.decrypted diff --git a/rainbowadn/toplevel/__init__.py b/rainbowadn/toplevel/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rainbowadn/toplevel/thresholdprotocol.py b/rainbowadn/toplevel/thresholdprotocol.py new file mode 100644 index 0000000..9de6a9b --- /dev/null +++ b/rainbowadn/toplevel/thresholdprotocol.py @@ -0,0 +1,10 @@ +from typing import Generic, TypeVar + +__all__ = ('ThresholdProtocol',) + +Referenced = TypeVar('Referenced') + + +class ThresholdProtocol(Generic[Referenced]): + def threshold(self, referenced: Referenced) -> bytes: + raise NotImplementedError diff --git a/rainbowadn/toplevel/validreference.py b/rainbowadn/toplevel/validreference.py new file mode 100644 index 0000000..f8089cb --- /dev/null +++ b/rainbowadn/toplevel/validreference.py @@ -0,0 +1,48 @@ +from typing import Generic, Iterable, TypeVar + +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin +from rainbowadn.toplevel.thresholdprotocol import ThresholdProtocol + +__all__ = ('ValidReference', 'ValidReferenceFactory') + + +Referenced = TypeVar('Referenced') + + +class ValidReference(RecursiveMentionable, Generic[Referenced]): + def __init__(self, reference: HashPoint[Referenced], protocol: ThresholdProtocol[Referenced]): + assert isinstance(reference, HashPoint) + assert isinstance(protocol, ThresholdProtocol) + self.reference = reference + self.protocol = protocol + + def points(self) -> Iterable[HashPoint]: + return [self.reference] + + def resolve(self) -> Referenced: + referenced: Referenced = self.reference.resolve() + assert self.reference.point < self.protocol.threshold(referenced) + return referenced + + def __bytes__(self): + return bytes(self.reference) + + def __factory__(self) -> RainbowFactory['ValidReference[Referenced]']: + return ValidReferenceFactory(self.reference.factory, self.protocol) + + +class ValidReferenceFactory(RainbowFactory[ValidReference[Referenced]], Generic[Referenced]): + def __init__(self, factory: RainbowFactory[Referenced], protocol: ThresholdProtocol[Referenced]): + assert isinstance(factory, RainbowFactory) + assert isinstance(protocol, ThresholdProtocol) + self.factory = factory + self.protocol = protocol + + def from_bytes(self, source: bytes, resolver: HashResolver) -> ValidReference[Referenced]: + assert isinstance(source, bytes) + assert isinstance(resolver, HashResolver) + return ValidReference(ResolverOrigin(self.factory, source, resolver).hash_point(), self.protocol) diff --git a/rainbowadn/v13/bankchain.py b/rainbowadn/v13/bankchain.py index e6453c3..18393c2 100644 --- a/rainbowadn/v13/bankchain.py +++ b/rainbowadn/v13/bankchain.py @@ -3,8 +3,8 @@ from typing import Generic, TypeVar from rainbowadn.chain.abstractreductionchainmetafactory import AbstractReductionChainMetaFactory from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface from rainbowadn.data.collection.stack.stack import Stack, StackFactory -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.v13.bankprotocol import BankProtocol from rainbowadn.v13.bankstate import BankState from rainbowadn.v13.transaction import Transaction diff --git a/rainbowadn/v13/bankprotocol.py b/rainbowadn/v13/bankprotocol.py index 411605f..9bf557e 100644 --- a/rainbowadn/v13/bankprotocol.py +++ b/rainbowadn/v13/bankprotocol.py @@ -6,12 +6,11 @@ from rainbowadn.data.atomic.integer import Integer from rainbowadn.data.collection.keymetadata import KeyMetadataFactory from rainbowadn.data.collection.stack.stack import Stack from rainbowadn.data.collection.trees.binary.binarytree import BinaryTreeFactory -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.nullability.null import Null -from rainbowadn.hashing.nullability.nullable import Nullable -from rainbowadn.hashing.nullability.nullablereference import NullableReference -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.static import StaticFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.nullability.null import Null +from rainbowadn.core.nullability.nullablereference import NullableReference +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.static import StaticFactory from rainbowadn.v13.bankstate import BankState from rainbowadn.v13.subject import Subject from rainbowadn.v13.transaction import Coin, Transaction @@ -27,12 +26,11 @@ class BankProtocol(ReductionProtocol[NullableReference[Stack[Transaction]], Bank assert isinstance(reduction, Reduction) bank_state: BankState = reduction.accumulator.resolve() assert isinstance(bank_state, BankState) - reference: Nullable[HashPoint[Stack[Transaction]]] = reduction.reductor.resolve().reference - assert isinstance(reference, Nullable) + reference: NullableReference[Stack[Transaction]] = reduction.reductor.resolve() if reference.null(): return Reduced(HashPoint.of(bank_state.without_miner())) else: - stack: Stack[Transaction] = reference.resolve().resolve() + stack: Stack[Transaction] = reference.resolve() assert isinstance(stack, Stack) return Reduction( HashPoint.of(stack.previous), diff --git a/rainbowadn/v13/bankstate.py b/rainbowadn/v13/bankstate.py index 880fd90..51e87a9 100644 --- a/rainbowadn/v13/bankstate.py +++ b/rainbowadn/v13/bankstate.py @@ -7,16 +7,16 @@ from rainbowadn.data.collection.trees.binary.avl import AVLBTBP from rainbowadn.data.collection.trees.binary.binarytree import BinaryTree, BinaryTreeFactory from rainbowadn.data.collection.trees.comparison.comparator import Fail from rainbowadn.data.collection.trees.comparison.hashcomparator import HashComparator -from rainbowadn.hashing.hash_point_format import tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.nullability.null import Null -from rainbowadn.hashing.nullability.nullable import Nullable -from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin -from rainbowadn.hashing.static import StaticFactory, StaticMentionable +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.nullability.null import Null +from rainbowadn.core.nullability.nullable import Nullable +from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin +from rainbowadn.core.static import StaticFactory, StaticMentionable from rainbowadn.v13.algo import MINT_CONST from rainbowadn.v13.subject import Subject from rainbowadn.v13.transaction import Coin, Transaction @@ -136,7 +136,7 @@ class BankState(RecursiveMentionable, StaticMentionable): def _push(self, transaction: Transaction) -> 'BankState': assert isinstance(transaction, Transaction) return self.use_coins( - transaction.data.resolve().iter_in_coins() + transaction.data_resolved().iter_in_coins() ).mint_coins( transaction ) @@ -155,5 +155,5 @@ class BankState(RecursiveMentionable, StaticMentionable): f'{tabulate(tab + 1)}(used)' \ f'{tabulate(tab + 1)}{self.used.str(tab + 1)}' \ f'{tabulate(tab + 1)}(length)' \ - f'{tabulate(tab + 1)}{self.length.resolve()}' \ + f'{tabulate(tab + 1)}{hash_point_format(self.length, tab + 1)}' \ f'{tabulate(tab)})' diff --git a/rainbowadn/v13/signature.py b/rainbowadn/v13/signature.py index 5a78e27..17faf9c 100644 --- a/rainbowadn/v13/signature.py +++ b/rainbowadn/v13/signature.py @@ -3,7 +3,7 @@ import nacl.exceptions import nacl.signing from rainbowadn.data.atomic.atomic import Atomic -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint from rainbowadn.v13.subject import Subject __all__ = ('BadSignature', 'Signature',) diff --git a/rainbowadn/v13/transaction.py b/rainbowadn/v13/transaction.py index 17924be..792529e 100644 --- a/rainbowadn/v13/transaction.py +++ b/rainbowadn/v13/transaction.py @@ -4,16 +4,16 @@ import nacl.signing from rainbowadn.data.atomic.integer import Integer from rainbowadn.data.collection.stack.stack import Stack, StackFactory -from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.nullability.notnull import NotNull -from rainbowadn.hashing.nullability.nullable import Nullable -from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin -from rainbowadn.hashing.static import StaticMentionable +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.nullability.notnull import NotNull +from rainbowadn.core.nullability.nullable import Nullable +from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin +from rainbowadn.core.static import StaticMentionable from rainbowadn.v13.signature import Signature from rainbowadn.v13.subject import Subject @@ -31,6 +31,9 @@ class CoinData(RecursiveMentionable, StaticMentionable): self.owner = owner self.value = value + def int_value(self) -> int: + return self.value.resolve().integer + @classmethod def of(cls, owner: Subject, value: int) -> 'CoinData': assert isinstance(owner, Subject) @@ -54,8 +57,8 @@ class CoinData(RecursiveMentionable, StaticMentionable): def str(self, tab: int) -> str: assert isinstance(tab, int) - return f'{self.owner.resolve()}' \ - f'{tabulate(tab)}{self.value.resolve()}' + return f'{hash_point_format(self.owner, tab)}' \ + f'{tabulate(tab)}{hash_point_format(self.value, tab)}' class Coin(RecursiveMentionable, StaticMentionable): @@ -72,6 +75,9 @@ class Coin(RecursiveMentionable, StaticMentionable): self.origin = origin self.index = index + def data_resolved(self) -> CoinData: + return self.data.resolve() + def points(self) -> Iterable[HashPoint]: return [self.data, self.origin, self.index] @@ -96,7 +102,7 @@ class Coin(RecursiveMentionable, StaticMentionable): f'{tabulate(tab + 1)}coin' \ f'{tabulate(tab + 1)}{hash_point_format(self.data, tab + 1)}' \ f'{tabulate(tab + 1)}(origin)' \ - f'{tabulate(tab + 1)}{self.index.resolve()}' \ + f'{tabulate(tab + 1)}{hash_point_format(self.index, tab + 1)}' \ f'{tabulate(tab)})' @@ -136,9 +142,9 @@ class TransactionData(RecursiveMentionable, StaticMentionable): self, signatures: NullableReference[Stack[Signature]] ) -> bool: - for coin, signature in zip(self.iter_in_coins(), Stack.iter(signatures), strict=True): + for coin, signature in zip(self.iter_in_coins_resolved(), Stack.iter(signatures), strict=True): assert signature.resolve().verify( - coin.resolve().data.resolve().owner.resolve(), + coin.data_resolved().owner.resolve(), self.hash_point ) return True @@ -146,14 +152,18 @@ class TransactionData(RecursiveMentionable, StaticMentionable): def iter_in_coins(self) -> Iterable[HashPoint[Coin]]: return Stack.iter(self.in_coins) + def iter_in_coins_resolved(self) -> Iterable[Coin]: + for coin in Stack.iter(self.in_coins): + yield coin.resolve() + def _total_in(self) -> int: - return sum(coin.resolve().data.resolve().value.resolve().integer for coin in self.iter_in_coins()) + return sum(coin.data_resolved().int_value() for coin in self.iter_in_coins_resolved()) def iter_out_coins(self) -> Iterable[HashPoint[CoinData]]: return Stack.iter(self.out_coins) def _total_out(self) -> int: - return sum(coin.resolve().value.resolve().integer for coin in self.iter_out_coins()) + return sum(coin.resolve().int_value() for coin in self.iter_out_coins()) def _verify_values(self, mint: int) -> bool: assert isinstance(mint, int) @@ -196,6 +206,9 @@ class Transaction(RecursiveMentionable, StaticMentionable): self.hash_point = HashPoint.of(self) assert isinstance(self.hash_point, HashPoint) + def data_resolved(self) -> TransactionData: + return self.data.resolve() + def points(self) -> Iterable[HashPoint]: return [self.data, *self.signatures.points()] @@ -220,7 +233,7 @@ class Transaction(RecursiveMentionable, StaticMentionable): mint: int, miner: Nullable[HashPoint[Subject]] ) -> Iterable[tuple[Coin, Nullable[HashPoint[Subject]]]]: - transaction_data = self.data.resolve() + transaction_data: TransactionData = self.data_resolved() assert isinstance(transaction_data, TransactionData) index = 0 out_coin: HashPoint[CoinData] @@ -258,7 +271,7 @@ class Transaction(RecursiveMentionable, StaticMentionable): def verify(self, mint: int): assert isinstance(mint, int) - data: TransactionData = self.data.resolve() + data: TransactionData = self.data_resolved() assert isinstance(data, TransactionData) assert data.verify(self.signatures, mint) return True diff --git a/rainbowadn/wrisbt/weakreferenceindexsetbtree.py b/rainbowadn/wrisbt/weakreferenceindexsetbtree.py index adaf709..ab61478 100644 --- a/rainbowadn/wrisbt/weakreferenceindexsetbtree.py +++ b/rainbowadn/wrisbt/weakreferenceindexsetbtree.py @@ -1,15 +1,15 @@ import bisect from typing import Iterable, Sequence -from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.localmetaorigin import LocalMetaOrigin -from rainbowadn.hashing.localorigin import LocalOrigin -from rainbowadn.hashing.metaorigin import MetaOrigin -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolvermetaorigin import ResolverMetaOrigin +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.localmetaorigin import LocalMetaOrigin +from rainbowadn.core.localorigin import LocalOrigin +from rainbowadn.core.metaorigin import MetaOrigin +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolvermetaorigin import ResolverMetaOrigin from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres __all__ = ('WeakReferenceIndexSetBTree', 'WrisbtFactory',) @@ -95,6 +95,12 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable): self.bytes_no(index, self.keyend, HashPoint.HASH_LENGTH) ) + def child_resolved_no(self, index: int) -> 'WeakReferenceIndexSetBTree': + assert isinstance(index, int) + assert 0 <= index < self.children + assert not self.leaf + return self.child_no(index).resolve() + def balanced(self) -> bool: return self.keys <= 2 * self.keymin @@ -181,7 +187,7 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable): assert key > self.key_no(index - 1) if self.leaf: return False - child: WeakReferenceIndexSetBTree = self.child_no(index).resolve() + child: WeakReferenceIndexSetBTree = self.child_resolved_no(index) assert isinstance(child, WeakReferenceIndexSetBTree) return child.contains(key) @@ -208,7 +214,7 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable): self.root, () ) - child: WeakReferenceIndexSetBTree = self.child_no(index).resolve() + child: WeakReferenceIndexSetBTree = self.child_resolved_no(index) assert isinstance(child, WeakReferenceIndexSetBTree) child: WeakReferenceIndexSetBTree = child.add(key) assert isinstance(child, WeakReferenceIndexSetBTree) @@ -273,7 +279,7 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable): if mode: yield self.key_no(real_index) else: - yield from self.child_no(real_index).resolve().iter_keys() + yield from self.child_resolved_no(real_index).iter_keys() class KeyView(Sequence[WeakReferenceIndexSetBTree]): diff --git a/rainbowadn/wrisbt/wrisbtchainprotocol.py b/rainbowadn/wrisbt/wrisbtchainprotocol.py index 5ad5689..a5a63b7 100644 --- a/rainbowadn/wrisbt/wrisbtchainprotocol.py +++ b/rainbowadn/wrisbt/wrisbtchainprotocol.py @@ -1,8 +1,8 @@ from typing import Generic, TypeVar from rainbowadn.chain.blockchainprotocol import BlockChainProtocol -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.rainbow_factory import RainbowFactory +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.rainbow_factory import RainbowFactory from rainbowadn.wrisbt.wrisbtindex import WrisbtIndex, WrisbtIndexFactory from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres from rainbowadn.wrisbt.wrisbtprotocol import WrisbtProtocol diff --git a/rainbowadn/wrisbt/wrisbtindex.py b/rainbowadn/wrisbt/wrisbtindex.py index c0e81ef..9890ae8 100644 --- a/rainbowadn/wrisbt/wrisbtindex.py +++ b/rainbowadn/wrisbt/wrisbtindex.py @@ -1,11 +1,11 @@ from typing import Iterable -from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres from rainbowadn.wrisbt.wrisbtroot import WrisbtRoot, WrisbtRootFactory diff --git a/rainbowadn/wrisbt/wrisbtprotocol.py b/rainbowadn/wrisbt/wrisbtprotocol.py index c999123..542a8a1 100644 --- a/rainbowadn/wrisbt/wrisbtprotocol.py +++ b/rainbowadn/wrisbt/wrisbtprotocol.py @@ -1,7 +1,7 @@ from typing import TypeVar from rainbowadn.chain.states.metareductionstateprotocol import MetaReductionStateProtocol -from rainbowadn.hashing.hashpoint import HashPoint +from rainbowadn.core.hashpoint import HashPoint from rainbowadn.wrisbt.wrisbtindex import WrisbtIndex from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres from rainbowadn.wrisbt.wrisbtroot import WrisbtRoot diff --git a/rainbowadn/wrisbt/wrisbtroot.py b/rainbowadn/wrisbt/wrisbtroot.py index df058f9..5f132cd 100644 --- a/rainbowadn/wrisbt/wrisbtroot.py +++ b/rainbowadn/wrisbt/wrisbtroot.py @@ -1,15 +1,15 @@ from typing import Iterable from rainbowadn.data.atomic.integer import Integer -from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate -from rainbowadn.hashing.hashpoint import HashPoint -from rainbowadn.hashing.hashresolver import HashResolver -from rainbowadn.hashing.localmetaorigin import LocalMetaOrigin -from rainbowadn.hashing.localorigin import LocalOrigin -from rainbowadn.hashing.mentionable import Mentionable -from rainbowadn.hashing.rainbow_factory import RainbowFactory -from rainbowadn.hashing.recursivementionable import RecursiveMentionable -from rainbowadn.hashing.resolverorigin import ResolverOrigin +from rainbowadn.core.hash_point_format import hash_point_format, tabulate +from rainbowadn.core.hashpoint import HashPoint +from rainbowadn.core.hashresolver import HashResolver +from rainbowadn.core.localmetaorigin import LocalMetaOrigin +from rainbowadn.core.localorigin import LocalOrigin +from rainbowadn.core.mentionable import Mentionable +from rainbowadn.core.rainbow_factory import RainbowFactory +from rainbowadn.core.recursivementionable import RecursiveMentionable +from rainbowadn.core.resolverorigin import ResolverOrigin from rainbowadn.wrisbt.weakreferenceindexsetbtree import WeakReferenceIndexSetBTree, WrisbtFactory from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres @@ -25,6 +25,9 @@ class WrisbtRoot(RecursiveMentionable): self.height = height self.parametres = parametres + def root_resolved(self) -> 'WeakReferenceIndexSetBTree': + return self.root.resolve() + def points(self) -> Iterable[HashPoint]: return [self.root] @@ -49,7 +52,7 @@ class WrisbtRoot(RecursiveMentionable): assert isinstance(key, bytes) assert len(key) == self.parametres.keysize - root: WeakReferenceIndexSetBTree = self.root.resolve() + root: WeakReferenceIndexSetBTree = self.root_resolved() assert isinstance(root, WeakReferenceIndexSetBTree) return root.contains(key) @@ -58,7 +61,7 @@ class WrisbtRoot(RecursiveMentionable): assert isinstance(key, bytes) assert len(key) == self.parametres.keysize - root: WeakReferenceIndexSetBTree = self.root.resolve().add(key) + root: WeakReferenceIndexSetBTree = self.root_resolved().add(key) assert isinstance(root, WeakReferenceIndexSetBTree) if root.full(): @@ -82,7 +85,7 @@ class WrisbtRoot(RecursiveMentionable): return cls(HashPoint.of(root), root.height, root.parametres) def keys(self) -> list[bytes]: - return list(self.root.resolve().iter_keys()) + return list(self.root_resolved().iter_keys()) def index( self, target: HashPoint, exclude: 'WrisbtRoot'