change import structure
This commit is contained in:
parent
a51967b238
commit
8bf8fcea32
2
plot.py
2
plot.py
@ -4,6 +4,8 @@ from pathlib import Path
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
__all__ = ('plot',)
|
||||
|
||||
|
||||
def plottable(log: list[tuple[float, int]]):
|
||||
if log:
|
||||
|
@ -1,3 +1,9 @@
|
||||
from .atomic import *
|
||||
from .integer import *
|
||||
from .plain import *
|
||||
__all__ = (
|
||||
'Atomic',
|
||||
'Integer',
|
||||
'Plain',
|
||||
)
|
||||
|
||||
from .atomic import Atomic
|
||||
from .integer import Integer
|
||||
from .plain import Plain
|
||||
|
@ -1,5 +1,13 @@
|
||||
from .blockchain import *
|
||||
from .blockchainprotocol import *
|
||||
from .chaincollectionfactory import *
|
||||
from .chaincollectioninterface import *
|
||||
from .reductionchainmetafactory import *
|
||||
__all__ = (
|
||||
'BlockChain', 'BlockChainFactory',
|
||||
'BlockChainProtocol',
|
||||
'ChainCollectionFactory',
|
||||
'ChainCollectionInterface',
|
||||
'ReductionChainMetaFactory',
|
||||
)
|
||||
|
||||
from .blockchain import BlockChain, BlockChainFactory
|
||||
from .blockchainprotocol import BlockChainProtocol
|
||||
from .chaincollectionfactory import ChainCollectionFactory
|
||||
from .chaincollectioninterface import ChainCollectionInterface
|
||||
from .reductionchainmetafactory import ReductionChainMetaFactory
|
||||
|
@ -11,7 +11,6 @@ __all__ = ('BlockChain', 'BlockChainFactory',)
|
||||
|
||||
HeaderType = TypeVar('HeaderType')
|
||||
StateType = TypeVar('StateType')
|
||||
ActualStateType = TypeVar('ActualStateType')
|
||||
|
||||
|
||||
class BlockChain(
|
||||
@ -20,10 +19,9 @@ class BlockChain(
|
||||
HeaderType,
|
||||
StateType
|
||||
],
|
||||
HeaderType,
|
||||
ActualStateType
|
||||
HeaderType
|
||||
],
|
||||
Generic[HeaderType, ActualStateType, StateType],
|
||||
Generic[HeaderType, StateType],
|
||||
):
|
||||
def __init__(
|
||||
self,
|
||||
@ -33,7 +31,7 @@ class BlockChain(
|
||||
StateType
|
||||
]
|
||||
],
|
||||
protocol: BlockChainProtocol[HeaderType, StateType, ActualStateType],
|
||||
protocol: BlockChainProtocol[HeaderType, StateType],
|
||||
):
|
||||
assert isinstance(reference, NullableReference)
|
||||
assert isinstance(protocol, BlockChainProtocol)
|
||||
@ -45,8 +43,7 @@ class BlockChain(
|
||||
HeaderType,
|
||||
StateType
|
||||
],
|
||||
HeaderType,
|
||||
ActualStateType
|
||||
HeaderType
|
||||
]:
|
||||
return BlockChainFactory(self.protocol)
|
||||
|
||||
@ -58,8 +55,7 @@ class BlockChain(
|
||||
HeaderType,
|
||||
StateType
|
||||
],
|
||||
HeaderType,
|
||||
ActualStateType
|
||||
HeaderType
|
||||
]:
|
||||
assert isinstance(header, HashPoint)
|
||||
return self.factory().from_reference(
|
||||
@ -107,8 +103,7 @@ class BlockChain(
|
||||
HeaderType,
|
||||
StateType
|
||||
],
|
||||
HeaderType,
|
||||
ActualStateType
|
||||
HeaderType
|
||||
]:
|
||||
assert not self.reference.null()
|
||||
block: Block[
|
||||
@ -123,7 +118,7 @@ class BlockChain(
|
||||
return True
|
||||
else:
|
||||
previous: ChainCollectionInterface[
|
||||
Block[HeaderType, StateType], HeaderType, ActualStateType
|
||||
Block[HeaderType, StateType], HeaderType
|
||||
] = await self.previous()
|
||||
assert isinstance(previous, ChainCollectionInterface)
|
||||
assert_trues(
|
||||
@ -161,26 +156,12 @@ class BlockChain(
|
||||
)
|
||||
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[
|
||||
Block[
|
||||
HeaderType,
|
||||
StateType
|
||||
],
|
||||
HeaderType,
|
||||
ActualStateType
|
||||
HeaderType
|
||||
]:
|
||||
return self
|
||||
|
||||
@ -191,19 +172,18 @@ class BlockChainFactory(
|
||||
HeaderType,
|
||||
StateType
|
||||
],
|
||||
HeaderType,
|
||||
ActualStateType
|
||||
HeaderType
|
||||
],
|
||||
Generic[HeaderType, ActualStateType, StateType]
|
||||
Generic[HeaderType, StateType]
|
||||
):
|
||||
def __init__(
|
||||
self,
|
||||
protocol: BlockChainProtocol[HeaderType, StateType, ActualStateType],
|
||||
protocol: BlockChainProtocol[HeaderType, StateType],
|
||||
):
|
||||
assert isinstance(protocol, BlockChainProtocol)
|
||||
self.protocol = protocol
|
||||
|
||||
def empty(self) -> BlockChain[HeaderType, ActualStateType, StateType]:
|
||||
def empty(self) -> BlockChain[HeaderType, StateType]:
|
||||
return BlockChain(
|
||||
NullableReference(
|
||||
Null(),
|
||||
@ -224,7 +204,7 @@ class BlockChainFactory(
|
||||
],
|
||||
]
|
||||
) -> BlockChain[
|
||||
HeaderType, ActualStateType, StateType
|
||||
HeaderType, StateType
|
||||
]:
|
||||
assert isinstance(reference, NullableReference)
|
||||
return BlockChain(
|
||||
|
@ -7,11 +7,10 @@ __all__ = ('BlockChainProtocol',)
|
||||
|
||||
HeaderType = TypeVar('HeaderType')
|
||||
StateType = TypeVar('StateType')
|
||||
ActualStateType = TypeVar('ActualStateType')
|
||||
|
||||
|
||||
class BlockChainProtocol(
|
||||
Generic[HeaderType, StateType, ActualStateType],
|
||||
Generic[HeaderType, StateType],
|
||||
):
|
||||
def __init__(
|
||||
self,
|
||||
@ -26,14 +25,5 @@ class BlockChainProtocol(
|
||||
self.header_factory = header_factory
|
||||
self.state_factory = state_factory
|
||||
|
||||
def actual_state_factory(self) -> RainbowFactory[ActualStateType]:
|
||||
raise NotImplementedError
|
||||
|
||||
async def actual_state(
|
||||
self,
|
||||
state: StateType
|
||||
) -> HashPoint[ActualStateType]:
|
||||
raise NotImplementedError
|
||||
|
||||
def loose(self) -> 'BlockChainProtocol[HeaderType, StateType, ActualStateType]':
|
||||
def loose(self) -> 'BlockChainProtocol[HeaderType, StateType]':
|
||||
return self
|
||||
|
@ -8,14 +8,13 @@ __all__ = ('BlockCollectionInterface',)
|
||||
|
||||
BlockType = TypeVar('BlockType')
|
||||
HeaderType = TypeVar('HeaderType')
|
||||
ActualStateType = TypeVar('ActualStateType')
|
||||
|
||||
|
||||
class BlockCollectionInterface(
|
||||
CollectionInterface[
|
||||
BlockType
|
||||
],
|
||||
Generic[BlockType, HeaderType, ActualStateType]
|
||||
Generic[BlockType, HeaderType]
|
||||
):
|
||||
def __init__(
|
||||
self,
|
||||
@ -44,20 +43,8 @@ class BlockCollectionInterface(
|
||||
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(
|
||||
self,
|
||||
header: HashPoint[HeaderType]
|
||||
) -> 'BlockCollectionInterface[BlockType, HeaderType, ActualStateType]':
|
||||
) -> 'BlockCollectionInterface[BlockType, HeaderType]':
|
||||
raise NotImplementedError
|
||||
|
@ -7,18 +7,17 @@ __all__ = ('ChainCollectionFactory',)
|
||||
|
||||
BlockType = TypeVar('BlockType')
|
||||
HeaderType = TypeVar('HeaderType')
|
||||
ActualStateType = TypeVar('ActualStateType')
|
||||
|
||||
|
||||
class ChainCollectionFactory(Generic[BlockType, HeaderType, ActualStateType]):
|
||||
def empty(self) -> ChainCollectionInterface[BlockType, HeaderType, ActualStateType]:
|
||||
class ChainCollectionFactory(Generic[BlockType, HeaderType]):
|
||||
def empty(self) -> ChainCollectionInterface[BlockType, HeaderType]:
|
||||
raise NotImplementedError
|
||||
|
||||
def from_reference(
|
||||
self,
|
||||
reference: NullableReference[BlockType]
|
||||
) -> ChainCollectionInterface[BlockType, HeaderType, ActualStateType]:
|
||||
) -> ChainCollectionInterface[BlockType, HeaderType]:
|
||||
raise NotImplementedError
|
||||
|
||||
def loose(self) -> 'ChainCollectionFactory[BlockType, HeaderType, ActualStateType]':
|
||||
def loose(self) -> 'ChainCollectionFactory[BlockType, HeaderType]':
|
||||
return self
|
||||
|
@ -8,22 +8,20 @@ __all__ = ('ChainCollectionInterface',)
|
||||
|
||||
BlockType = TypeVar('BlockType')
|
||||
HeaderType = TypeVar('HeaderType')
|
||||
ActualStateType = TypeVar('ActualStateType')
|
||||
|
||||
|
||||
class ChainCollectionInterface(
|
||||
BlockCollectionInterface[
|
||||
BlockType,
|
||||
HeaderType,
|
||||
ActualStateType
|
||||
HeaderType
|
||||
],
|
||||
Generic[BlockType, HeaderType, ActualStateType],
|
||||
Generic[BlockType, HeaderType],
|
||||
abc.ABC
|
||||
):
|
||||
async def add(
|
||||
self,
|
||||
header: HashPoint[HeaderType]
|
||||
) -> 'ChainCollectionInterface[BlockType, HeaderType, ActualStateType]':
|
||||
) -> 'ChainCollectionInterface[BlockType, HeaderType]':
|
||||
raise NotImplementedError
|
||||
|
||||
async def verify(self) -> bool:
|
||||
|
@ -1,5 +1,13 @@
|
||||
from .activestageprotocol import *
|
||||
from .activestagestateprotocol import *
|
||||
from .derived import *
|
||||
from .derivedstage import *
|
||||
from .derivedstate import *
|
||||
__all__ = (
|
||||
'ActiveStageProtocol',
|
||||
'ActiveStageStateProtocol',
|
||||
'Derived',
|
||||
'DerivedStage',
|
||||
'DerivedState',
|
||||
)
|
||||
|
||||
from .activestageprotocol import ActiveStageProtocol
|
||||
from .activestagestateprotocol import ActiveStageStateProtocol
|
||||
from .derived import Derived
|
||||
from .derivedstage import DerivedStage
|
||||
from .derivedstate import DerivedState
|
||||
|
@ -1,6 +1,15 @@
|
||||
from .abstractreductionchainmetafactory import *
|
||||
from .reduced import *
|
||||
from .reducible import *
|
||||
from .reductionchainprotocol import *
|
||||
from .reductionprotocol import *
|
||||
from .reductionresult import *
|
||||
__all__ = (
|
||||
'AbstractReductionChainMetaFactory',
|
||||
'Reduced',
|
||||
'Reducible', 'ReducibleFactory',
|
||||
'ReductionChainProtocol',
|
||||
'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
|
||||
|
@ -20,6 +20,6 @@ class AbstractReductionChainMetaFactory(
|
||||
accumulator_factory: RainbowFactory[AccumulatorType],
|
||||
protocol: ReductionProtocol[ReductorType, AccumulatorType],
|
||||
) -> ChainCollectionFactory[
|
||||
BlockType, ReductorType, AccumulatorType
|
||||
BlockType, ReductorType
|
||||
]:
|
||||
raise NotImplementedError
|
||||
|
@ -17,8 +17,7 @@ AccumulatorType = TypeVar('AccumulatorType')
|
||||
class ReductionChainProtocol(
|
||||
BlockChainProtocol[
|
||||
ReductorType,
|
||||
StateStage[ReductorType, AccumulatorType, Reducible[ReductorType, AccumulatorType]],
|
||||
AccumulatorType
|
||||
StateStage[ReductorType, AccumulatorType, Reducible[ReductorType, AccumulatorType]]
|
||||
]
|
||||
):
|
||||
def __init__(
|
||||
@ -60,17 +59,3 @@ class ReductionChainProtocol(
|
||||
|
||||
self.reductor_factory = reductor_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
|
||||
|
@ -34,8 +34,7 @@ class ReductionChainMetaFactory(
|
||||
ReductorType,
|
||||
StateStage[ReductorType, AccumulatorType, Reducible[ReductorType, AccumulatorType]]
|
||||
],
|
||||
ReductorType,
|
||||
AccumulatorType
|
||||
ReductorType
|
||||
]:
|
||||
assert isinstance(reductor_factory, RainbowFactory)
|
||||
assert isinstance(accumulator_factory, RainbowFactory)
|
||||
|
@ -1,3 +1,9 @@
|
||||
__all__ = (
|
||||
'StageProtocol',
|
||||
'StageStage', 'StageStageFactory', 'StateStage', 'StateStageFactory',
|
||||
'StageStateProtocol',
|
||||
)
|
||||
|
||||
from .stageprotocol import StageProtocol
|
||||
from .stagestate import *
|
||||
from .stagestate import StageStage, StageStageFactory, StateStage, StateStageFactory
|
||||
from .stagestateprotocol import StageStateProtocol
|
||||
|
@ -5,10 +5,7 @@ from rainbowadn.nullability import *
|
||||
from .stageprotocol import *
|
||||
|
||||
__all__ = (
|
||||
'StageStage',
|
||||
'StageStageFactory',
|
||||
'StateStage',
|
||||
'StateStageFactory',
|
||||
'StageStage', 'StageStageFactory', 'StateStage', 'StateStageFactory',
|
||||
)
|
||||
|
||||
HeaderType = TypeVar('HeaderType')
|
||||
|
@ -1,3 +1,9 @@
|
||||
__all__ = (
|
||||
'ActiveStateProtocol',
|
||||
'MetaReductionStateProtocol',
|
||||
'StateProtocol',
|
||||
)
|
||||
|
||||
from .activestateprotocol import ActiveStateProtocol
|
||||
from .metareductionstateprotocol import MetaReductionStateProtocol
|
||||
from .stateprotocol import StateProtocol
|
||||
|
@ -1,4 +1,11 @@
|
||||
from .comparator import *
|
||||
from .hashcomparator import *
|
||||
from .keyedcomparator import *
|
||||
from .plaincomparator import *
|
||||
__all__ = (
|
||||
'Comparison', 'Left', 'Right', 'Equal', 'Replace', 'Fail', 'Duplicate', 'Comparator',
|
||||
'HashComparator',
|
||||
'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
|
||||
|
@ -4,14 +4,7 @@ from typing import Generic, TypeVar
|
||||
from rainbowadn.core import *
|
||||
|
||||
__all__ = (
|
||||
'Comparison',
|
||||
'Left',
|
||||
'Right',
|
||||
'Equal',
|
||||
'Replace',
|
||||
'Fail',
|
||||
'Duplicate',
|
||||
'Comparator',
|
||||
'Comparison', 'Left', 'Right', 'Equal', 'Replace', 'Fail', 'Duplicate', 'Comparator',
|
||||
)
|
||||
|
||||
|
||||
|
@ -1,3 +1,9 @@
|
||||
from .array import *
|
||||
from .stack import *
|
||||
from .treelist import *
|
||||
__all__ = (
|
||||
'Array', 'ArrayFactory',
|
||||
'Stack', 'StackFactory',
|
||||
'TLRoot', 'TLRootFactory', 'TLRParametres',
|
||||
)
|
||||
|
||||
from .array import Array, ArrayFactory
|
||||
from .stack import Stack, StackFactory
|
||||
from .treelist import TLRParametres, TLRoot, TLRootFactory
|
||||
|
@ -1,2 +1,7 @@
|
||||
from .tlroot import *
|
||||
__all__ = (
|
||||
'TLRoot', 'TLRootFactory',
|
||||
'TLRParametres',
|
||||
)
|
||||
|
||||
from .tlroot import TLRoot, TLRootFactory
|
||||
from .tlrparametres import TLRParametres
|
||||
|
@ -1,3 +1,9 @@
|
||||
from .activebinarytree import *
|
||||
from .avl import *
|
||||
from .binarytree import *
|
||||
__all__ = (
|
||||
'ActiveBinaryTree',
|
||||
'AVL',
|
||||
'BinaryTree', 'BinaryTreeFactory',
|
||||
)
|
||||
|
||||
from .activebinarytree import ActiveBinaryTree
|
||||
from .avl import AVL
|
||||
from .binarytree import BinaryTree, BinaryTreeFactory
|
||||
|
@ -1,3 +1,9 @@
|
||||
from .binaryaction import *
|
||||
from .stdactions import *
|
||||
from .symmetric import *
|
||||
__all__ = (
|
||||
'BinaryAction',
|
||||
'AddAction', 'RemoveAction', 'ContainsAction',
|
||||
'Symmetric', 'InnerOuter', 'OuterInner',
|
||||
)
|
||||
|
||||
from .binaryaction import BinaryAction
|
||||
from .stdactions import AddAction, ContainsAction, RemoveAction
|
||||
from .symmetric import InnerOuter, OuterInner, Symmetric
|
||||
|
@ -1,3 +1,12 @@
|
||||
__all__ = (
|
||||
'BalancedCreation',
|
||||
'BinaryBalancing',
|
||||
'BinaryCreation',
|
||||
'BinaryProtocolized',
|
||||
'BinarySplit',
|
||||
'ProtocolizedBinarySplit',
|
||||
)
|
||||
|
||||
from .balancedcreation import BalancedCreation
|
||||
from .binarybalancing import BinaryBalancing
|
||||
from .binarycreation import BinaryCreation
|
||||
|
@ -1,16 +1,35 @@
|
||||
from .asserts import *
|
||||
from .extendableresolver import *
|
||||
from .gather import *
|
||||
from .hash_point_format import *
|
||||
from .hashpoint import *
|
||||
from .hashresolver import *
|
||||
from .localmetaorigin import *
|
||||
from .localorigin import *
|
||||
from .mentionable import *
|
||||
from .metaorigin import *
|
||||
from .origin import *
|
||||
from .rainbow_factory import *
|
||||
from .recursivementionable import *
|
||||
from .resolvermetaorigin import *
|
||||
from .resolverorigin import *
|
||||
from .static import *
|
||||
__all__ = (
|
||||
'assert_true', 'assert_trues', 'assert_false', 'assert_none', 'assert_none_strict', 'assert_eq',
|
||||
'ExtendableResolver',
|
||||
'gather', 'asum', 'alist', 'set_gather_asyncio', 'set_gather_linear',
|
||||
'hash_point_format', 'tabulate',
|
||||
'HashPoint',
|
||||
'HashResolver',
|
||||
'LocalMetaOrigin',
|
||||
'LocalOrigin',
|
||||
'Mentionable',
|
||||
'MetaOrigin',
|
||||
'Origin',
|
||||
'RainbowFactory',
|
||||
'RecursiveMentionable',
|
||||
'ResolverMetaOrigin',
|
||||
'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
|
||||
|
@ -1 +1,5 @@
|
||||
from .encrypted import *
|
||||
__all__ = (
|
||||
'Encrypted', 'EncryptedFactory',
|
||||
)
|
||||
|
||||
from .encrypted import Encrypted, EncryptedFactory
|
||||
|
@ -5,7 +5,7 @@ from nacl.secret import SecretBox
|
||||
|
||||
from rainbowadn.core import *
|
||||
|
||||
__all__ = ('Encrypted', 'EncryptedFactory')
|
||||
__all__ = ('Encrypted', 'EncryptedFactory',)
|
||||
|
||||
EncryptedType = TypeVar('EncryptedType')
|
||||
|
||||
|
@ -1,5 +1,11 @@
|
||||
"""a bridge between old .chain and new .flow
|
||||
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
|
||||
|
@ -6,11 +6,12 @@ from rainbowadn.collection.pair import *
|
||||
from rainbowadn.core import *
|
||||
from rainbowadn.flow.core import *
|
||||
from rainbowadn.flow.sequence import *
|
||||
from rainbowadn.flow.verification.core import *
|
||||
from rainbowadn.flow.verification.stages import *
|
||||
from rainbowadn.nullability import *
|
||||
from ._stackbridge import *
|
||||
|
||||
__all__ = ('StageBridgeVP', 'StageBridgeM',)
|
||||
__all__ = ('StageBridgeVP', 'StageBridgeM', 'stage_bridge',)
|
||||
|
||||
BaseT = TypeVar('BaseT')
|
||||
StageT = TypeVar('StageT')
|
||||
@ -69,3 +70,34 @@ class StageBridgeM(
|
||||
stack_bridge: Reducer[SequenceDispatcher[HashPoint[StageT], bool], bool] = StackBridge(stages_stack).loose()
|
||||
assert isinstance(stack_bridge, Reducer)
|
||||
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
|
||||
|
94
rainbowadn/flow/bridge/_statebridge.py
Normal file
94
rainbowadn/flow/bridge/_statebridge.py
Normal 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
|
@ -1,5 +1,13 @@
|
||||
from ._mapper import *
|
||||
from ._mapreduce import *
|
||||
from ._mapreducer import *
|
||||
from ._reduce import *
|
||||
from ._reducer import *
|
||||
__all__ = (
|
||||
'Mapper',
|
||||
'MapReduce',
|
||||
'MapReducer',
|
||||
'Reduce',
|
||||
'Reducer',
|
||||
)
|
||||
|
||||
from ._mapper import Mapper
|
||||
from ._mapreduce import MapReduce
|
||||
from ._mapreducer import MapReducer
|
||||
from ._reduce import Reduce
|
||||
from ._reducer import Reducer
|
||||
|
@ -1,3 +1,9 @@
|
||||
from ._dispatchmapper import *
|
||||
from ._sequencedispatch import *
|
||||
from ._sequencedispatcher import *
|
||||
__all__ = (
|
||||
'DispatchMapper',
|
||||
'SequenceDispatch',
|
||||
'SequenceDispatcher', 'FirstDispatcher', 'LastDispatcher', 'PairDispatcher',
|
||||
)
|
||||
|
||||
from ._dispatchmapper import DispatchMapper
|
||||
from ._sequencedispatch import SequenceDispatch
|
||||
from ._sequencedispatcher import FirstDispatcher, LastDispatcher, PairDispatcher, SequenceDispatcher
|
||||
|
@ -1,2 +1,7 @@
|
||||
from ._stackedreduce import *
|
||||
from ._stackedreducer import *
|
||||
__all__ = (
|
||||
'StackedReduce',
|
||||
'StackedReducer',
|
||||
)
|
||||
|
||||
from ._stackedreduce import StackedReduce
|
||||
from ._stackedreducer import StackedReducer
|
||||
|
@ -1,4 +1,11 @@
|
||||
from ._mapperverification import *
|
||||
from ._reduceverification import *
|
||||
from ._verification import *
|
||||
from ._verifyreduce import *
|
||||
__all__ = (
|
||||
'MapperVerification',
|
||||
'ReduceVerification',
|
||||
'Verification',
|
||||
'VerifyReduce',
|
||||
)
|
||||
|
||||
from ._mapperverification import MapperVerification
|
||||
from ._reduceverification import ReduceVerification
|
||||
from ._verification import Verification
|
||||
from ._verifyreduce import VerifyReduce
|
||||
|
@ -1,2 +1,7 @@
|
||||
from ._stageverification import *
|
||||
from ._stageverificationprotocol import *
|
||||
__all__ = (
|
||||
'StageVerification',
|
||||
'StageVerificationProtocol',
|
||||
)
|
||||
|
||||
from ._stageverification import StageVerification
|
||||
from ._stageverificationprotocol import StageVerificationProtocol
|
||||
|
@ -55,3 +55,6 @@ class StateVerification(
|
||||
assert isinstance(element, tuple)
|
||||
assert_true(await self.verification.map(await self._tuple(element)))
|
||||
return True
|
||||
|
||||
def loose(self) -> Verification[tuple[Nullable[Chain], Chain]]:
|
||||
return self
|
||||
|
@ -1,4 +1,11 @@
|
||||
from .concurrency import *
|
||||
from .counter import *
|
||||
from .entryexit import *
|
||||
from .instrumentation import *
|
||||
__all__ = (
|
||||
'Concurrency',
|
||||
'Counter',
|
||||
'EntryExit',
|
||||
'Instrumentation',
|
||||
)
|
||||
|
||||
from .concurrency import Concurrency
|
||||
from .counter import Counter
|
||||
from .entryexit import EntryExit
|
||||
from .instrumentation import Instrumentation
|
||||
|
@ -1,4 +1,11 @@
|
||||
from .notnull import *
|
||||
from .null import *
|
||||
from .nullable import *
|
||||
from .nullablereference import *
|
||||
__all__ = (
|
||||
'NotNull',
|
||||
'Null',
|
||||
'Nullable',
|
||||
'NullableReference', 'NullableReferenceFactory',
|
||||
)
|
||||
|
||||
from .notnull import NotNull
|
||||
from .null import Null
|
||||
from .nullable import Nullable
|
||||
from .nullablereference import NullableReference, NullableReferenceFactory
|
||||
|
@ -1,5 +1,13 @@
|
||||
from .cachingresolver import *
|
||||
from .defaultresolver import *
|
||||
from .delayedresolver import *
|
||||
from .dictresolver import *
|
||||
from .failresolver import *
|
||||
__all__ = (
|
||||
'CachingResolver',
|
||||
'default_resolver',
|
||||
'DelayedResolver',
|
||||
'DictResolver',
|
||||
'FailResolver',
|
||||
)
|
||||
|
||||
from .cachingresolver import CachingResolver
|
||||
from .defaultresolver import default_resolver
|
||||
from .delayedresolver import DelayedResolver
|
||||
from .dictresolver import DictResolver
|
||||
from .failresolver import FailResolver
|
||||
|
@ -1,5 +1,7 @@
|
||||
from rainbowadn.core import *
|
||||
|
||||
__all__ = ('FailResolver',)
|
||||
|
||||
|
||||
class FailResolver(HashResolver):
|
||||
async def resolve(self, point: bytes) -> tuple[bytes, 'HashResolver']:
|
||||
|
@ -1,13 +1,13 @@
|
||||
import unittest
|
||||
|
||||
from rainbowadn.atomic import Plain
|
||||
from rainbowadn.collection.linear import Stack
|
||||
from rainbowadn.core import HashPoint, assert_none_strict, hash_point_format
|
||||
from rainbowadn.flow.bridge import StackBridge
|
||||
from rainbowadn.flow.core import MapReduce, Reduce
|
||||
from rainbowadn.flow.sequence import DispatchMapper, SequenceDispatch
|
||||
from rainbowadn.flow.stacked import StackedReducer
|
||||
from rainbowadn.nullability import Nullable
|
||||
from rainbowadn.atomic import *
|
||||
from rainbowadn.collection.linear import *
|
||||
from rainbowadn.core import *
|
||||
from rainbowadn.flow.bridge import *
|
||||
from rainbowadn.flow.core import *
|
||||
from rainbowadn.flow.sequence import *
|
||||
from rainbowadn.flow.stacked import *
|
||||
from rainbowadn.nullability import *
|
||||
|
||||
|
||||
class PrintDispatch(SequenceDispatch[HashPoint, None]):
|
||||
|
@ -1,13 +1,13 @@
|
||||
import string
|
||||
import unittest
|
||||
|
||||
from rainbowadn.atomic import Integer, Plain
|
||||
from rainbowadn.collection.comparison import PlainComparator, Replace
|
||||
from rainbowadn.collection.trees.binary import AVL, ActiveBinaryTree
|
||||
from rainbowadn.core import HashPoint, set_gather_linear
|
||||
from rainbowadn.encryption import Encrypted
|
||||
from rainbowadn.instrument import Counter
|
||||
from rainbowadn.testing.resolvers import default_resolver
|
||||
from rainbowadn.atomic import *
|
||||
from rainbowadn.collection.comparison import *
|
||||
from rainbowadn.collection.trees.binary import *
|
||||
from rainbowadn.core import *
|
||||
from rainbowadn.encryption import *
|
||||
from rainbowadn.instrument import *
|
||||
from rainbowadn.testing.resolvers import *
|
||||
|
||||
|
||||
class TestEncryption(unittest.IsolatedAsyncioTestCase):
|
||||
|
@ -3,17 +3,14 @@ import time
|
||||
import unittest
|
||||
from typing import Any
|
||||
|
||||
from rainbowadn.atomic import Integer, Plain
|
||||
from rainbowadn.chain import BlockChainFactory, ChainCollectionInterface
|
||||
from rainbowadn.collection.comparison import PlainComparator, Replace
|
||||
from rainbowadn.collection.pair import Pair, PairFactory
|
||||
from rainbowadn.collection.trees.binary import AVL, ActiveBinaryTree
|
||||
from rainbowadn.core import (
|
||||
HashPoint, RainbowFactory, assert_eq, assert_false, assert_true, set_gather_asyncio,
|
||||
set_gather_linear,
|
||||
)
|
||||
from rainbowadn.testing.resolvers import default_resolver
|
||||
from rainbowadn.wrisbt import WrisbtChainProtocol, WrisbtParametres, WrisbtRoot
|
||||
from rainbowadn.atomic import *
|
||||
from rainbowadn.chain import *
|
||||
from rainbowadn.collection.comparison import *
|
||||
from rainbowadn.collection.pair import *
|
||||
from rainbowadn.collection.trees.binary import *
|
||||
from rainbowadn.core import *
|
||||
from rainbowadn.testing.resolvers import *
|
||||
from rainbowadn.wrisbt import *
|
||||
|
||||
|
||||
class TestTrees(unittest.IsolatedAsyncioTestCase):
|
||||
@ -79,10 +76,6 @@ class TestTrees(unittest.IsolatedAsyncioTestCase):
|
||||
with self.subTest('check'):
|
||||
set_gather_asyncio()
|
||||
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):
|
||||
set_gather_linear()
|
||||
|
@ -2,11 +2,11 @@ import unittest
|
||||
|
||||
import nacl.signing
|
||||
|
||||
from rainbowadn.chain import ReductionChainMetaFactory
|
||||
from rainbowadn.core import HashPoint, assert_true, set_gather_asyncio, set_gather_linear
|
||||
from rainbowadn.nullability import NotNull
|
||||
from rainbowadn.testing.resolvers import default_resolver
|
||||
from rainbowadn.v13 import BankChain, CoinData, MINT_CONST, Subject, Transaction
|
||||
from rainbowadn.chain import *
|
||||
from rainbowadn.core import *
|
||||
from rainbowadn.nullability import *
|
||||
from rainbowadn.testing.resolvers import *
|
||||
from rainbowadn.v13 import *
|
||||
|
||||
|
||||
class TestV13(unittest.IsolatedAsyncioTestCase):
|
||||
|
@ -1,2 +1,7 @@
|
||||
from .thresholdprotocol import *
|
||||
from .validreference import *
|
||||
__all__ = (
|
||||
'ThresholdProtocol',
|
||||
'ValidReference', 'ValidReferenceFactory',
|
||||
)
|
||||
|
||||
from .thresholdprotocol import ThresholdProtocol
|
||||
from .validreference import ValidReference, ValidReferenceFactory
|
||||
|
@ -1,5 +1,13 @@
|
||||
from .algo import *
|
||||
from .bankchain import *
|
||||
from .signature import *
|
||||
from .subject import *
|
||||
from .transaction import *
|
||||
__all__ = (
|
||||
'MINT_CONST',
|
||||
'BankChain',
|
||||
'BadSignature', 'Signature',
|
||||
'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
|
||||
|
@ -20,7 +20,6 @@ class BankChain(Generic[BlockType]):
|
||||
chain: ChainCollectionInterface[
|
||||
BlockType,
|
||||
NullableReference[Stack[Transaction]],
|
||||
BankState,
|
||||
]
|
||||
):
|
||||
assert isinstance(chain, ChainCollectionInterface)
|
||||
|
@ -1,3 +1,9 @@
|
||||
from .wrisbtchainprotocol import *
|
||||
from .wrisbtparametres import *
|
||||
from .wrisbtroot import *
|
||||
__all__ = (
|
||||
'WrisbtChainProtocol',
|
||||
'WrisbtParametres',
|
||||
'WrisbtRoot', 'WrisbtRootFactory',
|
||||
)
|
||||
|
||||
from .wrisbtchainprotocol import WrisbtChainProtocol
|
||||
from .wrisbtparametres import WrisbtParametres
|
||||
from .wrisbtroot import WrisbtRoot, WrisbtRootFactory
|
||||
|
@ -3,9 +3,7 @@ from typing import Generic, TypeVar
|
||||
from rainbowadn.chain import *
|
||||
from rainbowadn.core import *
|
||||
from .wrisbtindex import *
|
||||
from .wrisbtparametres import *
|
||||
from .wrisbtprotocol import *
|
||||
from .wrisbtroot import *
|
||||
|
||||
__all__ = ('WrisbtChainProtocol',)
|
||||
|
||||
@ -15,8 +13,7 @@ TargetType = TypeVar('TargetType')
|
||||
class WrisbtChainProtocol(
|
||||
BlockChainProtocol[
|
||||
TargetType,
|
||||
WrisbtIndex,
|
||||
WrisbtRoot
|
||||
WrisbtIndex
|
||||
],
|
||||
Generic[TargetType]
|
||||
):
|
||||
@ -35,10 +32,3 @@ class WrisbtChainProtocol(
|
||||
WrisbtIndexFactory(keymin)
|
||||
)
|
||||
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
|
||||
|
18
trace.py
18
trace.py
@ -8,15 +8,15 @@ from contextlib import ExitStack
|
||||
|
||||
from nacl.signing import SigningKey
|
||||
|
||||
from plot import plot
|
||||
from rainbowadn.chain import ReductionChainMetaFactory
|
||||
from rainbowadn.collection.linear import Stack
|
||||
from rainbowadn.collection.trees.binary import ActiveBinaryTree
|
||||
from rainbowadn.core import ExtendableResolver, HashPoint, assert_true, set_gather_asyncio, set_gather_linear
|
||||
from rainbowadn.instrument import Concurrency, Counter, EntryExit, Instrumentation
|
||||
from rainbowadn.nullability import NotNull
|
||||
from rainbowadn.testing.resolvers import DelayedResolver, DictResolver
|
||||
from rainbowadn.v13 import BankChain, CoinData, MINT_CONST, Subject, Transaction
|
||||
from plot import *
|
||||
from rainbowadn.chain import *
|
||||
from rainbowadn.collection.linear import *
|
||||
from rainbowadn.collection.trees.binary import *
|
||||
from rainbowadn.core import *
|
||||
from rainbowadn.instrument import *
|
||||
from rainbowadn.nullability import *
|
||||
from rainbowadn.testing.resolvers import *
|
||||
from rainbowadn.v13 import *
|
||||
|
||||
|
||||
def get_dr() -> ExtendableResolver:
|
||||
|
Loading…
Reference in New Issue
Block a user