change import structure

This commit is contained in:
AF 2022-07-11 19:54:46 +03:00
parent a51967b238
commit 8bf8fcea32
49 changed files with 477 additions and 251 deletions

View File

@ -4,6 +4,8 @@ from pathlib import Path
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
__all__ = ('plot',)
def plottable(log: list[tuple[float, int]]): def plottable(log: list[tuple[float, int]]):
if log: if log:

View File

@ -1,3 +1,9 @@
from .atomic import * __all__ = (
from .integer import * 'Atomic',
from .plain import * 'Integer',
'Plain',
)
from .atomic import Atomic
from .integer import Integer
from .plain import Plain

View File

@ -1,5 +1,13 @@
from .blockchain import * __all__ = (
from .blockchainprotocol import * 'BlockChain', 'BlockChainFactory',
from .chaincollectionfactory import * 'BlockChainProtocol',
from .chaincollectioninterface import * 'ChainCollectionFactory',
from .reductionchainmetafactory import * 'ChainCollectionInterface',
'ReductionChainMetaFactory',
)
from .blockchain import BlockChain, BlockChainFactory
from .blockchainprotocol import BlockChainProtocol
from .chaincollectionfactory import ChainCollectionFactory
from .chaincollectioninterface import ChainCollectionInterface
from .reductionchainmetafactory import ReductionChainMetaFactory

View File

@ -11,7 +11,6 @@ __all__ = ('BlockChain', 'BlockChainFactory',)
HeaderType = TypeVar('HeaderType') HeaderType = TypeVar('HeaderType')
StateType = TypeVar('StateType') StateType = TypeVar('StateType')
ActualStateType = TypeVar('ActualStateType')
class BlockChain( class BlockChain(
@ -20,10 +19,9 @@ class BlockChain(
HeaderType, HeaderType,
StateType StateType
], ],
HeaderType, HeaderType
ActualStateType
], ],
Generic[HeaderType, ActualStateType, StateType], Generic[HeaderType, StateType],
): ):
def __init__( def __init__(
self, self,
@ -33,7 +31,7 @@ class BlockChain(
StateType StateType
] ]
], ],
protocol: BlockChainProtocol[HeaderType, StateType, ActualStateType], protocol: BlockChainProtocol[HeaderType, StateType],
): ):
assert isinstance(reference, NullableReference) assert isinstance(reference, NullableReference)
assert isinstance(protocol, BlockChainProtocol) assert isinstance(protocol, BlockChainProtocol)
@ -45,8 +43,7 @@ class BlockChain(
HeaderType, HeaderType,
StateType StateType
], ],
HeaderType, HeaderType
ActualStateType
]: ]:
return BlockChainFactory(self.protocol) return BlockChainFactory(self.protocol)
@ -58,8 +55,7 @@ class BlockChain(
HeaderType, HeaderType,
StateType StateType
], ],
HeaderType, HeaderType
ActualStateType
]: ]:
assert isinstance(header, HashPoint) assert isinstance(header, HashPoint)
return self.factory().from_reference( return self.factory().from_reference(
@ -107,8 +103,7 @@ class BlockChain(
HeaderType, HeaderType,
StateType StateType
], ],
HeaderType, HeaderType
ActualStateType
]: ]:
assert not self.reference.null() assert not self.reference.null()
block: Block[ block: Block[
@ -123,7 +118,7 @@ class BlockChain(
return True return True
else: else:
previous: ChainCollectionInterface[ previous: ChainCollectionInterface[
Block[HeaderType, StateType], HeaderType, ActualStateType Block[HeaderType, StateType], HeaderType
] = await self.previous() ] = await self.previous()
assert isinstance(previous, ChainCollectionInterface) assert isinstance(previous, ChainCollectionInterface)
assert_trues( assert_trues(
@ -161,26 +156,12 @@ class BlockChain(
) )
return True return True
def _actual_state_factory(self) -> RainbowFactory[ActualStateType]:
return self.protocol.actual_state_factory()
async def _actual_state(
self,
block: Block[
HeaderType,
StateType
]
) -> HashPoint[ActualStateType]:
assert isinstance(block, Block)
return await self.protocol.actual_state(await block.state.resolve())
def loose(self) -> ChainCollectionInterface[ def loose(self) -> ChainCollectionInterface[
Block[ Block[
HeaderType, HeaderType,
StateType StateType
], ],
HeaderType, HeaderType
ActualStateType
]: ]:
return self return self
@ -191,19 +172,18 @@ class BlockChainFactory(
HeaderType, HeaderType,
StateType StateType
], ],
HeaderType, HeaderType
ActualStateType
], ],
Generic[HeaderType, ActualStateType, StateType] Generic[HeaderType, StateType]
): ):
def __init__( def __init__(
self, self,
protocol: BlockChainProtocol[HeaderType, StateType, ActualStateType], protocol: BlockChainProtocol[HeaderType, StateType],
): ):
assert isinstance(protocol, BlockChainProtocol) assert isinstance(protocol, BlockChainProtocol)
self.protocol = protocol self.protocol = protocol
def empty(self) -> BlockChain[HeaderType, ActualStateType, StateType]: def empty(self) -> BlockChain[HeaderType, StateType]:
return BlockChain( return BlockChain(
NullableReference( NullableReference(
Null(), Null(),
@ -224,7 +204,7 @@ class BlockChainFactory(
], ],
] ]
) -> BlockChain[ ) -> BlockChain[
HeaderType, ActualStateType, StateType HeaderType, StateType
]: ]:
assert isinstance(reference, NullableReference) assert isinstance(reference, NullableReference)
return BlockChain( return BlockChain(

View File

@ -7,11 +7,10 @@ __all__ = ('BlockChainProtocol',)
HeaderType = TypeVar('HeaderType') HeaderType = TypeVar('HeaderType')
StateType = TypeVar('StateType') StateType = TypeVar('StateType')
ActualStateType = TypeVar('ActualStateType')
class BlockChainProtocol( class BlockChainProtocol(
Generic[HeaderType, StateType, ActualStateType], Generic[HeaderType, StateType],
): ):
def __init__( def __init__(
self, self,
@ -26,14 +25,5 @@ class BlockChainProtocol(
self.header_factory = header_factory self.header_factory = header_factory
self.state_factory = state_factory self.state_factory = state_factory
def actual_state_factory(self) -> RainbowFactory[ActualStateType]: def loose(self) -> 'BlockChainProtocol[HeaderType, StateType]':
raise NotImplementedError
async def actual_state(
self,
state: StateType
) -> HashPoint[ActualStateType]:
raise NotImplementedError
def loose(self) -> 'BlockChainProtocol[HeaderType, StateType, ActualStateType]':
return self return self

View File

@ -8,14 +8,13 @@ __all__ = ('BlockCollectionInterface',)
BlockType = TypeVar('BlockType') BlockType = TypeVar('BlockType')
HeaderType = TypeVar('HeaderType') HeaderType = TypeVar('HeaderType')
ActualStateType = TypeVar('ActualStateType')
class BlockCollectionInterface( class BlockCollectionInterface(
CollectionInterface[ CollectionInterface[
BlockType BlockType
], ],
Generic[BlockType, HeaderType, ActualStateType] Generic[BlockType, HeaderType]
): ):
def __init__( def __init__(
self, self,
@ -44,20 +43,8 @@ class BlockCollectionInterface(
previous previous
) )
def _actual_state_factory(self) -> RainbowFactory[ActualStateType]:
raise NotImplementedError
async def _actual_state(self, block: BlockType) -> HashPoint[ActualStateType]:
raise NotImplementedError
async def actual_state(self) -> NullableReference[ActualStateType]:
if self.reference.null():
return NullableReference(Null(), self._actual_state_factory())
else:
return NullableReference.of(await self._actual_state(await self.reference.resolve()))
async def add( async def add(
self, self,
header: HashPoint[HeaderType] header: HashPoint[HeaderType]
) -> 'BlockCollectionInterface[BlockType, HeaderType, ActualStateType]': ) -> 'BlockCollectionInterface[BlockType, HeaderType]':
raise NotImplementedError raise NotImplementedError

View File

@ -7,18 +7,17 @@ __all__ = ('ChainCollectionFactory',)
BlockType = TypeVar('BlockType') BlockType = TypeVar('BlockType')
HeaderType = TypeVar('HeaderType') HeaderType = TypeVar('HeaderType')
ActualStateType = TypeVar('ActualStateType')
class ChainCollectionFactory(Generic[BlockType, HeaderType, ActualStateType]): class ChainCollectionFactory(Generic[BlockType, HeaderType]):
def empty(self) -> ChainCollectionInterface[BlockType, HeaderType, ActualStateType]: def empty(self) -> ChainCollectionInterface[BlockType, HeaderType]:
raise NotImplementedError raise NotImplementedError
def from_reference( def from_reference(
self, self,
reference: NullableReference[BlockType] reference: NullableReference[BlockType]
) -> ChainCollectionInterface[BlockType, HeaderType, ActualStateType]: ) -> ChainCollectionInterface[BlockType, HeaderType]:
raise NotImplementedError raise NotImplementedError
def loose(self) -> 'ChainCollectionFactory[BlockType, HeaderType, ActualStateType]': def loose(self) -> 'ChainCollectionFactory[BlockType, HeaderType]':
return self return self

View File

@ -8,22 +8,20 @@ __all__ = ('ChainCollectionInterface',)
BlockType = TypeVar('BlockType') BlockType = TypeVar('BlockType')
HeaderType = TypeVar('HeaderType') HeaderType = TypeVar('HeaderType')
ActualStateType = TypeVar('ActualStateType')
class ChainCollectionInterface( class ChainCollectionInterface(
BlockCollectionInterface[ BlockCollectionInterface[
BlockType, BlockType,
HeaderType, HeaderType
ActualStateType
], ],
Generic[BlockType, HeaderType, ActualStateType], Generic[BlockType, HeaderType],
abc.ABC abc.ABC
): ):
async def add( async def add(
self, self,
header: HashPoint[HeaderType] header: HashPoint[HeaderType]
) -> 'ChainCollectionInterface[BlockType, HeaderType, ActualStateType]': ) -> 'ChainCollectionInterface[BlockType, HeaderType]':
raise NotImplementedError raise NotImplementedError
async def verify(self) -> bool: async def verify(self) -> bool:

View File

@ -1,5 +1,13 @@
from .activestageprotocol import * __all__ = (
from .activestagestateprotocol import * 'ActiveStageProtocol',
from .derived import * 'ActiveStageStateProtocol',
from .derivedstage import * 'Derived',
from .derivedstate import * 'DerivedStage',
'DerivedState',
)
from .activestageprotocol import ActiveStageProtocol
from .activestagestateprotocol import ActiveStageStateProtocol
from .derived import Derived
from .derivedstage import DerivedStage
from .derivedstate import DerivedState

View File

@ -1,6 +1,15 @@
from .abstractreductionchainmetafactory import * __all__ = (
from .reduced import * 'AbstractReductionChainMetaFactory',
from .reducible import * 'Reduced',
from .reductionchainprotocol import * 'Reducible', 'ReducibleFactory',
from .reductionprotocol import * 'ReductionChainProtocol',
from .reductionresult import * 'ReductionProtocol',
'ReductionResult',
)
from .abstractreductionchainmetafactory import AbstractReductionChainMetaFactory
from .reduced import Reduced
from .reducible import Reducible, ReducibleFactory
from .reductionchainprotocol import ReductionChainProtocol
from .reductionprotocol import ReductionProtocol
from .reductionresult import ReductionResult

View File

@ -20,6 +20,6 @@ class AbstractReductionChainMetaFactory(
accumulator_factory: RainbowFactory[AccumulatorType], accumulator_factory: RainbowFactory[AccumulatorType],
protocol: ReductionProtocol[ReductorType, AccumulatorType], protocol: ReductionProtocol[ReductorType, AccumulatorType],
) -> ChainCollectionFactory[ ) -> ChainCollectionFactory[
BlockType, ReductorType, AccumulatorType BlockType, ReductorType
]: ]:
raise NotImplementedError raise NotImplementedError

View File

@ -17,8 +17,7 @@ AccumulatorType = TypeVar('AccumulatorType')
class ReductionChainProtocol( class ReductionChainProtocol(
BlockChainProtocol[ BlockChainProtocol[
ReductorType, ReductorType,
StateStage[ReductorType, AccumulatorType, Reducible[ReductorType, AccumulatorType]], StateStage[ReductorType, AccumulatorType, Reducible[ReductorType, AccumulatorType]]
AccumulatorType
] ]
): ):
def __init__( def __init__(
@ -60,17 +59,3 @@ class ReductionChainProtocol(
self.reductor_factory = reductor_factory self.reductor_factory = reductor_factory
self.accumulator_factory = accumulator_factory self.accumulator_factory = accumulator_factory
def actual_state_factory(self) -> RainbowFactory[AccumulatorType]:
return self.accumulator_factory
async def actual_state(
self,
state: StateStage[
ReductorType,
AccumulatorType,
Reducible[ReductorType, AccumulatorType]
]
) -> HashPoint[AccumulatorType]:
assert isinstance(state, StateStage)
return state.state

View File

@ -34,8 +34,7 @@ class ReductionChainMetaFactory(
ReductorType, ReductorType,
StateStage[ReductorType, AccumulatorType, Reducible[ReductorType, AccumulatorType]] StateStage[ReductorType, AccumulatorType, Reducible[ReductorType, AccumulatorType]]
], ],
ReductorType, ReductorType
AccumulatorType
]: ]:
assert isinstance(reductor_factory, RainbowFactory) assert isinstance(reductor_factory, RainbowFactory)
assert isinstance(accumulator_factory, RainbowFactory) assert isinstance(accumulator_factory, RainbowFactory)

View File

@ -1,3 +1,9 @@
__all__ = (
'StageProtocol',
'StageStage', 'StageStageFactory', 'StateStage', 'StateStageFactory',
'StageStateProtocol',
)
from .stageprotocol import StageProtocol from .stageprotocol import StageProtocol
from .stagestate import * from .stagestate import StageStage, StageStageFactory, StateStage, StateStageFactory
from .stagestateprotocol import StageStateProtocol from .stagestateprotocol import StageStateProtocol

View File

@ -5,10 +5,7 @@ from rainbowadn.nullability import *
from .stageprotocol import * from .stageprotocol import *
__all__ = ( __all__ = (
'StageStage', 'StageStage', 'StageStageFactory', 'StateStage', 'StateStageFactory',
'StageStageFactory',
'StateStage',
'StateStageFactory',
) )
HeaderType = TypeVar('HeaderType') HeaderType = TypeVar('HeaderType')

View File

@ -1,3 +1,9 @@
__all__ = (
'ActiveStateProtocol',
'MetaReductionStateProtocol',
'StateProtocol',
)
from .activestateprotocol import ActiveStateProtocol from .activestateprotocol import ActiveStateProtocol
from .metareductionstateprotocol import MetaReductionStateProtocol from .metareductionstateprotocol import MetaReductionStateProtocol
from .stateprotocol import StateProtocol from .stateprotocol import StateProtocol

View File

@ -1,4 +1,11 @@
from .comparator import * __all__ = (
from .hashcomparator import * 'Comparison', 'Left', 'Right', 'Equal', 'Replace', 'Fail', 'Duplicate', 'Comparator',
from .keyedcomparator import * 'HashComparator',
from .plaincomparator import * 'KeyedComparator',
'PlainComparator',
)
from .comparator import Comparator, Comparison, Duplicate, Equal, Fail, Left, Replace, Right
from .hashcomparator import HashComparator
from .keyedcomparator import KeyedComparator
from .plaincomparator import PlainComparator

View File

@ -4,14 +4,7 @@ from typing import Generic, TypeVar
from rainbowadn.core import * from rainbowadn.core import *
__all__ = ( __all__ = (
'Comparison', 'Comparison', 'Left', 'Right', 'Equal', 'Replace', 'Fail', 'Duplicate', 'Comparator',
'Left',
'Right',
'Equal',
'Replace',
'Fail',
'Duplicate',
'Comparator',
) )

View File

@ -1,3 +1,9 @@
from .array import * __all__ = (
from .stack import * 'Array', 'ArrayFactory',
from .treelist import * 'Stack', 'StackFactory',
'TLRoot', 'TLRootFactory', 'TLRParametres',
)
from .array import Array, ArrayFactory
from .stack import Stack, StackFactory
from .treelist import TLRParametres, TLRoot, TLRootFactory

View File

@ -1,2 +1,7 @@
from .tlroot import * __all__ = (
'TLRoot', 'TLRootFactory',
'TLRParametres',
)
from .tlroot import TLRoot, TLRootFactory
from .tlrparametres import TLRParametres from .tlrparametres import TLRParametres

View File

@ -1,3 +1,9 @@
from .activebinarytree import * __all__ = (
from .avl import * 'ActiveBinaryTree',
from .binarytree import * 'AVL',
'BinaryTree', 'BinaryTreeFactory',
)
from .activebinarytree import ActiveBinaryTree
from .avl import AVL
from .binarytree import BinaryTree, BinaryTreeFactory

View File

@ -1,3 +1,9 @@
from .binaryaction import * __all__ = (
from .stdactions import * 'BinaryAction',
from .symmetric import * 'AddAction', 'RemoveAction', 'ContainsAction',
'Symmetric', 'InnerOuter', 'OuterInner',
)
from .binaryaction import BinaryAction
from .stdactions import AddAction, ContainsAction, RemoveAction
from .symmetric import InnerOuter, OuterInner, Symmetric

View File

@ -1,3 +1,12 @@
__all__ = (
'BalancedCreation',
'BinaryBalancing',
'BinaryCreation',
'BinaryProtocolized',
'BinarySplit',
'ProtocolizedBinarySplit',
)
from .balancedcreation import BalancedCreation from .balancedcreation import BalancedCreation
from .binarybalancing import BinaryBalancing from .binarybalancing import BinaryBalancing
from .binarycreation import BinaryCreation from .binarycreation import BinaryCreation

View File

@ -1,16 +1,35 @@
from .asserts import * __all__ = (
from .extendableresolver import * 'assert_true', 'assert_trues', 'assert_false', 'assert_none', 'assert_none_strict', 'assert_eq',
from .gather import * 'ExtendableResolver',
from .hash_point_format import * 'gather', 'asum', 'alist', 'set_gather_asyncio', 'set_gather_linear',
from .hashpoint import * 'hash_point_format', 'tabulate',
from .hashresolver import * 'HashPoint',
from .localmetaorigin import * 'HashResolver',
from .localorigin import * 'LocalMetaOrigin',
from .mentionable import * 'LocalOrigin',
from .metaorigin import * 'Mentionable',
from .origin import * 'MetaOrigin',
from .rainbow_factory import * 'Origin',
from .recursivementionable import * 'RainbowFactory',
from .resolvermetaorigin import * 'RecursiveMentionable',
from .resolverorigin import * 'ResolverMetaOrigin',
from .static import * 'ResolverOrigin',
'StaticMentionable', 'StaticFactory',
)
from .asserts import assert_eq, assert_false, assert_none, assert_none_strict, assert_true, assert_trues
from .extendableresolver import ExtendableResolver
from .gather import alist, asum, gather, set_gather_asyncio, set_gather_linear
from .hash_point_format import hash_point_format, tabulate
from .hashpoint import HashPoint
from .hashresolver import HashResolver
from .localmetaorigin import LocalMetaOrigin
from .localorigin import LocalOrigin
from .mentionable import Mentionable
from .metaorigin import MetaOrigin
from .origin import Origin
from .rainbow_factory import RainbowFactory
from .recursivementionable import RecursiveMentionable
from .resolvermetaorigin import ResolverMetaOrigin
from .resolverorigin import ResolverOrigin
from .static import StaticFactory, StaticMentionable

View File

@ -1 +1,5 @@
from .encrypted import * __all__ = (
'Encrypted', 'EncryptedFactory',
)
from .encrypted import Encrypted, EncryptedFactory

View File

@ -5,7 +5,7 @@ from nacl.secret import SecretBox
from rainbowadn.core import * from rainbowadn.core import *
__all__ = ('Encrypted', 'EncryptedFactory') __all__ = ('Encrypted', 'EncryptedFactory',)
EncryptedType = TypeVar('EncryptedType') EncryptedType = TypeVar('EncryptedType')

View File

@ -1,5 +1,11 @@
"""a bridge between old .chain and new .flow """a bridge between old .chain and new .flow
todo: deprecate todo: deprecate
""" """
from ._stackbridge import *
from ._stagebridge import * __all__ = (
'StackBridge',
'StageBridgeVP', 'StageBridgeM', 'stage_bridge',
)
from ._stackbridge import StackBridge
from ._stagebridge import StageBridgeM, StageBridgeVP, stage_bridge

View File

@ -6,11 +6,12 @@ from rainbowadn.collection.pair import *
from rainbowadn.core import * from rainbowadn.core import *
from rainbowadn.flow.core import * from rainbowadn.flow.core import *
from rainbowadn.flow.sequence import * from rainbowadn.flow.sequence import *
from rainbowadn.flow.verification.core import *
from rainbowadn.flow.verification.stages import * from rainbowadn.flow.verification.stages import *
from rainbowadn.nullability import * from rainbowadn.nullability import *
from ._stackbridge import * from ._stackbridge import *
__all__ = ('StageBridgeVP', 'StageBridgeM',) __all__ = ('StageBridgeVP', 'StageBridgeM', 'stage_bridge',)
BaseT = TypeVar('BaseT') BaseT = TypeVar('BaseT')
StageT = TypeVar('StageT') StageT = TypeVar('StageT')
@ -69,3 +70,34 @@ class StageBridgeM(
stack_bridge: Reducer[SequenceDispatcher[HashPoint[StageT], bool], bool] = StackBridge(stages_stack).loose() stack_bridge: Reducer[SequenceDispatcher[HashPoint[StageT], bool], bool] = StackBridge(stages_stack).loose()
assert isinstance(stack_bridge, Reducer) assert isinstance(stack_bridge, Reducer)
return base, stack_bridge return base, stack_bridge
def stage_bridge(
stage_protocol: StageProtocol[HeaderT, BaseT, StageT], base_factory: RainbowFactory[BaseT]
) -> Verification[
tuple[
Nullable[HashPoint[Pair[BaseT, Stack[StageT]]]],
HashPoint[HeaderT],
HashPoint[Pair[BaseT, Stack[StageT]]]
]
]:
assert isinstance(stage_protocol, StageProtocol)
assert isinstance(base_factory, RainbowFactory)
vp: StageVerificationProtocol[
HashPoint[BaseT], HashPoint[StageT], HashPoint[HeaderT]
] = StageBridgeVP(stage_protocol, base_factory)
assert isinstance(vp, StageVerificationProtocol)
m: Mapper[
HashPoint[Pair[BaseT, Stack[StageT]]],
tuple[HashPoint[BaseT], Reducer[SequenceDispatcher[HashPoint[StageT], bool], bool]]
] = StageBridgeM()
assert isinstance(m, Mapper)
v: Verification[
tuple[
Nullable[HashPoint[Pair[BaseT, Stack[StageT]]]],
HashPoint[HeaderT],
HashPoint[Pair[BaseT, Stack[StageT]]]
]
] = StageVerification(vp, m).loose()
assert isinstance(v, Verification)
return v

View File

@ -0,0 +1,94 @@
from typing import Generic, TypeVar
from rainbowadn.chain.states import *
from rainbowadn.collection.pair import *
from rainbowadn.core import *
from rainbowadn.flow.core import *
from rainbowadn.flow.verification.core import *
from rainbowadn.flow.verification.stateverification import *
from rainbowadn.nullability import *
__all__ = ('StateBridgeM', 'StateBridgeV',)
HeaderT = TypeVar('HeaderT')
StateT = TypeVar('StateT')
class StateBridgeM(
Mapper[
HashPoint[Pair[HeaderT, StateT]],
tuple[HashPoint[HeaderT], HashPoint[StateT]],
],
Generic[HeaderT, StateT]
):
async def map(
self,
element: HashPoint[Pair[HeaderT, StateT]]
) -> tuple[HashPoint[HeaderT], HashPoint[StateT]]:
assert isinstance(element, HashPoint)
resolved = await element.resolve()
header: HashPoint[HeaderT] = resolved.element0
assert isinstance(header, HashPoint)
state: HashPoint[StateT] = resolved.element1
assert isinstance(state, HashPoint)
return header, state
class StateBridgeV(
Verification[
tuple[Nullable[HashPoint[StateT]], HashPoint[HeaderT], HashPoint[StateT]]
],
Generic[HeaderT, StateT]
):
def __init__(self, protocol: StateProtocol[HeaderT, StateT]):
assert isinstance(protocol, StateProtocol)
self.protocol = protocol
async def verify(
self,
element: tuple[Nullable[HashPoint[StateT]], HashPoint[HeaderT], HashPoint[StateT]]
) -> bool:
assert isinstance(element, tuple)
previous: Nullable[HashPoint[StateT]]
header: HashPoint[HeaderT]
state: HashPoint[StateT]
previous, header, state = element
assert isinstance(previous, Nullable)
assert isinstance(header, HashPoint)
assert isinstance(state, HashPoint)
assert_true(
await self.protocol.verify(
NullableReference(previous, state.factory),
header,
state
)
)
return True
def state_bridge(
protocol: StateProtocol[HeaderT, StateT]
) -> Verification[
tuple[
Nullable[HashPoint[Pair[HeaderT, StateT]]],
HashPoint[Pair[HeaderT, StateT]]
]
]:
assert isinstance(protocol, StateProtocol)
m: Mapper[
HashPoint[Pair[HeaderT, StateT]],
tuple[HashPoint[HeaderT], HashPoint[StateT]],
] = StateBridgeM()
assert isinstance(m, Mapper)
sv: Verification[
tuple[Nullable[HashPoint[StateT]], HashPoint[HeaderT], HashPoint[StateT]]
] = StateBridgeV(protocol)
assert isinstance(sv, Verification)
v: Verification[
tuple[
Nullable[HashPoint[Pair[HeaderT, StateT]]],
HashPoint[Pair[HeaderT, StateT]]
]
] = StateVerification(m, sv).loose()
assert isinstance(v, Verification)
return v

View File

@ -1,5 +1,13 @@
from ._mapper import * __all__ = (
from ._mapreduce import * 'Mapper',
from ._mapreducer import * 'MapReduce',
from ._reduce import * 'MapReducer',
from ._reducer import * 'Reduce',
'Reducer',
)
from ._mapper import Mapper
from ._mapreduce import MapReduce
from ._mapreducer import MapReducer
from ._reduce import Reduce
from ._reducer import Reducer

View File

@ -1,3 +1,9 @@
from ._dispatchmapper import * __all__ = (
from ._sequencedispatch import * 'DispatchMapper',
from ._sequencedispatcher import * 'SequenceDispatch',
'SequenceDispatcher', 'FirstDispatcher', 'LastDispatcher', 'PairDispatcher',
)
from ._dispatchmapper import DispatchMapper
from ._sequencedispatch import SequenceDispatch
from ._sequencedispatcher import FirstDispatcher, LastDispatcher, PairDispatcher, SequenceDispatcher

View File

@ -1,2 +1,7 @@
from ._stackedreduce import * __all__ = (
from ._stackedreducer import * 'StackedReduce',
'StackedReducer',
)
from ._stackedreduce import StackedReduce
from ._stackedreducer import StackedReducer

View File

@ -1,4 +1,11 @@
from ._mapperverification import * __all__ = (
from ._reduceverification import * 'MapperVerification',
from ._verification import * 'ReduceVerification',
from ._verifyreduce import * 'Verification',
'VerifyReduce',
)
from ._mapperverification import MapperVerification
from ._reduceverification import ReduceVerification
from ._verification import Verification
from ._verifyreduce import VerifyReduce

View File

@ -1,2 +1,7 @@
from ._stageverification import * __all__ = (
from ._stageverificationprotocol import * 'StageVerification',
'StageVerificationProtocol',
)
from ._stageverification import StageVerification
from ._stageverificationprotocol import StageVerificationProtocol

View File

@ -55,3 +55,6 @@ class StateVerification(
assert isinstance(element, tuple) assert isinstance(element, tuple)
assert_true(await self.verification.map(await self._tuple(element))) assert_true(await self.verification.map(await self._tuple(element)))
return True return True
def loose(self) -> Verification[tuple[Nullable[Chain], Chain]]:
return self

View File

@ -1,4 +1,11 @@
from .concurrency import * __all__ = (
from .counter import * 'Concurrency',
from .entryexit import * 'Counter',
from .instrumentation import * 'EntryExit',
'Instrumentation',
)
from .concurrency import Concurrency
from .counter import Counter
from .entryexit import EntryExit
from .instrumentation import Instrumentation

View File

@ -1,4 +1,11 @@
from .notnull import * __all__ = (
from .null import * 'NotNull',
from .nullable import * 'Null',
from .nullablereference import * 'Nullable',
'NullableReference', 'NullableReferenceFactory',
)
from .notnull import NotNull
from .null import Null
from .nullable import Nullable
from .nullablereference import NullableReference, NullableReferenceFactory

View File

@ -1,5 +1,13 @@
from .cachingresolver import * __all__ = (
from .defaultresolver import * 'CachingResolver',
from .delayedresolver import * 'default_resolver',
from .dictresolver import * 'DelayedResolver',
from .failresolver import * 'DictResolver',
'FailResolver',
)
from .cachingresolver import CachingResolver
from .defaultresolver import default_resolver
from .delayedresolver import DelayedResolver
from .dictresolver import DictResolver
from .failresolver import FailResolver

View File

@ -1,5 +1,7 @@
from rainbowadn.core import * from rainbowadn.core import *
__all__ = ('FailResolver',)
class FailResolver(HashResolver): class FailResolver(HashResolver):
async def resolve(self, point: bytes) -> tuple[bytes, 'HashResolver']: async def resolve(self, point: bytes) -> tuple[bytes, 'HashResolver']:

View File

@ -1,13 +1,13 @@
import unittest import unittest
from rainbowadn.atomic import Plain from rainbowadn.atomic import *
from rainbowadn.collection.linear import Stack from rainbowadn.collection.linear import *
from rainbowadn.core import HashPoint, assert_none_strict, hash_point_format from rainbowadn.core import *
from rainbowadn.flow.bridge import StackBridge from rainbowadn.flow.bridge import *
from rainbowadn.flow.core import MapReduce, Reduce from rainbowadn.flow.core import *
from rainbowadn.flow.sequence import DispatchMapper, SequenceDispatch from rainbowadn.flow.sequence import *
from rainbowadn.flow.stacked import StackedReducer from rainbowadn.flow.stacked import *
from rainbowadn.nullability import Nullable from rainbowadn.nullability import *
class PrintDispatch(SequenceDispatch[HashPoint, None]): class PrintDispatch(SequenceDispatch[HashPoint, None]):

View File

@ -1,13 +1,13 @@
import string import string
import unittest import unittest
from rainbowadn.atomic import Integer, Plain from rainbowadn.atomic import *
from rainbowadn.collection.comparison import PlainComparator, Replace from rainbowadn.collection.comparison import *
from rainbowadn.collection.trees.binary import AVL, ActiveBinaryTree from rainbowadn.collection.trees.binary import *
from rainbowadn.core import HashPoint, set_gather_linear from rainbowadn.core import *
from rainbowadn.encryption import Encrypted from rainbowadn.encryption import *
from rainbowadn.instrument import Counter from rainbowadn.instrument import *
from rainbowadn.testing.resolvers import default_resolver from rainbowadn.testing.resolvers import *
class TestEncryption(unittest.IsolatedAsyncioTestCase): class TestEncryption(unittest.IsolatedAsyncioTestCase):

View File

@ -3,17 +3,14 @@ import time
import unittest import unittest
from typing import Any from typing import Any
from rainbowadn.atomic import Integer, Plain from rainbowadn.atomic import *
from rainbowadn.chain import BlockChainFactory, ChainCollectionInterface from rainbowadn.chain import *
from rainbowadn.collection.comparison import PlainComparator, Replace from rainbowadn.collection.comparison import *
from rainbowadn.collection.pair import Pair, PairFactory from rainbowadn.collection.pair import *
from rainbowadn.collection.trees.binary import AVL, ActiveBinaryTree from rainbowadn.collection.trees.binary import *
from rainbowadn.core import ( from rainbowadn.core import *
HashPoint, RainbowFactory, assert_eq, assert_false, assert_true, set_gather_asyncio, from rainbowadn.testing.resolvers import *
set_gather_linear, from rainbowadn.wrisbt import *
)
from rainbowadn.testing.resolvers import default_resolver
from rainbowadn.wrisbt import WrisbtChainProtocol, WrisbtParametres, WrisbtRoot
class TestTrees(unittest.IsolatedAsyncioTestCase): class TestTrees(unittest.IsolatedAsyncioTestCase):
@ -79,10 +76,6 @@ class TestTrees(unittest.IsolatedAsyncioTestCase):
with self.subTest('check'): with self.subTest('check'):
set_gather_asyncio() set_gather_asyncio()
assert_true(await chain.verify()) assert_true(await chain.verify())
with self.subTest('measure height'):
reference = await chain.actual_state()
assert not reference.null()
print((await reference.resolve()).height)
async def test_avl(self): async def test_avl(self):
set_gather_linear() set_gather_linear()

View File

@ -2,11 +2,11 @@ import unittest
import nacl.signing import nacl.signing
from rainbowadn.chain import ReductionChainMetaFactory from rainbowadn.chain import *
from rainbowadn.core import HashPoint, assert_true, set_gather_asyncio, set_gather_linear from rainbowadn.core import *
from rainbowadn.nullability import NotNull from rainbowadn.nullability import *
from rainbowadn.testing.resolvers import default_resolver from rainbowadn.testing.resolvers import *
from rainbowadn.v13 import BankChain, CoinData, MINT_CONST, Subject, Transaction from rainbowadn.v13 import *
class TestV13(unittest.IsolatedAsyncioTestCase): class TestV13(unittest.IsolatedAsyncioTestCase):

View File

@ -1,2 +1,7 @@
from .thresholdprotocol import * __all__ = (
from .validreference import * 'ThresholdProtocol',
'ValidReference', 'ValidReferenceFactory',
)
from .thresholdprotocol import ThresholdProtocol
from .validreference import ValidReference, ValidReferenceFactory

View File

@ -1,5 +1,13 @@
from .algo import * __all__ = (
from .bankchain import * 'MINT_CONST',
from .signature import * 'BankChain',
from .subject import * 'BadSignature', 'Signature',
from .transaction import * 'Subject',
'CoinData', 'Coin', 'TransactionData', 'Transaction',
)
from .algo import MINT_CONST
from .bankchain import BankChain
from .signature import BadSignature, Signature
from .subject import Subject
from .transaction import Coin, CoinData, Transaction, TransactionData

View File

@ -20,7 +20,6 @@ class BankChain(Generic[BlockType]):
chain: ChainCollectionInterface[ chain: ChainCollectionInterface[
BlockType, BlockType,
NullableReference[Stack[Transaction]], NullableReference[Stack[Transaction]],
BankState,
] ]
): ):
assert isinstance(chain, ChainCollectionInterface) assert isinstance(chain, ChainCollectionInterface)

View File

@ -1,3 +1,9 @@
from .wrisbtchainprotocol import * __all__ = (
from .wrisbtparametres import * 'WrisbtChainProtocol',
from .wrisbtroot import * 'WrisbtParametres',
'WrisbtRoot', 'WrisbtRootFactory',
)
from .wrisbtchainprotocol import WrisbtChainProtocol
from .wrisbtparametres import WrisbtParametres
from .wrisbtroot import WrisbtRoot, WrisbtRootFactory

View File

@ -3,9 +3,7 @@ from typing import Generic, TypeVar
from rainbowadn.chain import * from rainbowadn.chain import *
from rainbowadn.core import * from rainbowadn.core import *
from .wrisbtindex import * from .wrisbtindex import *
from .wrisbtparametres import *
from .wrisbtprotocol import * from .wrisbtprotocol import *
from .wrisbtroot import *
__all__ = ('WrisbtChainProtocol',) __all__ = ('WrisbtChainProtocol',)
@ -15,8 +13,7 @@ TargetType = TypeVar('TargetType')
class WrisbtChainProtocol( class WrisbtChainProtocol(
BlockChainProtocol[ BlockChainProtocol[
TargetType, TargetType,
WrisbtIndex, WrisbtIndex
WrisbtRoot
], ],
Generic[TargetType] Generic[TargetType]
): ):
@ -35,10 +32,3 @@ class WrisbtChainProtocol(
WrisbtIndexFactory(keymin) WrisbtIndexFactory(keymin)
) )
self.total_factory = total_factory self.total_factory = total_factory
def actual_state_factory(self) -> RainbowFactory[WrisbtRoot]:
return WrisbtRootFactory(WrisbtParametres(self.keymin, HashPoint.HASH_LENGTH))
async def actual_state(self, state: WrisbtIndex) -> HashPoint[WrisbtRoot]:
assert isinstance(state, WrisbtIndex)
return state.total

View File

@ -8,15 +8,15 @@ from contextlib import ExitStack
from nacl.signing import SigningKey from nacl.signing import SigningKey
from plot import plot from plot import *
from rainbowadn.chain import ReductionChainMetaFactory from rainbowadn.chain import *
from rainbowadn.collection.linear import Stack from rainbowadn.collection.linear import *
from rainbowadn.collection.trees.binary import ActiveBinaryTree from rainbowadn.collection.trees.binary import *
from rainbowadn.core import ExtendableResolver, HashPoint, assert_true, set_gather_asyncio, set_gather_linear from rainbowadn.core import *
from rainbowadn.instrument import Concurrency, Counter, EntryExit, Instrumentation from rainbowadn.instrument import *
from rainbowadn.nullability import NotNull from rainbowadn.nullability import *
from rainbowadn.testing.resolvers import DelayedResolver, DictResolver from rainbowadn.testing.resolvers import *
from rainbowadn.v13 import BankChain, CoinData, MINT_CONST, Subject, Transaction from rainbowadn.v13 import *
def get_dr() -> ExtendableResolver: def get_dr() -> ExtendableResolver: