less of direct .resolve() calls
This commit is contained in:
parent
426fbc1fa5
commit
dcad23c818
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
@ -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',)
|
||||
|
@ -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',)
|
||||
|
@ -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',)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import TypeVar
|
||||
|
||||
from rainbowadn.hashing.rainbow_factory import RainbowFactory
|
||||
from rainbowadn.core.rainbow_factory import RainbowFactory
|
||||
|
||||
__all__ = ('Mentionable',)
|
||||
|
@ -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',)
|
||||
|
@ -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',)
|
||||
|
@ -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',)
|
||||
|
@ -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
|
@ -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',)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
from rainbowadn.hashing.hashresolver import HashResolver
|
||||
from rainbowadn.core.hashresolver import HashResolver
|
||||
|
||||
__all__ = ('RainbowFactory',)
|
||||
|
@ -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',)
|
||||
|
@ -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()
|
@ -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',)
|
||||
|
@ -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',)
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
from rainbowadn.hashing.hashpoint import HashPoint
|
||||
from rainbowadn.core.hashpoint import HashPoint
|
||||
|
||||
__all__ = ('BinaryTreeSplit',)
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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',)
|
||||
|
||||
|
@ -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')
|
||||
|
||||
|
@ -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):
|
||||
|
@ -1,4 +1,4 @@
|
||||
from rainbowadn.hashing.hashresolver import HashResolver
|
||||
from rainbowadn.core.hashresolver import HashResolver
|
||||
|
||||
|
||||
class FailResolver(HashResolver):
|
||||
|
@ -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
|
||||
|
0
rainbowadn/toplevel/__init__.py
Normal file
0
rainbowadn/toplevel/__init__.py
Normal file
10
rainbowadn/toplevel/thresholdprotocol.py
Normal file
10
rainbowadn/toplevel/thresholdprotocol.py
Normal 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
|
48
rainbowadn/toplevel/validreference.py
Normal file
48
rainbowadn/toplevel/validreference.py
Normal 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)
|
@ -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
|
||||
|
@ -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),
|
||||
|
@ -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)})'
|
||||
|
@ -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',)
|
||||
|
@ -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
|
||||
|
@ -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]):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user