less of direct .resolve() calls

This commit is contained in:
AF 2022-06-18 18:35:01 +03:00
parent 426fbc1fa5
commit dcad23c818
79 changed files with 392 additions and 313 deletions

View File

@ -2,7 +2,7 @@ from typing import Generic, TypeVar
from rainbowadn.chain.chaincollectionfactory import ChainCollectionFactory from rainbowadn.chain.chaincollectionfactory import ChainCollectionFactory
from rainbowadn.chain.reduction.reductionprotocol import ReductionProtocol from rainbowadn.chain.reduction.reductionprotocol import ReductionProtocol
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('AbstractReductionChainMetaFactory',) __all__ = ('AbstractReductionChainMetaFactory',)

View File

@ -1,12 +1,12 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
__all__ = ('Block', 'BlockFactory',) __all__ = ('Block', 'BlockFactory',)

View File

@ -4,10 +4,10 @@ from rainbowadn.chain.block import Block, BlockFactory
from rainbowadn.chain.blockchainprotocol import BlockChainProtocol from rainbowadn.chain.blockchainprotocol import BlockChainProtocol
from rainbowadn.chain.chaincollectionfactory import ChainCollectionFactory from rainbowadn.chain.chaincollectionfactory import ChainCollectionFactory
from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.null import Null from rainbowadn.core.nullability.null import Null
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('BlockChain', 'BlockChainFactory',) __all__ = ('BlockChain', 'BlockChainFactory',)
@ -75,16 +75,13 @@ class BlockChain(
) -> NullableReference[ ) -> NullableReference[
StateType StateType
]: ]:
if self.reference.reference.null(): if self.reference.null():
return NullableReference( return NullableReference(
Null(), Null(),
self.protocol.state_factory self.protocol.state_factory
) )
else: else:
block: Block[ block: Block[HeaderType, StateType] = self.reference.resolve()
HeaderType,
StateType
] = self.reference.reference.resolve().resolve()
assert isinstance(block, Block) assert isinstance(block, Block)
return NullableReference.of(block.state) return NullableReference.of(block.state)
@ -115,21 +112,21 @@ class BlockChain(
HeaderType, HeaderType,
ActualStateType ActualStateType
]: ]:
assert not self.reference.reference.null() assert not self.reference.null()
block: Block[ block: Block[
HeaderType, HeaderType,
StateType StateType
] = self.reference.reference.resolve().resolve() ] = self.reference.resolve()
assert isinstance(block, Block) assert isinstance(block, Block)
return self.factory().from_reference(block.previous) return self.factory().from_reference(block.previous)
def verify(self) -> bool: def verify(self) -> bool:
if self.reference.reference.null(): if self.reference.null():
return True return True
else: else:
return self.verify_link( assert self.verify_link(self.previous().reference)
self.previous().reference assert self.previous().verify()
) and self.previous().verify() return True
def _verify_link( def _verify_link(
self, self,
@ -149,11 +146,12 @@ class BlockChain(
assert block.previous == previous assert block.previous == previous
previous_chain = self.factory().from_reference(previous) previous_chain = self.factory().from_reference(previous)
assert isinstance(previous_chain, BlockChain) assert isinstance(previous_chain, BlockChain)
return self.protocol.state_protocol.verify( assert self.protocol.state_protocol.verify(
previous_chain.state(), previous_chain.state(),
block.header, block.header,
block.state, block.state,
) )
return True
def _actual_state_factory(self) -> RainbowFactory[ActualStateType]: def _actual_state_factory(self) -> RainbowFactory[ActualStateType]:
return self.protocol.actual_state_factory() return self.protocol.actual_state_factory()

View File

@ -1,8 +1,8 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('BlockChainProtocol',) __all__ = ('BlockChainProtocol',)

View File

@ -1,10 +1,10 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.data.collection.collection_interface.collectioninterface import CollectionInterface from rainbowadn.data.collection.collection_interface.collectioninterface import CollectionInterface
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.null import Null from rainbowadn.core.nullability.null import Null
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('BlockCollectionInterface',) __all__ = ('BlockCollectionInterface',)
@ -38,11 +38,11 @@ class BlockCollectionInterface(
previous: NullableReference[BlockType] previous: NullableReference[BlockType]
) -> bool: ) -> bool:
assert isinstance(previous, NullableReference) assert isinstance(previous, NullableReference)
if self.reference.reference.null(): if self.reference.null():
return True return True
else: else:
return self._verify_link( return self._verify_link(
self.reference.reference.resolve().resolve(), self.reference.resolve(),
previous previous
) )
@ -53,10 +53,10 @@ class BlockCollectionInterface(
raise NotImplementedError raise NotImplementedError
def actual_state(self) -> NullableReference[ActualStateType]: def actual_state(self) -> NullableReference[ActualStateType]:
if self.reference.reference.null(): if self.reference.null():
return NullableReference(Null(), self._actual_state_factory()) return NullableReference(Null(), self._actual_state_factory())
else: else:
return NullableReference.of(self._actual_state(self.reference.reference.resolve().resolve())) return NullableReference.of(self._actual_state(self.reference.resolve()))
def add( def add(
self, self,

View File

@ -1,7 +1,7 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
__all__ = ('ChainCollectionFactory',) __all__ = ('ChainCollectionFactory',)

View File

@ -2,7 +2,7 @@ import abc
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.chain.blockcollectioninterface import BlockCollectionInterface from rainbowadn.chain.blockcollectioninterface import BlockCollectionInterface
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ('ChainCollectionInterface',) __all__ = ('ChainCollectionInterface',)

View File

@ -1,7 +1,7 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.chain.reduction.reductionresult import ReductionResult from rainbowadn.chain.reduction.reductionresult import ReductionResult
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ('Reduced',) __all__ = ('Reduced',)

View File

@ -1,12 +1,12 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.chain.reduction.reductionresult import ReductionResult from rainbowadn.chain.reduction.reductionresult import ReductionResult
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
__all__ = ('Reduction', 'ReductionFactory',) __all__ = ('Reduction', 'ReductionFactory',)

View File

@ -8,7 +8,7 @@ from rainbowadn.chain.reduction.reduction import Reduction
from rainbowadn.chain.reduction.reductionchainprotocol import ReductionChainProtocol from rainbowadn.chain.reduction.reductionchainprotocol import ReductionChainProtocol
from rainbowadn.chain.reduction.reductionprotocol import ReductionProtocol from rainbowadn.chain.reduction.reductionprotocol import ReductionProtocol
from rainbowadn.chain.stages.stage import StateStage from rainbowadn.chain.stages.stage import StateStage
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('ReductionChainMetaFactory',) __all__ = ('ReductionChainMetaFactory',)

View File

@ -7,8 +7,8 @@ from rainbowadn.chain.reduction.reductionstageprotocol import ReductionStageProt
from rainbowadn.chain.stages.derivation.activestageprotocol import ActiveStageProtocol from rainbowadn.chain.stages.derivation.activestageprotocol import ActiveStageProtocol
from rainbowadn.chain.stages.derivation.activestagestateprotocol import ActiveStageStateProtocol from rainbowadn.chain.stages.derivation.activestagestateprotocol import ActiveStageStateProtocol
from rainbowadn.chain.stages.stage import StateStage, StateStageFactory from rainbowadn.chain.stages.stage import StateStage, StateStageFactory
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('ReductionChainProtocol',) __all__ = ('ReductionChainProtocol',)

View File

@ -2,8 +2,8 @@ from typing import Generic, TypeVar
from rainbowadn.chain.reduction.reduction import Reduction from rainbowadn.chain.reduction.reduction import Reduction
from rainbowadn.chain.reduction.reductionresult import ReductionResult from rainbowadn.chain.reduction.reductionresult import ReductionResult
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('ReductionProtocol',) __all__ = ('ReductionProtocol',)

View File

@ -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.derived import Derived
from rainbowadn.chain.stages.derivation.derivedstage import DerivedStage from rainbowadn.chain.stages.derivation.derivedstage import DerivedStage
from rainbowadn.chain.stages.derivation.derivedstate import DerivedState from rainbowadn.chain.stages.derivation.derivedstate import DerivedState
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
__all__ = ('ReductionStageProtocol',) __all__ = ('ReductionStageProtocol',)
@ -31,10 +31,10 @@ class ReductionStageProtocol(
previous: NullableReference[AccumulatorType], previous: NullableReference[AccumulatorType],
) -> HashPoint[AccumulatorType]: ) -> HashPoint[AccumulatorType]:
assert isinstance(previous, NullableReference) assert isinstance(previous, NullableReference)
if previous.reference.null(): if previous.null():
return self.protocol.initial(previous.factory) return self.protocol.initial(previous.factory)
else: else:
return self.protocol.header_filter(previous.reference.resolve()) return self.protocol.header_filter(previous.hashpoint())
def derive_header( def derive_header(
self, self,

View File

@ -5,10 +5,10 @@ from rainbowadn.chain.stages.derivation.derivedstage import DerivedStage
from rainbowadn.chain.stages.derivation.derivedstate import DerivedState from rainbowadn.chain.stages.derivation.derivedstate import DerivedState
from rainbowadn.chain.stages.stage import StageStage, StageStageFactory, StateStage from rainbowadn.chain.stages.stage import StageStage, StageStageFactory, StateStage
from rainbowadn.chain.stages.stageprotocol import StageProtocol from rainbowadn.chain.stages.stageprotocol import StageProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.null import Null from rainbowadn.core.nullability.null import Null
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('ActiveStageProtocol',) __all__ = ('ActiveStageProtocol',)
@ -42,12 +42,10 @@ class ActiveStageProtocol(
) -> NullableReference[BaseStateType]: ) -> NullableReference[BaseStateType]:
assert isinstance(previous_reference, NullableReference) assert isinstance(previous_reference, NullableReference)
assert isinstance(base_state_factory, RainbowFactory) assert isinstance(base_state_factory, RainbowFactory)
if previous_reference.reference.null(): if previous_reference.null():
return NullableReference(Null(), base_state_factory) return NullableReference(Null(), base_state_factory)
else: else:
previous_state_stage: StateStage[HeaderType, BaseStateType, StageType] = ( previous_state_stage: StateStage[HeaderType, BaseStateType, StageType] = previous_reference.resolve()
previous_reference.reference.resolve().resolve()
)
assert isinstance(previous_state_stage, StateStage) assert isinstance(previous_state_stage, StateStage)
return NullableReference.of(previous_state_stage.state) return NullableReference.of(previous_state_stage.state)

View File

@ -3,9 +3,9 @@ from typing import TypeVar
from rainbowadn.chain.stages.derivation.activestageprotocol import ActiveStageProtocol from rainbowadn.chain.stages.derivation.activestageprotocol import ActiveStageProtocol
from rainbowadn.chain.stages.stage import StateStage from rainbowadn.chain.stages.stage import StateStage
from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('ActiveStageStateProtocol',) __all__ = ('ActiveStageStateProtocol',)

View File

@ -1,7 +1,7 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.chain.stages.derivation.derived import Derived from rainbowadn.chain.stages.derivation.derived import Derived
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ('DerivedStage',) __all__ = ('DerivedStage',)

View File

@ -1,7 +1,7 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.chain.stages.derivation.derived import Derived from rainbowadn.chain.stages.derivation.derived import Derived
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ('DerivedState',) __all__ = ('DerivedState',)

View File

@ -1,14 +1,14 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.chain.stages.stageprotocol import StageProtocol from rainbowadn.chain.stages.stageprotocol import StageProtocol
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.nullability.null import Null from rainbowadn.core.nullability.null import Null
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
__all__ = ( __all__ = (
'StageStage', 'StageStage',
@ -54,10 +54,10 @@ class StageStage(
) -> NullableReference[BaseStateType]: ) -> NullableReference[BaseStateType]:
assert isinstance(previous, NullableReference) assert isinstance(previous, NullableReference)
assert isinstance(base_factory, RainbowFactory) assert isinstance(base_factory, RainbowFactory)
if previous.reference.null(): if previous.null():
return NullableReference(Null(), base_factory) return NullableReference(Null(), base_factory)
else: else:
state_stage: StateStage[HeaderType, BaseStateType, StageType] = previous.reference.resolve().resolve() state_stage: StateStage[HeaderType, BaseStateType, StageType] = previous.resolve()
assert isinstance(state_stage, StateStage) assert isinstance(state_stage, StateStage)
return NullableReference.of(state_stage.state) return NullableReference.of(state_stage.state)
@ -70,16 +70,14 @@ class StageStage(
assert isinstance(previous, NullableReference) assert isinstance(previous, NullableReference)
assert isinstance(header, HashPoint) assert isinstance(header, HashPoint)
assert isinstance(base_factory, RainbowFactory) assert isinstance(base_factory, RainbowFactory)
if self.previous.reference.null(): if self.previous.null():
return self.protocol.verify_header( return self.protocol.verify_header(
self._previous_state(previous, base_factory), self._previous_state(previous, base_factory),
header, header,
self.stage self.stage
) )
else: else:
previous_stage: StageStage[HeaderType, BaseStateType, StageType] = ( previous_stage: StageStage[HeaderType, BaseStateType, StageType] = self.previous.resolve()
self.previous.reference.resolve().resolve()
)
assert isinstance(previous_stage, StageStage) assert isinstance(previous_stage, StageStage)
return self.protocol.verify_stage( return self.protocol.verify_stage(
previous_stage.stage, previous_stage.stage,

View File

@ -1,7 +1,7 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
__all__ = ('StageProtocol',) __all__ = ('StageProtocol',)

View File

@ -2,8 +2,8 @@ from typing import Generic, TypeVar
from rainbowadn.chain.stages.stage import StateStage from rainbowadn.chain.stages.stage import StateStage
from rainbowadn.chain.states.stateprotocol import StateProtocol from rainbowadn.chain.states.stateprotocol import StateProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
__all__ = ('StageStateProtocol',) __all__ = ('StageStateProtocol',)

View File

@ -1,8 +1,8 @@
from typing import TypeVar from typing import TypeVar
from rainbowadn.chain.states.stateprotocol import StateProtocol from rainbowadn.chain.states.stateprotocol import StateProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
__all__ = ('ActiveStateProtocol',) __all__ = ('ActiveStateProtocol',)

View File

@ -1,8 +1,8 @@
from typing import TypeVar from typing import TypeVar
from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
__all__ = ('MetaReductionStateProtocol',) __all__ = ('MetaReductionStateProtocol',)
@ -40,9 +40,9 @@ class MetaReductionStateProtocol(ActiveStateProtocol[HeaderType, StateType]):
) -> HashPoint[StateType]: ) -> HashPoint[StateType]:
assert isinstance(previous, NullableReference) assert isinstance(previous, NullableReference)
assert isinstance(header, HashPoint) assert isinstance(header, HashPoint)
if previous.reference.null(): if previous.null():
previous_state: HashPoint[StateType] = self._initial_state() previous_state: HashPoint[StateType] = self._initial_state()
else: else:
previous_state: HashPoint[StateType] = previous.reference.resolve() previous_state: HashPoint[StateType] = previous.hashpoint()
assert isinstance(previous_state, HashPoint) assert isinstance(previous_state, HashPoint)
return self._derive(previous_state, header) return self._derive(previous_state, header)

View File

@ -1,7 +1,7 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
__all__ = ('StateProtocol',) __all__ = ('StateProtocol',)

View File

@ -1,5 +1,5 @@
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
__all__ = ('hash_point_format', 'tabulate',) __all__ = ('hash_point_format', 'tabulate',)

View File

@ -1,10 +1,10 @@
import hashlib import hashlib
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.localorigin import LocalOrigin from rainbowadn.core.localorigin import LocalOrigin
from rainbowadn.hashing.mentionable import Mentionable from rainbowadn.core.mentionable import Mentionable
from rainbowadn.hashing.origin import Origin from rainbowadn.core.origin import Origin
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('HashPoint',) __all__ = ('HashPoint',)

View File

@ -1,9 +1,9 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.metaorigin import MetaOrigin from rainbowadn.core.metaorigin import MetaOrigin
from rainbowadn.hashing.origin import Origin from rainbowadn.core.origin import Origin
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('LocalMetaOrigin',) __all__ = ('LocalMetaOrigin',)

View File

@ -1,7 +1,7 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.mentionable import Mentionable from rainbowadn.core.mentionable import Mentionable
from rainbowadn.hashing.origin import Origin from rainbowadn.core.origin import Origin
__all__ = ('LocalOrigin',) __all__ = ('LocalOrigin',)

View File

@ -1,6 +1,6 @@
from typing import TypeVar from typing import TypeVar
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('Mentionable',) __all__ = ('Mentionable',)

View File

@ -1,8 +1,8 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.origin import Origin from rainbowadn.core.origin import Origin
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('MetaOrigin',) __all__ = ('MetaOrigin',)

View File

@ -1,6 +1,6 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.nullability.nullable import Nullable from rainbowadn.core.nullability.nullable import Nullable
__all__ = ('NotNull',) __all__ = ('NotNull',)

View File

@ -1,6 +1,6 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.nullability.nullable import Nullable from rainbowadn.core.nullability.nullable import Nullable
__all__ = ('Null',) __all__ = ('Null',)

View File

@ -1,38 +1,38 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.hashing.hash_point_format import hash_point_format from rainbowadn.core.hash_point_format import hash_point_format
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.core.nullability.notnull import NotNull
from rainbowadn.hashing.nullability.null import Null from rainbowadn.core.nullability.null import Null
from rainbowadn.hashing.nullability.nullable import Nullable from rainbowadn.core.nullability.nullable import Nullable
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
__all__ = ('NullableReference', 'NullableReferenceFactory',) __all__ = ('NullableReference', 'NullableReferenceFactory',)
ReferencedType = TypeVar('ReferencedType') Referenced = TypeVar('Referenced')
class NullableReference(RecursiveMentionable, Generic[ReferencedType]): class NullableReference(RecursiveMentionable, Generic[Referenced]):
def __factory__(self) -> RainbowFactory['NullableReference[ReferencedType]']: def __factory__(self) -> RainbowFactory['NullableReference[Referenced]']:
return NullableReferenceFactory(self.factory) return NullableReferenceFactory(self.factory)
def points(self) -> Iterable[HashPoint]: def points(self) -> Iterable[HashPoint]:
if self.reference.null(): if self.null():
return [] return []
else: else:
return [self.reference.resolve()] return [self.hashpoint()]
def __bytes__(self): def __bytes__(self):
if self.reference.null(): if self.null():
return HashPoint.NULL_HASH return HashPoint.NULL_HASH
else: else:
return self.reference.resolve().point return self.hashpoint().point
def __init__( def __init__(
self, reference: Nullable[HashPoint[ReferencedType]], factory: RainbowFactory[ReferencedType] self, reference: Nullable[HashPoint[Referenced]], factory: RainbowFactory[Referenced]
): ):
assert isinstance(reference, Nullable) assert isinstance(reference, Nullable)
assert isinstance(factory, RainbowFactory) assert isinstance(factory, RainbowFactory)
@ -40,19 +40,19 @@ class NullableReference(RecursiveMentionable, Generic[ReferencedType]):
self.factory = factory self.factory = factory
@classmethod @classmethod
def of(cls, hash_point: HashPoint[ReferencedType]) -> 'NullableReference[ReferencedType]': def of(cls, hash_point: HashPoint[Referenced]) -> 'NullableReference[Referenced]':
assert isinstance(hash_point, HashPoint) assert isinstance(hash_point, HashPoint)
return cls(NotNull(hash_point), hash_point.factory) return cls(NotNull(hash_point), hash_point.factory)
@classmethod @classmethod
def off(cls, value: ReferencedType) -> 'NullableReference[ReferencedType]': def off(cls, value: Referenced) -> 'NullableReference[Referenced]':
return cls.of(HashPoint.of(value)) return cls.of(HashPoint.of(value))
def str(self, tab: int) -> str: def str(self, tab: int) -> str:
if self.reference.null(): if self.null():
return f'-' return f'-'
else: else:
return f'{hash_point_format(self.reference.resolve(), tab)}' return f'{hash_point_format(self.hashpoint(), tab)}'
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, NullableReference): if isinstance(other, NullableReference):
@ -60,16 +60,24 @@ class NullableReference(RecursiveMentionable, Generic[ReferencedType]):
else: else:
return NotImplemented 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]): class NullableReferenceFactory(RainbowFactory[NullableReference[Referenced]], Generic[Referenced]):
def __init__(self, factory: RainbowFactory[FReferencedType]): def __init__(self, factory: RainbowFactory[Referenced]):
assert isinstance(factory, RainbowFactory) assert isinstance(factory, RainbowFactory)
self.factory = factory 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(source, bytes)
assert isinstance(resolver, HashResolver) assert isinstance(resolver, HashResolver)
if source == HashPoint.NULL_HASH: if source == HashPoint.NULL_HASH:
@ -79,5 +87,5 @@ class NullableReferenceFactory(RainbowFactory[NullableReference[FReferencedType]
ResolverOrigin(self.factory, source, resolver).hash_point() ResolverOrigin(self.factory, source, resolver).hash_point()
) )
def loose(self) -> RainbowFactory[NullableReference[FReferencedType]]: def loose(self) -> RainbowFactory[NullableReference[Referenced]]:
return self return self

View File

@ -1,6 +1,6 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('Origin',) __all__ = ('Origin',)

View File

@ -1,6 +1,6 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
__all__ = ('RainbowFactory',) __all__ = ('RainbowFactory',)

View File

@ -1,8 +1,8 @@
import abc import abc
from typing import Iterable from typing import Iterable
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.mentionable import Mentionable from rainbowadn.core.mentionable import Mentionable
__all__ = ('RecursiveMentionable',) __all__ = ('RecursiveMentionable',)

View File

@ -1,11 +1,11 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.metaorigin import MetaOrigin from rainbowadn.core.metaorigin import MetaOrigin
from rainbowadn.hashing.origin import Origin from rainbowadn.core.origin import Origin
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
__all__ = ('ResolverMetaOrigin',) __all__ = ('ResolverMetaOrigin',)
@ -26,3 +26,6 @@ class ResolverMetaOrigin(MetaOrigin[Mentioned], Generic[Mentioned]):
def migrate(self, hash_point: HashPoint[Mentioned]) -> HashPoint[Mentioned]: def migrate(self, hash_point: HashPoint[Mentioned]) -> HashPoint[Mentioned]:
assert isinstance(hash_point, HashPoint) assert isinstance(hash_point, HashPoint)
return self.hash_point(hash_point.factory, hash_point.point) return self.hash_point(hash_point.factory, hash_point.point)
def migrate_resolved(self, mentioned: Mentioned) -> Mentioned:
return self.migrate(HashPoint.of(mentioned)).resolve()

View File

@ -1,10 +1,10 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.mentionable import Mentionable from rainbowadn.core.mentionable import Mentionable
from rainbowadn.hashing.origin import Origin from rainbowadn.core.origin import Origin
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('ResolverOrigin',) __all__ = ('ResolverOrigin',)

View File

@ -1,9 +1,9 @@
import abc import abc
from typing import Generic, Type, TypeVar from typing import Generic, Type, TypeVar
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.mentionable import Mentionable from rainbowadn.core.mentionable import Mentionable
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('StaticMentionable', 'StaticFactory',) __all__ = ('StaticMentionable', 'StaticFactory',)

View File

@ -1,9 +1,9 @@
import abc import abc
from typing import Type, TypeVar from typing import Type, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.static import StaticMentionable from rainbowadn.core.static import StaticMentionable
__all__ = ('Atomic',) __all__ = ('Atomic',)

View File

@ -1,11 +1,11 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
__all__ = ('Array', 'ArrayFactory',) __all__ = ('Array', 'ArrayFactory',)

View File

@ -1,6 +1,6 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
__all__ = ('CollectionInterface',) __all__ = ('CollectionInterface',)

View File

@ -1,8 +1,8 @@
import abc import abc
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
__all__ = ('Keyed',) __all__ = ('Keyed',)

View File

@ -1,11 +1,11 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.data.collection.keyed import Keyed from rainbowadn.data.collection.keyed import Keyed
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
__all__ = ('KeyMetadata', 'KeyMetadataFactory',) __all__ = ('KeyMetadata', 'KeyMetadataFactory',)

View File

@ -1,10 +1,10 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.data.collection.keyed import Keyed from rainbowadn.data.collection.keyed import Keyed
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
__all__ = ('KeyValue', 'KeyValueFactory',) __all__ = ('KeyValue', 'KeyValueFactory',)

View File

@ -1,11 +1,11 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
__all__ = ('Pair', 'PairFactory',) __all__ = ('Pair', 'PairFactory',)

View File

@ -1,13 +1,13 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.nullability.null import Null from rainbowadn.core.nullability.null import Null
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
__all__ = ('Stack', 'StackFactory',) __all__ = ('Stack', 'StackFactory',)
@ -74,10 +74,10 @@ class Stack(RecursiveMentionable, Generic[ElementType]):
reference: NullableReference['Stack[ElementType]'] reference: NullableReference['Stack[ElementType]']
) -> Iterable[HashPoint[ElementType]]: ) -> Iterable[HashPoint[ElementType]]:
assert isinstance(reference, NullableReference) assert isinstance(reference, NullableReference)
if reference.reference.null(): if reference.null():
pass pass
else: else:
stack: Stack[ElementType] = reference.reference.resolve().resolve() stack: Stack[ElementType] = reference.resolve()
yield stack.element yield stack.element
yield from cls.iter(stack.previous) yield from cls.iter(stack.previous)

View File

@ -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.actions.binarytreeaction import BinaryTreeAction
from rainbowadn.data.collection.trees.binary.binarytreecase import BinaryTreeCase from rainbowadn.data.collection.trees.binary.binarytreecase import BinaryTreeCase
from rainbowadn.data.collection.trees.comparison.comparator import Comparison, Equal, Left, Right 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',) __all__ = ('CompareAction',)

View File

@ -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.binarytreebalancingprotocol import BinaryTreeBalancingProtocol
from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol
from rainbowadn.data.collection.trees.binary.binarytreesplit import BinaryTreeSplit from rainbowadn.data.collection.trees.binary.binarytreesplit import BinaryTreeSplit
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.null import Null from rainbowadn.core.nullability.null import Null
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.nullability.nullablereference import NullableReference
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
__all__ = ('ActiveBinaryTree',) __all__ = ('ActiveBinaryTree',)
@ -101,14 +101,10 @@ class ActiveCreationProtocol(
] ]
]: ]:
assert isinstance(tree, ActiveBinaryTree) assert isinstance(tree, ActiveBinaryTree)
if tree.reference.reference.null(): if tree.reference.null():
return None return None
else: else:
hash_point: HashPoint[ resolved: BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]] = tree.reference.resolve()
BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]]
] = tree.reference.reference.resolve()
assert isinstance(hash_point, HashPoint)
resolved: BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]] = hash_point.resolve()
assert isinstance(resolved, BinaryTree) assert isinstance(resolved, BinaryTree)
key_metadata: KeyMetadata[ActiveKeyType, MetaDataType] = resolved.key.resolve() key_metadata: KeyMetadata[ActiveKeyType, MetaDataType] = resolved.key.resolve()
assert isinstance(key_metadata, KeyMetadata) assert isinstance(key_metadata, KeyMetadata)

View File

@ -3,7 +3,7 @@ from typing import TypeVar
from rainbowadn.data.atomic.integer import Integer from rainbowadn.data.atomic.integer import Integer
from rainbowadn.data.collection.trees.binary.binarytreebalancingprotocol import BinaryTreeBalancingProtocol from rainbowadn.data.collection.trees.binary.binarytreebalancingprotocol import BinaryTreeBalancingProtocol
from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ('AVLBTBP',) __all__ = ('AVLBTBP',)

View File

@ -3,7 +3,7 @@ from typing import Generic, TypeVar
from rainbowadn.data.collection.trees.binary.binarytreebalancingprotocol import BinaryTreeBalancingProtocol from rainbowadn.data.collection.trees.binary.binarytreebalancingprotocol import BinaryTreeBalancingProtocol
from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ('BalancedTreeCreationProtocol',) __all__ = ('BalancedTreeCreationProtocol',)

View File

@ -1,12 +1,12 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
__all__ = ('BinaryTree', 'BinaryTreeFactory',) __all__ = ('BinaryTree', 'BinaryTreeFactory',)

View File

@ -2,7 +2,7 @@ from typing import Generic, TypeVar
from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol
from rainbowadn.data.collection.trees.comparison.comparator import Comparator from rainbowadn.data.collection.trees.comparison.comparator import Comparator
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ('BinaryTreeBalancingProtocol',) __all__ = ('BinaryTreeBalancingProtocol',)

View File

@ -2,7 +2,7 @@ from typing import Generic, Optional, TypeVar
from rainbowadn.data.collection.trees.binary.binarytreesplit import BinaryTreeSplit from rainbowadn.data.collection.trees.binary.binarytreesplit import BinaryTreeSplit
from rainbowadn.data.collection.trees.comparison.comparator import Comparator from rainbowadn.data.collection.trees.comparison.comparator import Comparator
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ('BinaryTreeCreationProtocol',) __all__ = ('BinaryTreeCreationProtocol',)

View File

@ -1,6 +1,6 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ('BinaryTreeSplit',) __all__ = ('BinaryTreeSplit',)

View File

@ -1,7 +1,7 @@
import abc import abc
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ( __all__ = (
'Comparison', 'Comparison',

View File

@ -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.comparator import Comparison, Left, Right
from rainbowadn.data.collection.trees.comparison.protocolcomparator import ProtocolComparator from rainbowadn.data.collection.trees.comparison.protocolcomparator import ProtocolComparator
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ('HashComparator',) __all__ = ('HashComparator',)

View File

@ -2,7 +2,7 @@ from typing import Generic, TypeVar
from rainbowadn.data.collection.keyed import Keyed from rainbowadn.data.collection.keyed import Keyed
from rainbowadn.data.collection.trees.comparison.comparator import Comparator, Comparison from rainbowadn.data.collection.trees.comparison.comparator import Comparator, Comparison
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ('KeyedComparator',) __all__ = ('KeyedComparator',)

View File

@ -1,7 +1,7 @@
from rainbowadn.data.atomic.plain import Plain from rainbowadn.data.atomic.plain import Plain
from rainbowadn.data.collection.trees.comparison.comparator import Comparison, Left, Right from rainbowadn.data.collection.trees.comparison.comparator import Comparison, Left, Right
from rainbowadn.data.collection.trees.comparison.protocolcomparator import ProtocolComparator from rainbowadn.data.collection.trees.comparison.protocolcomparator import ProtocolComparator
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
__all__ = ('PlainComparator',) __all__ = ('PlainComparator',)

View File

@ -3,13 +3,13 @@ from typing import Generic, Iterable, TypeVar
from nacl.bindings import crypto_hash_sha256 from nacl.bindings import crypto_hash_sha256
from nacl.secret import SecretBox from nacl.secret import SecretBox
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.mentionable import Mentionable from rainbowadn.core.mentionable import Mentionable
from rainbowadn.hashing.origin import Origin from rainbowadn.core.origin import Origin
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
__all__ = ('Encrypted', 'EncryptedFactory') __all__ = ('Encrypted', 'EncryptedFactory')

View File

@ -1,10 +1,10 @@
from collections import OrderedDict from collections import OrderedDict
from typing import MutableMapping from typing import MutableMapping
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.mentionable import Mentionable from rainbowadn.core.mentionable import Mentionable
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
class DictResolver(HashResolver): class DictResolver(HashResolver):

View File

@ -1,4 +1,4 @@
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
class FailResolver(HashResolver): class FailResolver(HashResolver):

View File

@ -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.comparator import Replace
from rainbowadn.data.collection.trees.comparison.plaincomparator import PlainComparator from rainbowadn.data.collection.trees.comparison.plaincomparator import PlainComparator
from rainbowadn.encryption.encrypted import Encrypted from rainbowadn.encryption.encrypted import Encrypted
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.core.nullability.notnull import NotNull
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.resolvermetaorigin import ResolverMetaOrigin from rainbowadn.core.resolvermetaorigin import ResolverMetaOrigin
from rainbowadn.testing.dictresolver import DictResolver from rainbowadn.testing.dictresolver import DictResolver
from rainbowadn.testing.instrumentation import Counter from rainbowadn.testing.instrumentation import Counter
from rainbowadn.v13.algo import MINT_CONST from rainbowadn.v13.algo import MINT_CONST
@ -69,7 +69,7 @@ class TestAll(unittest.TestCase):
with self.subTest('recover'): with self.subTest('recover'):
dr.save(HashPoint.of(bank.reference)) dr.save(HashPoint.of(bank.reference))
bank = BankChain.from_reference( bank = BankChain.from_reference(
ReductionChainMetaFactory(), ResolverMetaOrigin(dr).migrate(HashPoint.of(bank.reference)).resolve() ReductionChainMetaFactory(), ResolverMetaOrigin(dr).migrate_resolved(bank.reference)
) )
print(bank) print(bank)
with self.subTest('verify'): with self.subTest('verify'):
@ -104,7 +104,7 @@ class TestAll(unittest.TestCase):
dr.save(HashPoint.of(btree)) dr.save(HashPoint.of(btree))
measure('save') measure('save')
with self.subTest('resolve and iterate'): 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 assert len(btree.keys()) == n
print(btree.height) print(btree.height)
measure('resolve and iterate') measure('resolve and iterate')
@ -154,7 +154,7 @@ class TestAll(unittest.TestCase):
) )
for i in range(250): for i in range(250):
tree = tree.add(HashPoint.of(Plain(os.urandom(16)))) 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): def test_encryption(self):
instrumentation = Counter(Encrypted, 'encrypt') instrumentation = Counter(Encrypted, 'encrypt')
@ -186,7 +186,7 @@ class TestAll(unittest.TestCase):
eeed = Encrypted.encrypt(target, key) eeed = Encrypted.encrypt(target, key)
print(instrumentation.counter) print(instrumentation.counter)
dr.save(HashPoint.of(eeed)) 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'): with self.subTest('re-encrypt'):
new_key = b'b' * 32 new_key = b'b' * 32
target = eeed.decrypted target = eeed.decrypted

View File

View File

@ -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

View File

@ -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)

View File

@ -3,8 +3,8 @@ from typing import Generic, TypeVar
from rainbowadn.chain.abstractreductionchainmetafactory import AbstractReductionChainMetaFactory from rainbowadn.chain.abstractreductionchainmetafactory import AbstractReductionChainMetaFactory
from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface
from rainbowadn.data.collection.stack.stack import Stack, StackFactory from rainbowadn.data.collection.stack.stack import Stack, StackFactory
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.v13.bankprotocol import BankProtocol from rainbowadn.v13.bankprotocol import BankProtocol
from rainbowadn.v13.bankstate import BankState from rainbowadn.v13.bankstate import BankState
from rainbowadn.v13.transaction import Transaction from rainbowadn.v13.transaction import Transaction

View File

@ -6,12 +6,11 @@ from rainbowadn.data.atomic.integer import Integer
from rainbowadn.data.collection.keymetadata import KeyMetadataFactory from rainbowadn.data.collection.keymetadata import KeyMetadataFactory
from rainbowadn.data.collection.stack.stack import Stack from rainbowadn.data.collection.stack.stack import Stack
from rainbowadn.data.collection.trees.binary.binarytree import BinaryTreeFactory from rainbowadn.data.collection.trees.binary.binarytree import BinaryTreeFactory
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.nullability.null import Null from rainbowadn.core.nullability.null import Null
from rainbowadn.hashing.nullability.nullable import Nullable from rainbowadn.core.nullability.nullablereference import NullableReference
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.static import StaticFactory
from rainbowadn.hashing.static import StaticFactory
from rainbowadn.v13.bankstate import BankState from rainbowadn.v13.bankstate import BankState
from rainbowadn.v13.subject import Subject from rainbowadn.v13.subject import Subject
from rainbowadn.v13.transaction import Coin, Transaction from rainbowadn.v13.transaction import Coin, Transaction
@ -27,12 +26,11 @@ class BankProtocol(ReductionProtocol[NullableReference[Stack[Transaction]], Bank
assert isinstance(reduction, Reduction) assert isinstance(reduction, Reduction)
bank_state: BankState = reduction.accumulator.resolve() bank_state: BankState = reduction.accumulator.resolve()
assert isinstance(bank_state, BankState) assert isinstance(bank_state, BankState)
reference: Nullable[HashPoint[Stack[Transaction]]] = reduction.reductor.resolve().reference reference: NullableReference[Stack[Transaction]] = reduction.reductor.resolve()
assert isinstance(reference, Nullable)
if reference.null(): if reference.null():
return Reduced(HashPoint.of(bank_state.without_miner())) return Reduced(HashPoint.of(bank_state.without_miner()))
else: else:
stack: Stack[Transaction] = reference.resolve().resolve() stack: Stack[Transaction] = reference.resolve()
assert isinstance(stack, Stack) assert isinstance(stack, Stack)
return Reduction( return Reduction(
HashPoint.of(stack.previous), HashPoint.of(stack.previous),

View File

@ -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.binary.binarytree import BinaryTree, BinaryTreeFactory
from rainbowadn.data.collection.trees.comparison.comparator import Fail from rainbowadn.data.collection.trees.comparison.comparator import Fail
from rainbowadn.data.collection.trees.comparison.hashcomparator import HashComparator from rainbowadn.data.collection.trees.comparison.hashcomparator import HashComparator
from rainbowadn.hashing.hash_point_format import tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.nullability.null import Null from rainbowadn.core.nullability.null import Null
from rainbowadn.hashing.nullability.nullable import Nullable from rainbowadn.core.nullability.nullable import Nullable
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
from rainbowadn.hashing.static import StaticFactory, StaticMentionable from rainbowadn.core.static import StaticFactory, StaticMentionable
from rainbowadn.v13.algo import MINT_CONST from rainbowadn.v13.algo import MINT_CONST
from rainbowadn.v13.subject import Subject from rainbowadn.v13.subject import Subject
from rainbowadn.v13.transaction import Coin, Transaction from rainbowadn.v13.transaction import Coin, Transaction
@ -136,7 +136,7 @@ class BankState(RecursiveMentionable, StaticMentionable):
def _push(self, transaction: Transaction) -> 'BankState': def _push(self, transaction: Transaction) -> 'BankState':
assert isinstance(transaction, Transaction) assert isinstance(transaction, Transaction)
return self.use_coins( return self.use_coins(
transaction.data.resolve().iter_in_coins() transaction.data_resolved().iter_in_coins()
).mint_coins( ).mint_coins(
transaction transaction
) )
@ -155,5 +155,5 @@ class BankState(RecursiveMentionable, StaticMentionable):
f'{tabulate(tab + 1)}(used)' \ f'{tabulate(tab + 1)}(used)' \
f'{tabulate(tab + 1)}{self.used.str(tab + 1)}' \ f'{tabulate(tab + 1)}{self.used.str(tab + 1)}' \
f'{tabulate(tab + 1)}(length)' \ 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)})' f'{tabulate(tab)})'

View File

@ -3,7 +3,7 @@ import nacl.exceptions
import nacl.signing import nacl.signing
from rainbowadn.data.atomic.atomic import Atomic 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 from rainbowadn.v13.subject import Subject
__all__ = ('BadSignature', 'Signature',) __all__ = ('BadSignature', 'Signature',)

View File

@ -4,16 +4,16 @@ import nacl.signing
from rainbowadn.data.atomic.integer import Integer from rainbowadn.data.atomic.integer import Integer
from rainbowadn.data.collection.stack.stack import Stack, StackFactory from rainbowadn.data.collection.stack.stack import Stack, StackFactory
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.core.nullability.notnull import NotNull
from rainbowadn.hashing.nullability.nullable import Nullable from rainbowadn.core.nullability.nullable import Nullable
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.core.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
from rainbowadn.hashing.static import StaticMentionable from rainbowadn.core.static import StaticMentionable
from rainbowadn.v13.signature import Signature from rainbowadn.v13.signature import Signature
from rainbowadn.v13.subject import Subject from rainbowadn.v13.subject import Subject
@ -31,6 +31,9 @@ class CoinData(RecursiveMentionable, StaticMentionable):
self.owner = owner self.owner = owner
self.value = value self.value = value
def int_value(self) -> int:
return self.value.resolve().integer
@classmethod @classmethod
def of(cls, owner: Subject, value: int) -> 'CoinData': def of(cls, owner: Subject, value: int) -> 'CoinData':
assert isinstance(owner, Subject) assert isinstance(owner, Subject)
@ -54,8 +57,8 @@ class CoinData(RecursiveMentionable, StaticMentionable):
def str(self, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(tab, int) assert isinstance(tab, int)
return f'{self.owner.resolve()}' \ return f'{hash_point_format(self.owner, tab)}' \
f'{tabulate(tab)}{self.value.resolve()}' f'{tabulate(tab)}{hash_point_format(self.value, tab)}'
class Coin(RecursiveMentionable, StaticMentionable): class Coin(RecursiveMentionable, StaticMentionable):
@ -72,6 +75,9 @@ class Coin(RecursiveMentionable, StaticMentionable):
self.origin = origin self.origin = origin
self.index = index self.index = index
def data_resolved(self) -> CoinData:
return self.data.resolve()
def points(self) -> Iterable[HashPoint]: def points(self) -> Iterable[HashPoint]:
return [self.data, self.origin, self.index] return [self.data, self.origin, self.index]
@ -96,7 +102,7 @@ class Coin(RecursiveMentionable, StaticMentionable):
f'{tabulate(tab + 1)}coin' \ f'{tabulate(tab + 1)}coin' \
f'{tabulate(tab + 1)}{hash_point_format(self.data, tab + 1)}' \ f'{tabulate(tab + 1)}{hash_point_format(self.data, tab + 1)}' \
f'{tabulate(tab + 1)}(origin)' \ 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)})' f'{tabulate(tab)})'
@ -136,9 +142,9 @@ class TransactionData(RecursiveMentionable, StaticMentionable):
self, self,
signatures: NullableReference[Stack[Signature]] signatures: NullableReference[Stack[Signature]]
) -> bool: ) -> 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( assert signature.resolve().verify(
coin.resolve().data.resolve().owner.resolve(), coin.data_resolved().owner.resolve(),
self.hash_point self.hash_point
) )
return True return True
@ -146,14 +152,18 @@ class TransactionData(RecursiveMentionable, StaticMentionable):
def iter_in_coins(self) -> Iterable[HashPoint[Coin]]: def iter_in_coins(self) -> Iterable[HashPoint[Coin]]:
return Stack.iter(self.in_coins) 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: 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]]: def iter_out_coins(self) -> Iterable[HashPoint[CoinData]]:
return Stack.iter(self.out_coins) return Stack.iter(self.out_coins)
def _total_out(self) -> int: 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: def _verify_values(self, mint: int) -> bool:
assert isinstance(mint, int) assert isinstance(mint, int)
@ -196,6 +206,9 @@ class Transaction(RecursiveMentionable, StaticMentionable):
self.hash_point = HashPoint.of(self) self.hash_point = HashPoint.of(self)
assert isinstance(self.hash_point, HashPoint) assert isinstance(self.hash_point, HashPoint)
def data_resolved(self) -> TransactionData:
return self.data.resolve()
def points(self) -> Iterable[HashPoint]: def points(self) -> Iterable[HashPoint]:
return [self.data, *self.signatures.points()] return [self.data, *self.signatures.points()]
@ -220,7 +233,7 @@ class Transaction(RecursiveMentionable, StaticMentionable):
mint: int, mint: int,
miner: Nullable[HashPoint[Subject]] miner: Nullable[HashPoint[Subject]]
) -> Iterable[tuple[Coin, 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) assert isinstance(transaction_data, TransactionData)
index = 0 index = 0
out_coin: HashPoint[CoinData] out_coin: HashPoint[CoinData]
@ -258,7 +271,7 @@ class Transaction(RecursiveMentionable, StaticMentionable):
def verify(self, mint: int): def verify(self, mint: int):
assert isinstance(mint, int) assert isinstance(mint, int)
data: TransactionData = self.data.resolve() data: TransactionData = self.data_resolved()
assert isinstance(data, TransactionData) assert isinstance(data, TransactionData)
assert data.verify(self.signatures, mint) assert data.verify(self.signatures, mint)
return True return True

View File

@ -1,15 +1,15 @@
import bisect import bisect
from typing import Iterable, Sequence from typing import Iterable, Sequence
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.localmetaorigin import LocalMetaOrigin from rainbowadn.core.localmetaorigin import LocalMetaOrigin
from rainbowadn.hashing.localorigin import LocalOrigin from rainbowadn.core.localorigin import LocalOrigin
from rainbowadn.hashing.metaorigin import MetaOrigin from rainbowadn.core.metaorigin import MetaOrigin
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolvermetaorigin import ResolverMetaOrigin from rainbowadn.core.resolvermetaorigin import ResolverMetaOrigin
from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres
__all__ = ('WeakReferenceIndexSetBTree', 'WrisbtFactory',) __all__ = ('WeakReferenceIndexSetBTree', 'WrisbtFactory',)
@ -95,6 +95,12 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
self.bytes_no(index, self.keyend, HashPoint.HASH_LENGTH) 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: def balanced(self) -> bool:
return self.keys <= 2 * self.keymin return self.keys <= 2 * self.keymin
@ -181,7 +187,7 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
assert key > self.key_no(index - 1) assert key > self.key_no(index - 1)
if self.leaf: if self.leaf:
return False return False
child: WeakReferenceIndexSetBTree = self.child_no(index).resolve() child: WeakReferenceIndexSetBTree = self.child_resolved_no(index)
assert isinstance(child, WeakReferenceIndexSetBTree) assert isinstance(child, WeakReferenceIndexSetBTree)
return child.contains(key) return child.contains(key)
@ -208,7 +214,7 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
self.root, self.root,
() ()
) )
child: WeakReferenceIndexSetBTree = self.child_no(index).resolve() child: WeakReferenceIndexSetBTree = self.child_resolved_no(index)
assert isinstance(child, WeakReferenceIndexSetBTree) assert isinstance(child, WeakReferenceIndexSetBTree)
child: WeakReferenceIndexSetBTree = child.add(key) child: WeakReferenceIndexSetBTree = child.add(key)
assert isinstance(child, WeakReferenceIndexSetBTree) assert isinstance(child, WeakReferenceIndexSetBTree)
@ -273,7 +279,7 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
if mode: if mode:
yield self.key_no(real_index) yield self.key_no(real_index)
else: 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]): class KeyView(Sequence[WeakReferenceIndexSetBTree]):

View File

@ -1,8 +1,8 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.chain.blockchainprotocol import BlockChainProtocol from rainbowadn.chain.blockchainprotocol import BlockChainProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.wrisbt.wrisbtindex import WrisbtIndex, WrisbtIndexFactory from rainbowadn.wrisbt.wrisbtindex import WrisbtIndex, WrisbtIndexFactory
from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres
from rainbowadn.wrisbt.wrisbtprotocol import WrisbtProtocol from rainbowadn.wrisbt.wrisbtprotocol import WrisbtProtocol

View File

@ -1,11 +1,11 @@
from typing import Iterable from typing import Iterable
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres
from rainbowadn.wrisbt.wrisbtroot import WrisbtRoot, WrisbtRootFactory from rainbowadn.wrisbt.wrisbtroot import WrisbtRoot, WrisbtRootFactory

View File

@ -1,7 +1,7 @@
from typing import TypeVar from typing import TypeVar
from rainbowadn.chain.states.metareductionstateprotocol import MetaReductionStateProtocol 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.wrisbtindex import WrisbtIndex
from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres
from rainbowadn.wrisbt.wrisbtroot import WrisbtRoot from rainbowadn.wrisbt.wrisbtroot import WrisbtRoot

View File

@ -1,15 +1,15 @@
from typing import Iterable from typing import Iterable
from rainbowadn.data.atomic.integer import Integer from rainbowadn.data.atomic.integer import Integer
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.core.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.core.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.core.hashresolver import HashResolver
from rainbowadn.hashing.localmetaorigin import LocalMetaOrigin from rainbowadn.core.localmetaorigin import LocalMetaOrigin
from rainbowadn.hashing.localorigin import LocalOrigin from rainbowadn.core.localorigin import LocalOrigin
from rainbowadn.hashing.mentionable import Mentionable from rainbowadn.core.mentionable import Mentionable
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.core.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.core.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin from rainbowadn.core.resolverorigin import ResolverOrigin
from rainbowadn.wrisbt.weakreferenceindexsetbtree import WeakReferenceIndexSetBTree, WrisbtFactory from rainbowadn.wrisbt.weakreferenceindexsetbtree import WeakReferenceIndexSetBTree, WrisbtFactory
from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres
@ -25,6 +25,9 @@ class WrisbtRoot(RecursiveMentionable):
self.height = height self.height = height
self.parametres = parametres self.parametres = parametres
def root_resolved(self) -> 'WeakReferenceIndexSetBTree':
return self.root.resolve()
def points(self) -> Iterable[HashPoint]: def points(self) -> Iterable[HashPoint]:
return [self.root] return [self.root]
@ -49,7 +52,7 @@ class WrisbtRoot(RecursiveMentionable):
assert isinstance(key, bytes) assert isinstance(key, bytes)
assert len(key) == self.parametres.keysize assert len(key) == self.parametres.keysize
root: WeakReferenceIndexSetBTree = self.root.resolve() root: WeakReferenceIndexSetBTree = self.root_resolved()
assert isinstance(root, WeakReferenceIndexSetBTree) assert isinstance(root, WeakReferenceIndexSetBTree)
return root.contains(key) return root.contains(key)
@ -58,7 +61,7 @@ class WrisbtRoot(RecursiveMentionable):
assert isinstance(key, bytes) assert isinstance(key, bytes)
assert len(key) == self.parametres.keysize assert len(key) == self.parametres.keysize
root: WeakReferenceIndexSetBTree = self.root.resolve().add(key) root: WeakReferenceIndexSetBTree = self.root_resolved().add(key)
assert isinstance(root, WeakReferenceIndexSetBTree) assert isinstance(root, WeakReferenceIndexSetBTree)
if root.full(): if root.full():
@ -82,7 +85,7 @@ class WrisbtRoot(RecursiveMentionable):
return cls(HashPoint.of(root), root.height, root.parametres) return cls(HashPoint.of(root), root.height, root.parametres)
def keys(self) -> list[bytes]: def keys(self) -> list[bytes]:
return list(self.root.resolve().iter_keys()) return list(self.root_resolved().iter_keys())
def index( def index(
self, target: HashPoint, exclude: 'WrisbtRoot' self, target: HashPoint, exclude: 'WrisbtRoot'