origin protocol

This commit is contained in:
AF 2022-05-19 11:03:16 +03:00
parent 3d3facc10a
commit 899415f580
60 changed files with 537 additions and 465 deletions

61
main.py
View File

@ -10,7 +10,6 @@ from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface
from rainbowadn.chain.reduction.reductionchainmetafactory import ReductionChainMetaFactory from rainbowadn.chain.reduction.reductionchainmetafactory import ReductionChainMetaFactory
from rainbowadn.data.atomic.integer import Integer from rainbowadn.data.atomic.integer import Integer
from rainbowadn.data.atomic.plain import Plain from rainbowadn.data.atomic.plain import Plain
from rainbowadn.data.collection.array.array import Array
from rainbowadn.data.collection.trees.binary.activebinarytree import ActiveBinaryTree from rainbowadn.data.collection.trees.binary.activebinarytree import ActiveBinaryTree
from rainbowadn.data.collection.trees.binary.avl import AVLBTBP from rainbowadn.data.collection.trees.binary.avl import AVLBTBP
from rainbowadn.data.collection.trees.comparison.comparator import Replace from rainbowadn.data.collection.trees.comparison.comparator import Replace
@ -20,6 +19,7 @@ from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.hashing.nullability.notnull import NotNull
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolvermetaorigin import ResolverMetaOrigin
from rainbowadn.v13.algo import MINT_CONST from rainbowadn.v13.algo import MINT_CONST
from rainbowadn.v13.bankchain import BankChain from rainbowadn.v13.bankchain import BankChain
from rainbowadn.v13.subject import Subject from rainbowadn.v13.subject import Subject
@ -33,7 +33,7 @@ class DumbResolver(HashResolver):
def __init__(self): def __init__(self):
self.table: MutableMapping[bytes, bytes] = OrderedDict() self.table: MutableMapping[bytes, bytes] = OrderedDict()
def _resolve(self, point: bytes) -> bytes: def resolve_bytes(self, point: bytes) -> bytes:
assert isinstance(point, bytes) assert isinstance(point, bytes)
return self.table[point] return self.table[point]
@ -41,26 +41,25 @@ class DumbResolver(HashResolver):
assert isinstance(hash_point, HashPoint) assert isinstance(hash_point, HashPoint)
if hash_point.point in self.table: if hash_point.point in self.table:
pass pass
elif isinstance(hash_point.value, NotNull): else:
value: HashMentionable = hash_point.value.value value: HashMentionable = hash_point.resolve()
assert isinstance(value, HashMentionable)
self.table[hash_point.point] = HashPoint.bytes_of_mentioned(value) self.table[hash_point.point] = HashPoint.bytes_of_mentioned(value)
if isinstance(value, RecursiveMentionable): if isinstance(value, RecursiveMentionable):
for hash_point in value.points(): for hash_point in value.points():
self.save(hash_point) self.save(hash_point)
else:
raise TypeError
def main0(): def main0():
dr = DumbResolver() dr = DumbResolver()
bank = BankChain.empty(ReductionChainMetaFactory(), dr) bank = BankChain.empty(ReductionChainMetaFactory())
key_0 = nacl.signing.SigningKey.generate() key_0 = nacl.signing.SigningKey.generate()
transaction_0 = Transaction.make( transaction_0 = Transaction.make(
[], [],
[CoinData.of(Subject(key_0.verify_key), 1_000_000)], [CoinData.of(Subject(key_0.verify_key), 1_000_000)],
[] []
) )
coin_0, coin_1 = transaction_0.coins(dr, MINT_CONST, NotNull(HashPoint.of(Subject(key_0.verify_key)))) coin_0, coin_1 = transaction_0.coins(MINT_CONST, NotNull(HashPoint.of(Subject(key_0.verify_key))))
bank = bank.adds( bank = bank.adds(
[ [
transaction_0, transaction_0,
@ -77,7 +76,9 @@ def main0():
print(bank) print(bank)
print(bank.verify()) print(bank.verify())
dr.save(HashPoint.of(bank.reference)) dr.save(HashPoint.of(bank.reference))
bank = BankChain.from_reference(ReductionChainMetaFactory(), dr.resolve(HashPoint.of(bank.reference).loose()), dr) bank = BankChain.from_reference(
ReductionChainMetaFactory(), ResolverMetaOrigin(dr).migrate(HashPoint.of(bank.reference)).resolve()
)
print(bank) print(bank)
print(bank.verify()) print(bank.verify())
# for key, value in dr.table.items(): # for key, value in dr.table.items():
@ -87,50 +88,58 @@ def main0():
def main1(): def main1():
stoptime = time.process_time() stoptime = time.process_time()
def measure(message: str): def measure(message: str) -> float:
nonlocal stoptime nonlocal stoptime
now = time.process_time() now = time.process_time()
print(message, now - stoptime) delta = now - stoptime
print(message, delta)
stoptime = now stoptime = now
return delta
dr = DumbResolver() dr = DumbResolver()
btree = WrisbtRoot.empty(WrisbtParametres(1, 5)) btree = WrisbtRoot.empty(WrisbtParametres(1, 5))
n = 10000
measure('init') measure('init')
for _ in range(10000): for _ in range(n):
key = os.urandom(5) key = os.urandom(5)
assert not btree.contains(dr, key) assert not btree.contains(key)
btree = btree.add(dr, key) btree = btree.add(key)
assert btree.contains(dr, key) assert btree.contains(key)
measure('add') measure('add')
dr.save(HashPoint.of(btree)) dr.save(HashPoint.of(btree))
measure('save') measure('save')
btree = dr.resolve(HashPoint.of(btree).loose()) btree = ResolverMetaOrigin(dr).migrate(HashPoint.of(btree)).resolve()
assert len(btree.keys()) == n
print(btree.height) print(btree.height)
measure('resolve') measure('resolve and iterate')
for _ in range(n):
key = os.urandom(5)
assert not btree.contains(key)
btree = btree.add(key)
assert btree.contains(key)
measure('resolve and add')
def main2(): def main2():
dr = DumbResolver() chain: ChainCollectionInterface[Any, Plain, WrisbtRoot] = BlockChainFactory(
chain: ChainCollectionInterface[Any, Plain, Array[WrisbtRoot]] = BlockChainFactory( WrisbtChainProtocol(Plain.factory(), 2).loose()
WrisbtChainProtocol(dr, Plain.factory(), 2).loose() ).empty().loose()
).loose().empty().loose()
for _ in range(1000): for _ in range(1000):
chain = chain.add(HashPoint.of(Plain(os.urandom(16)))) chain = chain.add(HashPoint.of(Plain(os.urandom(16))))
assert chain assert chain
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
print(dr.resolve(chain.actual_state().reference.value).height) print(chain.actual_state().reference.value.resolve().height)
def main(): def main():
dr = DumbResolver()
tree: ActiveBinaryTree[Plain, Integer] = ActiveBinaryTree.empty( tree: ActiveBinaryTree[Plain, Integer] = ActiveBinaryTree.empty(
AVLBTBP(PlainComparator(dr, Replace())), Plain.factory() AVLBTBP(PlainComparator(Replace())), Plain.factory()
) )
for i in range(26): for i in range(26):
tree = tree.add(HashPoint.of(Plain(bytes([ord('A') + i])))) tree = tree.add(HashPoint.of(Plain(bytes([ord('A') + i]))))
print(tree.reference.str(dr, 0)) print(tree.reference.str(0))
if __name__ == '__main__': if __name__ == '__main__':
main1() main0()

View File

@ -1,12 +1,12 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate 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.hashresolver import HashResolver
from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin
__all__ = ('Block', 'BlockFactory',) __all__ = ('Block', 'BlockFactory',)
@ -40,16 +40,15 @@ class Block(RecursiveMentionable, Generic[HeaderType, StateType]):
self.state.factory, self.state.factory,
) )
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'{self.previous.str(resolver, tab)}' \ return f'{self.previous.str(tab)}' \
f'{tabulate(tab)}(' \ f'{tabulate(tab)}(' \
f'{tabulate(tab + 1)}block' \ f'{tabulate(tab + 1)}block' \
f'{tabulate(tab + 1)}(header)' \ f'{tabulate(tab + 1)}(header)' \
f'{tabulate(tab + 1)}{hash_point_format(self.header, resolver, tab + 1)}' \ f'{tabulate(tab + 1)}{hash_point_format(self.header, tab + 1)}' \
f'{tabulate(tab + 1)}(state)' \ f'{tabulate(tab + 1)}(state)' \
f'{tabulate(tab + 1)}{hash_point_format(self.state, resolver, tab + 1)}' \ f'{tabulate(tab + 1)}{hash_point_format(self.state, tab + 1)}' \
f'{tabulate(tab)})' f'{tabulate(tab)})'
@ -64,10 +63,15 @@ class BlockFactory(RainbowFactory[Block[HeaderType, StateType]], Generic[HeaderT
self.header_factory = header_factory self.header_factory = header_factory
self.state_factory = state_factory self.state_factory = state_factory
def from_bytes(self, source: bytes) -> Block[HeaderType, StateType]: def from_bytes(self, source: bytes, resolver: HashResolver) -> Block[HeaderType, StateType]:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return Block( return Block(
NullableReferenceFactory(self).from_bytes(source[:HashPoint.HASH_LENGTH]), NullableReferenceFactory(self).from_bytes(source[:HashPoint.HASH_LENGTH], resolver),
HashPoint(self.header_factory, source[HashPoint.HASH_LENGTH:2 * HashPoint.HASH_LENGTH], Null()), ResolverOrigin(
HashPoint(self.state_factory, source[2 * HashPoint.HASH_LENGTH:3 * HashPoint.HASH_LENGTH], Null()), self.header_factory, source[HashPoint.HASH_LENGTH:2 * HashPoint.HASH_LENGTH], resolver
).hash_point(),
ResolverOrigin(
self.state_factory, source[2 * HashPoint.HASH_LENGTH:3 * HashPoint.HASH_LENGTH], resolver
).hash_point(),
) )

View File

@ -26,7 +26,7 @@ class BlockChain(
HeaderType, HeaderType,
ActualStateType ActualStateType
], ],
Generic[HeaderType, StateType, ActualStateType], Generic[HeaderType, ActualStateType, StateType],
): ):
def __init__( def __init__(
self, self,
@ -40,7 +40,7 @@ class BlockChain(
): ):
assert isinstance(reference, NullableReference) assert isinstance(reference, NullableReference)
assert isinstance(protocol, BlockChainProtocol) assert isinstance(protocol, BlockChainProtocol)
super().__init__(reference, protocol.resolver) super().__init__(reference)
self.protocol = protocol self.protocol = protocol
def factory(self) -> ChainCollectionFactory[ def factory(self) -> ChainCollectionFactory[
@ -85,7 +85,7 @@ class BlockChain(
block: Block[ block: Block[
HeaderType, HeaderType,
StateType StateType
] = self.resolver.resolve(self.reference.reference.value) ] = self.reference.reference.value.resolve()
assert isinstance(block, Block) assert isinstance(block, Block)
return NullableReference.of(block.state) return NullableReference.of(block.state)
else: else:
@ -122,7 +122,7 @@ class BlockChain(
block: Block[ block: Block[
HeaderType, HeaderType,
StateType StateType
] = self.resolver.resolve(self.reference.reference.value) ] = self.reference.reference.value.resolve()
assert isinstance(block, Block) assert isinstance(block, Block)
return self.factory().from_reference(block.previous) return self.factory().from_reference(block.previous)
@ -171,7 +171,7 @@ class BlockChain(
] ]
) -> HashPoint[ActualStateType]: ) -> HashPoint[ActualStateType]:
assert isinstance(block, Block) assert isinstance(block, Block)
return self.protocol.actual_state(self.resolver.resolve(block.state)) return self.protocol.actual_state(block.state.resolve())
def loose(self) -> ChainCollectionInterface[ def loose(self) -> ChainCollectionInterface[
Block[ Block[
@ -193,7 +193,7 @@ class BlockChainFactory(
HeaderType, HeaderType,
ActualStateType ActualStateType
], ],
Generic[HeaderType, StateType, ActualStateType] Generic[HeaderType, ActualStateType, StateType]
): ):
def __init__( def __init__(
self, self,
@ -202,7 +202,7 @@ class BlockChainFactory(
assert isinstance(protocol, BlockChainProtocol) assert isinstance(protocol, BlockChainProtocol)
self.protocol = protocol self.protocol = protocol
def empty(self) -> BlockChain[HeaderType, StateType, ActualStateType]: def empty(self) -> BlockChain[HeaderType, ActualStateType, StateType]:
return BlockChain( return BlockChain(
NullableReference( NullableReference(
Null(), Null(),
@ -223,7 +223,7 @@ class BlockChainFactory(
], ],
] ]
) -> BlockChain[ ) -> BlockChain[
HeaderType, StateType, ActualStateType HeaderType, ActualStateType, StateType
]: ]:
assert isinstance(reference, NullableReference) assert isinstance(reference, NullableReference)
return BlockChain( return BlockChain(

View File

@ -2,7 +2,6 @@ from typing import Generic, TypeVar
from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
__all__ = ('BlockChainProtocol',) __all__ = ('BlockChainProtocol',)
@ -27,8 +26,6 @@ class BlockChainProtocol(
self.state_protocol = protocol self.state_protocol = protocol
self.header_factory = header_factory self.header_factory = header_factory
self.state_factory = state_factory self.state_factory = state_factory
self.resolver = protocol.resolver
assert isinstance(self.resolver, HashResolver)
def actual_state_factory(self) -> RainbowFactory[ActualStateType]: def actual_state_factory(self) -> RainbowFactory[ActualStateType]:
raise NotImplementedError raise NotImplementedError

View File

@ -2,7 +2,6 @@ from typing import Generic, TypeVar
from rainbowadn.data.collection.collection_interface.collectioninterface import CollectionInterface from rainbowadn.data.collection.collection_interface.collectioninterface import CollectionInterface
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.hashing.nullability.notnull import NotNull
from rainbowadn.hashing.nullability.null import Null from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.hashing.nullability.nullablereference import NullableReference
@ -23,12 +22,9 @@ class BlockCollectionInterface(
): ):
def __init__( def __init__(
self, self,
reference: NullableReference[BlockType], reference: NullableReference[BlockType]
resolver: HashResolver
): ):
assert isinstance(reference, NullableReference) assert isinstance(reference, NullableReference)
assert isinstance(resolver, HashResolver)
self.resolver = resolver
super().__init__(reference) super().__init__(reference)
def _verify_link( def _verify_link(
@ -47,7 +43,7 @@ class BlockCollectionInterface(
return True return True
elif isinstance(self.reference.reference, NotNull): elif isinstance(self.reference.reference, NotNull):
return self._verify_link( return self._verify_link(
self.resolver.resolve(self.reference.reference.value), self.reference.reference.value.resolve(),
previous previous
) )
else: else:
@ -63,7 +59,7 @@ class BlockCollectionInterface(
if isinstance(self.reference.reference, Null): if isinstance(self.reference.reference, Null):
return NullableReference(Null(), self._actual_state_factory()) return NullableReference(Null(), self._actual_state_factory())
elif isinstance(self.reference.reference, NotNull): elif isinstance(self.reference.reference, NotNull):
return NullableReference.of(self._actual_state(self.resolver.resolve(self.reference.reference.value))) return NullableReference.of(self._actual_state(self.reference.reference.value.resolve()))
else: else:
raise TypeError raise TypeError

View File

@ -1,12 +1,12 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.chain.reduction.reductionresult import ReductionResult from rainbowadn.chain.reduction.reductionresult import ReductionResult
from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate 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.hashresolver import HashResolver
from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin
__all__ = ('Reduction', 'ReductionFactory',) __all__ = ('Reduction', 'ReductionFactory',)
@ -34,11 +34,10 @@ class Reduction(
def __factory__(self) -> RainbowFactory['Reduction[ReductorType, AccumulatorType]']: def __factory__(self) -> RainbowFactory['Reduction[ReductorType, AccumulatorType]']:
return ReductionFactory(self.reductor.factory, self.accumulator.factory) return ReductionFactory(self.reductor.factory, self.accumulator.factory)
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'(reduction)' \ return f'(reduction)' \
f'{tabulate(tab)}{hash_point_format(self.accumulator, resolver, tab)}' f'{tabulate(tab)}{hash_point_format(self.accumulator, tab)}'
class ReductionFactory( class ReductionFactory(
@ -55,9 +54,10 @@ class ReductionFactory(
self.reductor_factory = reductor_factory self.reductor_factory = reductor_factory
self.accumulator_factory = accumulator_factory self.accumulator_factory = accumulator_factory
def from_bytes(self, source: bytes) -> Reduction[ReductorType, AccumulatorType]: def from_bytes(self, source: bytes, resolver: HashResolver) -> Reduction[ReductorType, AccumulatorType]:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return Reduction( return Reduction(
HashPoint(self.reductor_factory, source[:HashPoint.HASH_LENGTH], Null()), ResolverOrigin(self.reductor_factory, source[:HashPoint.HASH_LENGTH], resolver).hash_point(),
HashPoint(self.accumulator_factory, source[HashPoint.HASH_LENGTH:], Null()), ResolverOrigin(self.accumulator_factory, source[HashPoint.HASH_LENGTH:], resolver).hash_point(),
) )

View File

@ -3,7 +3,6 @@ from typing import Generic, TypeVar
from rainbowadn.chain.reduction.reduction import Reduction from rainbowadn.chain.reduction.reduction import Reduction
from rainbowadn.chain.reduction.reductionresult import ReductionResult from rainbowadn.chain.reduction.reductionresult import ReductionResult
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
__all__ = ('ReductionProtocol',) __all__ = ('ReductionProtocol',)
@ -13,10 +12,6 @@ AccumulatorType = TypeVar('AccumulatorType')
class ReductionProtocol(Generic[ReductorType, AccumulatorType]): class ReductionProtocol(Generic[ReductorType, AccumulatorType]):
def __init__(self, resolver: HashResolver):
assert isinstance(resolver, HashResolver)
self.resolver = resolver
def reduce( def reduce(
self, self,
reduction: Reduction[ReductorType, AccumulatorType] reduction: Reduction[ReductorType, AccumulatorType]

View File

@ -26,7 +26,7 @@ class ReductionStageProtocol(
def __init__(self, protocol: ReductionProtocol[ReductorType, AccumulatorType]): def __init__(self, protocol: ReductionProtocol[ReductorType, AccumulatorType]):
assert isinstance(protocol, ReductionProtocol) assert isinstance(protocol, ReductionProtocol)
self.protocol = protocol self.protocol = protocol
super().__init__(protocol.resolver) super().__init__()
def _derive_accumulator( def _derive_accumulator(
self, self,
@ -72,8 +72,4 @@ class ReductionStageProtocol(
stage: HashPoint[Reduction[ReductorType, AccumulatorType]] stage: HashPoint[Reduction[ReductorType, AccumulatorType]]
) -> Derived[ReductorType, Reduction[ReductorType, AccumulatorType]]: ) -> Derived[ReductorType, Reduction[ReductorType, AccumulatorType]]:
assert isinstance(stage, HashPoint) assert isinstance(stage, HashPoint)
return self._derived_from_reduced( return self._derived_from_reduced(self.protocol.reduce(stage.resolve()))
self.protocol.reduce(
self.resolver.resolve(stage)
)
)

View File

@ -35,8 +35,9 @@ class ActiveStageProtocol(
) -> Derived[BaseStateType, StageType]: ) -> Derived[BaseStateType, StageType]:
raise NotImplementedError raise NotImplementedError
@classmethod
def _previous_base_state( def _previous_base_state(
self, cls,
previous_reference: NullableReference[StateStage[HeaderType, BaseStateType, StageType]], previous_reference: NullableReference[StateStage[HeaderType, BaseStateType, StageType]],
base_state_factory: RainbowFactory[BaseStateType], base_state_factory: RainbowFactory[BaseStateType],
) -> NullableReference[BaseStateType]: ) -> NullableReference[BaseStateType]:
@ -45,8 +46,8 @@ class ActiveStageProtocol(
if isinstance(previous_reference.reference, Null): if isinstance(previous_reference.reference, Null):
return NullableReference(Null(), base_state_factory) return NullableReference(Null(), base_state_factory)
elif isinstance(previous_reference.reference, NotNull): elif isinstance(previous_reference.reference, NotNull):
previous_state_stage: StateStage[HeaderType, BaseStateType, StageType] = self.resolver.resolve( previous_state_stage: StateStage[HeaderType, BaseStateType, StageType] = (
previous_reference.reference.value previous_reference.reference.value.resolve()
) )
assert isinstance(previous_state_stage, StateStage) assert isinstance(previous_state_stage, StateStage)
return NullableReference.of(previous_state_stage.state) return NullableReference.of(previous_state_stage.state)

View File

@ -33,7 +33,6 @@ class ActiveStageStateProtocol(
assert isinstance(protocol, ActiveStageProtocol) assert isinstance(protocol, ActiveStageProtocol)
assert isinstance(stage_factory, RainbowFactory) assert isinstance(stage_factory, RainbowFactory)
assert isinstance(base_state_factory, RainbowFactory) assert isinstance(base_state_factory, RainbowFactory)
super().__init__(protocol.resolver)
self.protocol = protocol self.protocol = protocol
self.stage_factory = stage_factory self.stage_factory = stage_factory
self.base_state_factory = base_state_factory self.base_state_factory = base_state_factory

View File

@ -1,14 +1,15 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.chain.stages.stageprotocol import StageProtocol from rainbowadn.chain.stages.stageprotocol import StageProtocol
from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate 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.hashresolver import HashResolver
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.hashing.nullability.notnull import NotNull
from rainbowadn.hashing.nullability.null import Null from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin
__all__ = ( __all__ = (
'StageStage', 'StageStage',
@ -46,8 +47,9 @@ class StageStage(
self.previous = previous self.previous = previous
self.stage = stage self.stage = stage
@classmethod
def _previous_state( def _previous_state(
self, cls,
previous: NullableReference['StateStage[HeaderType, BaseStateType, StageType]'], previous: NullableReference['StateStage[HeaderType, BaseStateType, StageType]'],
base_factory: RainbowFactory[BaseStateType], base_factory: RainbowFactory[BaseStateType],
) -> NullableReference[BaseStateType]: ) -> NullableReference[BaseStateType]:
@ -56,9 +58,7 @@ class StageStage(
if isinstance(previous.reference, Null): if isinstance(previous.reference, Null):
return NullableReference(Null(), base_factory) return NullableReference(Null(), base_factory)
elif isinstance(previous.reference, NotNull): elif isinstance(previous.reference, NotNull):
state_stage: StateStage[HeaderType, BaseStateType, StageType] = self.protocol.resolver.resolve( state_stage: StateStage[HeaderType, BaseStateType, StageType] = previous.reference.value.resolve()
previous.reference.value
)
assert isinstance(state_stage, StateStage) assert isinstance(state_stage, StateStage)
return NullableReference.of(state_stage.state) return NullableReference.of(state_stage.state)
else: else:
@ -80,9 +80,7 @@ class StageStage(
self.stage self.stage
) )
elif isinstance(self.previous.reference, NotNull): elif isinstance(self.previous.reference, NotNull):
previous_stage: StageStage[HeaderType, BaseStateType, StageType] = self.protocol.resolver.resolve( previous_stage: StageStage[HeaderType, BaseStateType, StageType] = self.previous.reference.value.resolve()
self.previous.reference.value
)
assert isinstance(previous_stage, StageStage) assert isinstance(previous_stage, StageStage)
return self.protocol.verify_stage( return self.protocol.verify_stage(
previous_stage.stage, previous_stage.stage,
@ -107,11 +105,10 @@ class StageStage(
self.stage.factory self.stage.factory
) )
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'{self.previous.str(resolver, tab)}' \ return f'{self.previous.str(tab)}' \
f'{tabulate(tab)}{hash_point_format(self.stage, resolver, tab)}' f'{tabulate(tab)}{hash_point_format(self.stage, tab)}'
class StageStageFactory(RainbowFactory[StageStage[HeaderType, BaseStateType, StageType]]): class StageStageFactory(RainbowFactory[StageStage[HeaderType, BaseStateType, StageType]]):
@ -125,12 +122,13 @@ class StageStageFactory(RainbowFactory[StageStage[HeaderType, BaseStateType, Sta
self.protocol = protocol self.protocol = protocol
self.stage_factory = stage_factory self.stage_factory = stage_factory
def from_bytes(self, source: bytes) -> StageStage[HeaderType, BaseStateType, StageType]: def from_bytes(self, source: bytes, resolver: HashResolver) -> StageStage[HeaderType, BaseStateType, StageType]:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return StageStage( return StageStage(
self.protocol, self.protocol,
NullableReferenceFactory(self).from_bytes(source[:HashPoint.HASH_LENGTH]), NullableReferenceFactory(self).from_bytes(source[:HashPoint.HASH_LENGTH], resolver),
HashPoint(self.stage_factory, source[HashPoint.HASH_LENGTH:], Null()) ResolverOrigin(self.stage_factory, source[HashPoint.HASH_LENGTH:], resolver).hash_point()
) )
@ -162,9 +160,7 @@ class StateStage(
) -> bool: ) -> bool:
assert isinstance(previous, NullableReference) assert isinstance(previous, NullableReference)
assert isinstance(header, HashPoint) assert isinstance(header, HashPoint)
previous_stage: StageStage[HeaderType, BaseStateType, StageType] = self.protocol.resolver.resolve( previous_stage: StageStage[HeaderType, BaseStateType, StageType] = self.previous.resolve()
self.previous
)
assert isinstance(previous_stage, StageStage) assert isinstance(previous_stage, StageStage)
return self.protocol.verify_state( return self.protocol.verify_state(
previous_stage.stage, previous_stage.stage,
@ -188,11 +184,10 @@ class StateStage(
self.state.factory self.state.factory
) )
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'{hash_point_format(self.previous, resolver, tab)}' \ return f'{hash_point_format(self.previous, tab)}' \
f'{tabulate(tab)}{hash_point_format(self.state, resolver, tab)}' f'{tabulate(tab)}{hash_point_format(self.state, tab)}'
class StateStageFactory(RainbowFactory[StateStage[HeaderType, BaseStateType, StageType]]): class StateStageFactory(RainbowFactory[StateStage[HeaderType, BaseStateType, StageType]]):
@ -209,17 +204,19 @@ class StateStageFactory(RainbowFactory[StateStage[HeaderType, BaseStateType, Sta
self.stage_factory = stage_factory self.stage_factory = stage_factory
self.state_factory = state_factory self.state_factory = state_factory
def from_bytes(self, source: bytes) -> StateStage[HeaderType, BaseStateType, StageType]: def from_bytes(self, source: bytes, resolver: HashResolver) -> StateStage[HeaderType, BaseStateType, StageType]:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return StateStage( return StateStage(
self.protocol, self.protocol,
HashPoint( ResolverOrigin(
StageStageFactory( StageStageFactory(
self.protocol, self.protocol,
self.stage_factory self.stage_factory
), ),
source[:HashPoint.HASH_LENGTH], Null() source[:HashPoint.HASH_LENGTH],
), resolver
HashPoint(self.state_factory, source[HashPoint.HASH_LENGTH:], Null()), ).hash_point(),
ResolverOrigin(self.state_factory, source[HashPoint.HASH_LENGTH:], resolver).hash_point(),
self.stage_factory self.stage_factory
) )

View File

@ -1,7 +1,6 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.hashing.nullability.nullablereference import NullableReference
__all__ = ('StageProtocol',) __all__ = ('StageProtocol',)
@ -12,10 +11,6 @@ StageType = TypeVar('StageType')
class StageProtocol(Generic[HeaderType, BaseStateType, StageType]): class StageProtocol(Generic[HeaderType, BaseStateType, StageType]):
def __init__(self, resolver: HashResolver):
assert isinstance(resolver, HashResolver)
self.resolver = resolver
def verify_header( def verify_header(
self, self,
previous: NullableReference[BaseStateType], previous: NullableReference[BaseStateType],

View File

@ -25,4 +25,4 @@ class StageStateProtocol(
assert isinstance(previous, NullableReference) assert isinstance(previous, NullableReference)
assert isinstance(header, HashPoint) assert isinstance(header, HashPoint)
assert isinstance(state, HashPoint) assert isinstance(state, HashPoint)
return self.resolver.resolve(state).verify(previous, header) return state.resolve().verify(previous, header)

View File

@ -1,7 +1,6 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.hashing.nullability.nullablereference import NullableReference
__all__ = ('StateProtocol',) __all__ = ('StateProtocol',)
@ -11,10 +10,6 @@ StateType = TypeVar('StateType')
class StateProtocol(Generic[HeaderType, StateType]): class StateProtocol(Generic[HeaderType, StateType]):
def __init__(self, resolver: HashResolver):
assert isinstance(resolver, HashResolver)
self.resolver = resolver
def verify( def verify(
self, self,
previous: NullableReference[StateType], previous: NullableReference[StateType],

View File

@ -1,7 +1,8 @@
import abc import abc
from typing import TypeVar from typing import Type, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.static import StaticMentionable from rainbowadn.hashing.static import StaticMentionable
__all__ = ('Atomic',) __all__ = ('Atomic',)
@ -12,3 +13,13 @@ AtomicMentioned = TypeVar('AtomicMentioned')
class Atomic(StaticMentionable, abc.ABC): class Atomic(StaticMentionable, abc.ABC):
def __topology_hash__(self) -> bytes: def __topology_hash__(self) -> bytes:
return HashPoint.hash(b'') return HashPoint.hash(b'')
@classmethod
def from_bytes(cls: Type[AtomicMentioned], source: bytes, resolver: HashResolver) -> AtomicMentioned:
assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return cls._from_bytes(source)
@classmethod
def _from_bytes(cls: Type[AtomicMentioned], source: bytes) -> AtomicMentioned:
raise NotImplementedError

View File

@ -10,7 +10,7 @@ class Integer(Atomic):
self.integer = integer self.integer = integer
@classmethod @classmethod
def from_bytes(cls, source: bytes) -> 'Integer': def _from_bytes(cls, source: bytes) -> 'Integer':
assert isinstance(source, bytes) assert isinstance(source, bytes)
return cls(int.from_bytes(source, 'little')) return cls(int.from_bytes(source, 'little'))

View File

@ -9,7 +9,7 @@ class Plain(Atomic):
self.source = source self.source = source
@classmethod @classmethod
def from_bytes(cls, source: bytes) -> 'Plain': def _from_bytes(cls, source: bytes) -> 'Plain':
assert isinstance(source, bytes) assert isinstance(source, bytes)
return cls(source) return cls(source)

View File

@ -3,9 +3,9 @@ from typing import Generic, Iterable, TypeVar
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin
__all__ = ('Array', 'ArrayFactory',) __all__ = ('Array', 'ArrayFactory',)
@ -32,12 +32,11 @@ class Array(RecursiveMentionable, Generic[ElementType]):
def __factory__(self) -> RainbowFactory['Array']: def __factory__(self) -> RainbowFactory['Array']:
return ArrayFactory(self.factory) return ArrayFactory(self.factory)
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
formatted = f'(' formatted = f'('
for hash_point in self.array: for hash_point in self.array:
formatted += f'{tabulate(tab+1)}{hash_point_format(hash_point,resolver,tab+1)}' formatted += f'{tabulate(tab + 1)}{hash_point_format(hash_point, tab + 1)}'
return f'{formatted}' \ return f'{formatted}' \
f'{tabulate(tab)})' f'{tabulate(tab)})'
@ -50,12 +49,13 @@ class ArrayFactory(RainbowFactory[Array], Generic[ElementType]):
assert isinstance(factory, RainbowFactory) assert isinstance(factory, RainbowFactory)
self.factory = factory self.factory = factory
def from_bytes(self, source: bytes) -> Array: def from_bytes(self, source: bytes, resolver: HashResolver) -> Array:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return Array( return Array(
self.factory, self.factory,
tuple( tuple(
HashPoint(self.factory, source[i:i + HashPoint.HASH_LENGTH], Null()) ResolverOrigin(self.factory, source[i:i + HashPoint.HASH_LENGTH], resolver).hash_point()
for for
i i
in in

View File

@ -1,11 +1,11 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.data.collection.keyed import Keyed from rainbowadn.data.collection.keyed import Keyed
from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate 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.hashresolver import HashResolver
from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.resolverorigin import ResolverOrigin
__all__ = ('KeyMetadata', 'KeyMetadataFactory',) __all__ = ('KeyMetadata', 'KeyMetadataFactory',)
@ -29,11 +29,10 @@ class KeyMetadata(Keyed[ActiveKeyType], Generic[ActiveKeyType, MetaDataType]):
def __factory__(self) -> RainbowFactory['KeyMetadata[ActiveKeyType, MetaDataType]']: def __factory__(self) -> RainbowFactory['KeyMetadata[ActiveKeyType, MetaDataType]']:
return KeyMetadataFactory(self.key.factory, self.metadata.factory) return KeyMetadataFactory(self.key.factory, self.metadata.factory)
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'{hash_point_format(self.key, resolver, tab)}' \ return f'{hash_point_format(self.key, tab)}' \
f'{tabulate(tab)}{hash_point_format(self.metadata, resolver, tab)}' f'{tabulate(tab)}{hash_point_format(self.metadata, tab)}'
class KeyMetadataFactory( class KeyMetadataFactory(
@ -46,11 +45,12 @@ class KeyMetadataFactory(
self.key_factory = key_factory self.key_factory = key_factory
self.metadata_factory = metadata_factory self.metadata_factory = metadata_factory
def from_bytes(self, source: bytes) -> KeyMetadata[ActiveKeyType, MetaDataType]: def from_bytes(self, source: bytes, resolver: HashResolver) -> KeyMetadata[ActiveKeyType, MetaDataType]:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return KeyMetadata( return KeyMetadata(
HashPoint(self.key_factory, source[:HashPoint.HASH_LENGTH], Null()), ResolverOrigin(self.key_factory, source[:HashPoint.HASH_LENGTH], resolver).hash_point(),
HashPoint(self.metadata_factory, source[HashPoint.HASH_LENGTH:], Null()), ResolverOrigin(self.metadata_factory, source[HashPoint.HASH_LENGTH:], resolver).hash_point(),
) )
def loose(self) -> RainbowFactory[KeyMetadata[ActiveKeyType, MetaDataType]]: def loose(self) -> RainbowFactory[KeyMetadata[ActiveKeyType, MetaDataType]]:

View File

@ -3,7 +3,6 @@ from typing import Generic, TypeVar
from rainbowadn.data.collection.collection_interface.querycollectioninterface import QueryCollectionInterface from rainbowadn.data.collection.collection_interface.querycollectioninterface import QueryCollectionInterface
from rainbowadn.data.collection.keymetadata import KeyMetadata from rainbowadn.data.collection.keymetadata import KeyMetadata
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.hashing.nullability.notnull import NotNull
from rainbowadn.hashing.nullability.null import Null from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.nullability.nullable import Nullable from rainbowadn.hashing.nullability.nullable import Nullable
@ -19,14 +18,11 @@ class KeyMetadataQueryCollection(QueryCollectionInterface[ActiveKeyType], Generi
self, self,
metadata: HashPoint[MetaDataType], metadata: HashPoint[MetaDataType],
collection: QueryCollectionInterface[KeyMetadata[ActiveKeyType, MetaDataType]], collection: QueryCollectionInterface[KeyMetadata[ActiveKeyType, MetaDataType]],
resolver: HashResolver
): ):
assert isinstance(metadata, HashPoint) assert isinstance(metadata, HashPoint)
assert isinstance(collection, QueryCollectionInterface) assert isinstance(collection, QueryCollectionInterface)
assert isinstance(resolver, HashResolver)
self.metadata = metadata self.metadata = metadata
self.collection = collection self.collection = collection
self.resolver = resolver
def query(self, key: HashPoint[ActiveKeyType]) -> Nullable[HashPoint[ActiveKeyType]]: def query(self, key: HashPoint[ActiveKeyType]) -> Nullable[HashPoint[ActiveKeyType]]:
assert isinstance(key, HashPoint) assert isinstance(key, HashPoint)
@ -39,6 +35,6 @@ class KeyMetadataQueryCollection(QueryCollectionInterface[ActiveKeyType], Generi
elif isinstance(result, NotNull): elif isinstance(result, NotNull):
hash_point: HashPoint[KeyMetadata[ActiveKeyType, MetaDataType]] = result.value hash_point: HashPoint[KeyMetadata[ActiveKeyType, MetaDataType]] = result.value
assert isinstance(hash_point, HashPoint) assert isinstance(hash_point, HashPoint)
return NotNull(self.resolver.resolve(hash_point).key) return NotNull(hash_point.resolve().key)
else: else:
raise TypeError raise TypeError

View File

@ -2,8 +2,9 @@ from typing import Generic, Iterable, TypeVar
from rainbowadn.data.collection.keyed import Keyed from rainbowadn.data.collection.keyed import Keyed
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.nullability.null import Null from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.resolverorigin import ResolverOrigin
__all__ = ('KeyValue', 'KeyValueFactory',) __all__ = ('KeyValue', 'KeyValueFactory',)
@ -38,9 +39,10 @@ class KeyValueFactory(
self.key_factory = key_factory self.key_factory = key_factory
self.value_factory = value_factory self.value_factory = value_factory
def from_bytes(self, source: bytes) -> KeyValue[KVKeyType, KVValueType]: def from_bytes(self, source: bytes, resolver: HashResolver) -> KeyValue[KVKeyType, KVValueType]:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return KeyValue( return KeyValue(
HashPoint(self.key_factory, source[:HashPoint.HASH_LENGTH], Null()), ResolverOrigin(self.key_factory, source[:HashPoint.HASH_LENGTH], resolver).hash_point(),
HashPoint(self.value_factory, source[HashPoint.HASH_LENGTH:], Null()), ResolverOrigin(self.value_factory, source[HashPoint.HASH_LENGTH:], resolver).hash_point(),
) )

View File

@ -3,7 +3,6 @@ from typing import Generic, TypeVar
from rainbowadn.data.collection.collection_interface.querycollectioninterface import QueryCollectionInterface from rainbowadn.data.collection.collection_interface.querycollectioninterface import QueryCollectionInterface
from rainbowadn.data.collection.keyvalue import KeyValue from rainbowadn.data.collection.keyvalue import KeyValue
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.hashing.nullability.notnull import NotNull
from rainbowadn.hashing.nullability.null import Null from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.nullability.nullable import Nullable from rainbowadn.hashing.nullability.nullable import Nullable
@ -18,15 +17,12 @@ class QueryMapping(Generic[KVKeyType, KVValueType]):
def __init__( def __init__(
self, self,
collection: QueryCollectionInterface[KeyValue[KVKeyType, KVValueType]], collection: QueryCollectionInterface[KeyValue[KVKeyType, KVValueType]],
empty_value: HashPoint[KVValueType], empty_value: HashPoint[KVValueType]
resoler: HashResolver
): ):
assert isinstance(collection, QueryCollectionInterface) assert isinstance(collection, QueryCollectionInterface)
assert isinstance(empty_value, HashPoint) assert isinstance(empty_value, HashPoint)
assert isinstance(resoler, HashResolver)
self.collection = collection self.collection = collection
self.empty_value = empty_value self.empty_value = empty_value
self.resolver = resoler
def query(self, key: HashPoint[KVKeyType]) -> Nullable[HashPoint[KVValueType]]: def query(self, key: HashPoint[KVKeyType]) -> Nullable[HashPoint[KVValueType]]:
assert isinstance(key, HashPoint) assert isinstance(key, HashPoint)
@ -37,7 +33,7 @@ class QueryMapping(Generic[KVKeyType, KVValueType]):
if isinstance(query_result, Null): if isinstance(query_result, Null):
return Null() return Null()
elif isinstance(query_result, NotNull): elif isinstance(query_result, NotNull):
key_value: KeyValue[KVKeyType, KVValueType] = self.resolver.resolve(query_result.value) key_value: KeyValue[KVKeyType, KVValueType] = query_result.value.resolve()
assert isinstance(key_value, KeyValue) assert isinstance(key_value, KeyValue)
return NotNull(key_value.value) return NotNull(key_value.value)
else: else:

View File

@ -7,6 +7,7 @@ from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin
__all__ = ('Stack', 'StackFactory',) __all__ = ('Stack', 'StackFactory',)
@ -34,11 +35,10 @@ class Stack(RecursiveMentionable, Generic[ElementType]):
def __bytes__(self): def __bytes__(self):
return bytes(self.previous) + bytes(self.element) return bytes(self.previous) + bytes(self.element)
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'{self.previous.str(resolver, tab)}' \ return f'{self.previous.str(tab)}' \
f'{tabulate(tab)}{hash_point_format(self.element, resolver, tab)}' f'{tabulate(tab)}{hash_point_format(self.element, tab)}'
@classmethod @classmethod
def of( def of(
@ -74,11 +74,12 @@ class StackFactory(RainbowFactory[Stack[ElementType]], Generic[ElementType]):
assert isinstance(factory, RainbowFactory) assert isinstance(factory, RainbowFactory)
self.factory = factory self.factory = factory
def from_bytes(self, source: bytes) -> Stack[ElementType]: def from_bytes(self, source: bytes, resolver: HashResolver) -> Stack[ElementType]:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return Stack( return Stack(
NullableReferenceFactory(self).from_bytes(source[:HashPoint.HASH_LENGTH]), NullableReferenceFactory(self).from_bytes(source[:HashPoint.HASH_LENGTH], resolver),
HashPoint(self.factory, source[HashPoint.HASH_LENGTH:], Null()) ResolverOrigin(self.factory, source[HashPoint.HASH_LENGTH:], resolver).hash_point()
) )
def loose(self) -> RainbowFactory[Stack[ElementType]]: def loose(self) -> RainbowFactory[Stack[ElementType]]:

View File

@ -12,7 +12,6 @@ from rainbowadn.data.collection.trees.binary.querybinarytree import QueryBinaryT
from rainbowadn.data.collection.trees.comparison.comparator import (Comparator, Comparison, Left, Replace, Right) from rainbowadn.data.collection.trees.comparison.comparator import (Comparator, Comparison, Left, Replace, Right)
from rainbowadn.data.collection.trees.comparison.keyedcomparator import KeyedComparator from rainbowadn.data.collection.trees.comparison.keyedcomparator import KeyedComparator
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.hashing.nullability.notnull import NotNull
from rainbowadn.hashing.nullability.null import Null from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.nullability.nullablereference import NullableReference from rainbowadn.hashing.nullability.nullablereference import NullableReference
@ -39,8 +38,6 @@ class ActiveBinaryTree(
self.protocol = protocol self.protocol = protocol
self.comparator = protocol.comparator self.comparator = protocol.comparator
assert isinstance(self.comparator, Comparator) assert isinstance(self.comparator, Comparator)
self.resolver = protocol.resolver
assert isinstance(self.resolver, HashResolver)
self.creation = ActiveCreationProtocol(protocol) self.creation = ActiveCreationProtocol(protocol)
assert isinstance(self.creation, BinaryTreeCreationProtocol) assert isinstance(self.creation, BinaryTreeCreationProtocol)
@ -96,8 +93,7 @@ class ActiveBinaryTree(
def query_tree(self) -> QueryCollectionInterface[ActiveKeyType]: def query_tree(self) -> QueryCollectionInterface[ActiveKeyType]:
return KeyMetadataQueryCollection( return KeyMetadataQueryCollection(
self.protocol.empty_metadata(), self.protocol.empty_metadata(),
QueryBinaryTree(KeyedComparator(self.comparator), self.reference), QueryBinaryTree(KeyedComparator(self.comparator), self.reference)
self.resolver
) )
@ -119,9 +115,9 @@ class ActiveCreationProtocol(BalancedTreeCreationProtocol[ActiveKeyType, MetaDat
assert isinstance(tree.reference.reference, NotNull) assert isinstance(tree.reference.reference, NotNull)
hash_point: HashPoint[BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]]] = tree.reference.reference.value hash_point: HashPoint[BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]]] = tree.reference.reference.value
assert isinstance(hash_point, HashPoint) assert isinstance(hash_point, HashPoint)
resolved: BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]] = self.resolver.resolve(hash_point) resolved: BinaryTree[KeyMetadata[ActiveKeyType, MetaDataType]] = hash_point.resolve()
assert isinstance(resolved, BinaryTree) assert isinstance(resolved, BinaryTree)
key_metadata: KeyMetadata[ActiveKeyType, MetaDataType] = self.resolver.resolve(resolved.key) key_metadata: KeyMetadata[ActiveKeyType, MetaDataType] = resolved.key.resolve()
assert isinstance(key_metadata, KeyMetadata) assert isinstance(key_metadata, KeyMetadata)
return tree.create(resolved.treel), key_metadata.key, key_metadata.metadata, tree.create(resolved.treer) return tree.create(resolved.treel), key_metadata.key, key_metadata.metadata, tree.create(resolved.treer)

View File

@ -26,14 +26,15 @@ class AVLBTBP(BinaryTreeBalancingProtocol[ActiveKeyType, Integer, TreeType]):
Integer(1 + max(self.height(treel, protocol), self.height(treer, protocol))) Integer(1 + max(self.height(treel, protocol), self.height(treer, protocol)))
) )
@classmethod
def height( def height(
self, cls,
tree: TreeType, tree: TreeType,
protocol: BinaryTreeCreationProtocol[ActiveKeyType, Integer, TreeType] protocol: BinaryTreeCreationProtocol[ActiveKeyType, Integer, TreeType]
) -> int: ) -> int:
if protocol.splittable(tree): if protocol.splittable(tree):
_, _, metadata, _ = protocol.split(tree) _, _, metadata, _ = protocol.split(tree)
return self.resolver.resolve(metadata).integer return metadata.resolve().integer
else: else:
return 0 return 0

View File

@ -3,7 +3,6 @@ from typing import Generic, TypeVar
from rainbowadn.data.collection.trees.binary.binarytreebalancingprotocol import BinaryTreeBalancingProtocol from rainbowadn.data.collection.trees.binary.binarytreebalancingprotocol import BinaryTreeBalancingProtocol
from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
__all__ = ('BalancedTreeCreationProtocol',) __all__ = ('BalancedTreeCreationProtocol',)
@ -22,8 +21,6 @@ class BalancedTreeCreationProtocol(
): ):
assert isinstance(protocol, BinaryTreeBalancingProtocol) assert isinstance(protocol, BinaryTreeBalancingProtocol)
self.protocol = protocol self.protocol = protocol
self.resolver = protocol.resolver
assert isinstance(self.resolver, HashResolver)
def splittable(self, tree: TreeType) -> bool: def splittable(self, tree: TreeType) -> bool:
raise NotImplementedError raise NotImplementedError

View File

@ -1,12 +1,12 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate 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.hashresolver import HashResolver
from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin
__all__ = ('BinaryTree', 'BinaryTreeFactory',) __all__ = ('BinaryTree', 'BinaryTreeFactory',)
@ -40,12 +40,11 @@ class BinaryTree(RecursiveMentionable, Generic[TreeKeyType]):
def __bytes__(self): def __bytes__(self):
return bytes(self.treel) + bytes(self.treer) + bytes(self.key) return bytes(self.treel) + bytes(self.treer) + bytes(self.key)
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'{self.treel.str(resolver, tab)}' \ return f'{self.treel.str(tab)}' \
f'{tabulate(tab)}{hash_point_format(self.key, resolver, tab)}' \ f'{tabulate(tab)}{hash_point_format(self.key, tab)}' \
f'{tabulate(tab)}{self.treer.str(resolver, tab)}' f'{tabulate(tab)}{self.treer.str(tab)}'
class BinaryTreeFactory(RainbowFactory[BinaryTree[TreeKeyType]], Generic[TreeKeyType]): class BinaryTreeFactory(RainbowFactory[BinaryTree[TreeKeyType]], Generic[TreeKeyType]):
@ -53,12 +52,16 @@ class BinaryTreeFactory(RainbowFactory[BinaryTree[TreeKeyType]], Generic[TreeKey
assert isinstance(factory, RainbowFactory) assert isinstance(factory, RainbowFactory)
self.factory = factory self.factory = factory
def from_bytes(self, source: bytes) -> BinaryTree[TreeKeyType]: def from_bytes(self, source: bytes, resolver: HashResolver) -> BinaryTree[TreeKeyType]:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return BinaryTree( return BinaryTree(
NullableReferenceFactory(self).from_bytes(source[:HashPoint.HASH_LENGTH]), NullableReferenceFactory(self).from_bytes(source[:HashPoint.HASH_LENGTH], resolver),
NullableReferenceFactory(self).from_bytes(source[HashPoint.HASH_LENGTH:HashPoint.HASH_LENGTH * 2]), NullableReferenceFactory(self).from_bytes(
HashPoint(self.factory, source[HashPoint.HASH_LENGTH * 2:], Null()) source[HashPoint.HASH_LENGTH:HashPoint.HASH_LENGTH * 2],
resolver
),
ResolverOrigin(self.factory, source[HashPoint.HASH_LENGTH * 2:], resolver).hash_point()
) )
def loose(self) -> RainbowFactory[BinaryTree[TreeKeyType]]: def loose(self) -> RainbowFactory[BinaryTree[TreeKeyType]]:

View File

@ -3,7 +3,6 @@ from typing import Generic, TypeVar
from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol from rainbowadn.data.collection.trees.binary.binarytreecreationprotocol import BinaryTreeCreationProtocol
from rainbowadn.data.collection.trees.comparison.comparator import Comparator from rainbowadn.data.collection.trees.comparison.comparator import Comparator
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
__all__ = ('BinaryTreeBalancingProtocol',) __all__ = ('BinaryTreeBalancingProtocol',)
@ -19,8 +18,6 @@ class BinaryTreeBalancingProtocol(Generic[ActiveKeyType, MetaDataType, TreeType]
): ):
assert isinstance(comparator, Comparator) assert isinstance(comparator, Comparator)
self.comparator = comparator self.comparator = comparator
self.resolver = comparator.resolver
assert isinstance(self.resolver, HashResolver)
def empty_metadata(self) -> HashPoint[MetaDataType]: def empty_metadata(self) -> HashPoint[MetaDataType]:
raise NotImplementedError raise NotImplementedError

View File

@ -1,10 +1,9 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.data.collection.collection_interface.querycollectioninterface import QueryCollectionInterface
from rainbowadn.data.collection.trees.binary.binarytree import BinaryTree from rainbowadn.data.collection.trees.binary.binarytree import BinaryTree
from rainbowadn.data.collection.trees.comparison.comparator import Comparator, Comparison, Equal, Left, Right from rainbowadn.data.collection.trees.comparison.comparator import Comparator, Comparison, Equal, Left, Right
from rainbowadn.data.collection.collection_interface.querycollectioninterface import QueryCollectionInterface
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.hashing.nullability.notnull import NotNull
from rainbowadn.hashing.nullability.null import Null from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.nullability.nullable import Nullable from rainbowadn.hashing.nullability.nullable import Nullable
@ -23,8 +22,6 @@ class QueryBinaryTree(QueryCollectionInterface[KeyType], Generic[KeyType]):
assert isinstance(reference, NullableReference) assert isinstance(reference, NullableReference)
self.comparator = comparator self.comparator = comparator
self.reference = reference self.reference = reference
self.resolver = comparator.resolver
assert isinstance(self.resolver, HashResolver)
def query(self, key: HashPoint[KeyType]) -> Nullable[HashPoint[KeyType]]: def query(self, key: HashPoint[KeyType]) -> Nullable[HashPoint[KeyType]]:
assert isinstance(key, HashPoint) assert isinstance(key, HashPoint)
@ -35,7 +32,7 @@ class QueryBinaryTree(QueryCollectionInterface[KeyType], Generic[KeyType]):
elif isinstance(reference, NotNull): elif isinstance(reference, NotNull):
hash_point: HashPoint[BinaryTree[KeyType]] = reference.value hash_point: HashPoint[BinaryTree[KeyType]] = reference.value
assert isinstance(hash_point, HashPoint) assert isinstance(hash_point, HashPoint)
tree: BinaryTree[KeyType] = self.resolver.resolve(hash_point) tree: BinaryTree[KeyType] = hash_point.resolve()
assert isinstance(tree, BinaryTree) assert isinstance(tree, BinaryTree)
comparison: Comparison = self.comparator.compare(tree.key, key) comparison: Comparison = self.comparator.compare(tree.key, key)
assert isinstance(comparison, Comparison) assert isinstance(comparison, Comparison)

View File

@ -2,7 +2,6 @@ import abc
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
__all__ = ( __all__ = (
'Comparison', 'Comparison',
@ -48,9 +47,5 @@ KeyType = TypeVar('KeyType')
class Comparator(Generic[KeyType]): class Comparator(Generic[KeyType]):
def __init__(self, resolver: HashResolver):
assert isinstance(resolver, HashResolver)
self.resolver = resolver
def compare(self, original: HashPoint[KeyType], key: HashPoint[KeyType]) -> Comparison: def compare(self, original: HashPoint[KeyType], key: HashPoint[KeyType]) -> Comparison:
raise NotImplementedError raise NotImplementedError

View File

@ -15,7 +15,7 @@ class KeyedComparator(
def __init__(self, comparator: Comparator[ComparatorKeyType]): def __init__(self, comparator: Comparator[ComparatorKeyType]):
assert isinstance(comparator, Comparator) assert isinstance(comparator, Comparator)
self.comparator = comparator self.comparator = comparator
super().__init__(comparator.resolver) super().__init__()
def compare( def compare(
self, self,
@ -25,6 +25,6 @@ class KeyedComparator(
assert isinstance(original, HashPoint) assert isinstance(original, HashPoint)
assert isinstance(key, HashPoint) assert isinstance(key, HashPoint)
return self.comparator.compare( return self.comparator.compare(
self.resolver.resolve(original).key, original.resolve().key,
self.resolver.resolve(key).key, key.resolve().key,
) )

View File

@ -10,9 +10,9 @@ class PlainComparator(ProtocolComparator[Plain]):
def compare(self, original: HashPoint[Plain], key: HashPoint[Plain]) -> Comparison: def compare(self, original: HashPoint[Plain], key: HashPoint[Plain]) -> Comparison:
assert isinstance(original, HashPoint) assert isinstance(original, HashPoint)
assert isinstance(key, HashPoint) assert isinstance(key, HashPoint)
original_value: Plain = self.resolver.resolve(original) original_value: Plain = original.resolve()
assert isinstance(original_value, Plain) assert isinstance(original_value, Plain)
key_value: Plain = self.resolver.resolve(key) key_value: Plain = key.resolve()
assert isinstance(key_value, Plain) assert isinstance(key_value, Plain)
if key_value.source < original_value.source: if key_value.source < original_value.source:
return Left() return Left()

View File

@ -2,7 +2,6 @@ import abc
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.data.collection.trees.comparison.comparator import Comparator, Equal from rainbowadn.data.collection.trees.comparison.comparator import Comparator, Equal
from rainbowadn.hashing.hashresolver import HashResolver
__all__ = ('ProtocolComparator',) __all__ = ('ProtocolComparator',)
@ -10,8 +9,6 @@ KeyType = TypeVar('KeyType')
class ProtocolComparator(Comparator[KeyType], abc.ABC, Generic[KeyType]): class ProtocolComparator(Comparator[KeyType], abc.ABC, Generic[KeyType]):
def __init__(self, resolver: HashResolver, equal: Equal): def __init__(self, equal: Equal):
assert isinstance(resolver, HashResolver)
assert isinstance(equal, Equal) assert isinstance(equal, Equal)
super().__init__(resolver)
self.equal = equal self.equal = equal

View File

View File

@ -1,17 +1,15 @@
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
__all__ = ('hash_point_format', 'tabulate',) __all__ = ('hash_point_format', 'tabulate',)
def hash_point_format(hash_point: HashPoint, resolver: HashResolver, tab: int) -> str: def hash_point_format(hash_point: HashPoint, tab: int) -> str:
assert isinstance(hash_point, HashPoint) assert isinstance(hash_point, HashPoint)
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
value = resolver.resolve(hash_point) value = hash_point.resolve()
if isinstance(value, RecursiveMentionable): if isinstance(value, RecursiveMentionable):
return value.str(resolver, tab) return value.str(tab)
else: else:
return str(value) return str(value)

View File

@ -2,9 +2,8 @@ import hashlib
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashmentionable import HashMentionable from rainbowadn.hashing.hashmentionable import HashMentionable
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.hashing.localorigin import LocalOrigin
from rainbowadn.hashing.nullability.null import Null from rainbowadn.hashing.origin import Origin
from rainbowadn.hashing.nullability.nullable import Nullable
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
__all__ = ('HashPoint',) __all__ = ('HashPoint',)
@ -18,14 +17,19 @@ def _hash(source: bytes) -> bytes:
class HashPoint(Generic[HashMentioned]): class HashPoint(Generic[HashMentioned]):
def __init__(self, factory: RainbowFactory[HashMentioned], point: bytes, value: Nullable[HashMentioned]): def __init__(
self,
factory: RainbowFactory[HashMentioned],
point: bytes,
origin: Origin[HashMentioned]
):
assert isinstance(factory, RainbowFactory) assert isinstance(factory, RainbowFactory)
assert isinstance(point, bytes) assert isinstance(point, bytes)
assert isinstance(value, Nullable) assert isinstance(origin, Origin)
assert len(point) == self.HASH_LENGTH assert len(point) == self.HASH_LENGTH
self.factory = factory self.factory = factory
self.point = point self.point = point
self.value = value self.origin = origin
def __bytes__(self): def __bytes__(self):
return self.point return self.point
@ -50,11 +54,13 @@ class HashPoint(Generic[HashMentioned]):
def of(cls, mentioned: HashMentioned) -> 'HashPoint[HashMentioned]': def of(cls, mentioned: HashMentioned) -> 'HashPoint[HashMentioned]':
assert isinstance(mentioned, HashMentionable) assert isinstance(mentioned, HashMentionable)
return cls( return cls(
mentioned.__factory__(), cls.hash(cls.bytes_of_mentioned(mentioned)), NotNull(mentioned) mentioned.__factory__(), cls.hash(cls.bytes_of_mentioned(mentioned)), LocalOrigin(mentioned)
) )
def loose(self) -> 'HashPoint[HashMentioned]': def resolve(self) -> HashMentioned:
return HashPoint(self.factory, self.point, Null()) resolved = self.origin.resolve()
assert isinstance(resolved, HashMentionable)
return resolved
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, HashPoint): if isinstance(other, HashPoint):

View File

@ -1,29 +1,10 @@
from typing import TypeVar from typing import TypeVar
from rainbowadn.hashing.hashmentionable import HashMentionable
from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.nullability.notnull import NotNull
from rainbowadn.hashing.nullability.null import Null
__all__ = ('HashResolver',) __all__ = ('HashResolver',)
RHashMentioned = TypeVar('RHashMentioned') RHashMentioned = TypeVar('RHashMentioned')
class HashResolver: class HashResolver:
def _resolve(self, point: bytes) -> bytes: def resolve_bytes(self, point: bytes) -> bytes:
raise NotImplementedError raise NotImplementedError
def resolve(self, hashpoint: HashPoint[RHashMentioned]) -> RHashMentioned:
assert isinstance(hashpoint, HashPoint)
if isinstance(hashpoint.value, NotNull):
return hashpoint.value.value
elif isinstance(hashpoint.value, Null):
resolved: bytes = self._resolve(bytes(hashpoint))
assert isinstance(resolved, bytes)
mentioned: RHashMentioned = hashpoint.factory.from_bytes(resolved[HashPoint.HASH_LENGTH:])
assert isinstance(mentioned, HashMentionable)
assert mentioned.__topology_hash__() == resolved[:HashPoint.HASH_LENGTH]
return mentioned
else:
raise TypeError

View File

@ -0,0 +1,22 @@
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
__all__ = ('LocalMetaOrigin',)
OriginType = TypeVar('OriginType')
class LocalMetaOrigin(MetaOrigin[OriginType], Generic[OriginType]):
def __init__(self, origin: Origin[OriginType]):
assert isinstance(origin, Origin)
self._origin = origin
def origin(self, factory: RainbowFactory[OriginType], point: bytes) -> Origin[OriginType]:
assert isinstance(factory, RainbowFactory)
assert isinstance(point, bytes)
assert len(point) == HashPoint.HASH_LENGTH
return self._origin

View File

@ -0,0 +1,17 @@
from typing import Generic, TypeVar
from rainbowadn.hashing.hashmentionable import HashMentionable
from rainbowadn.hashing.origin import Origin
__all__ = ('LocalOrigin',)
OriginType = TypeVar('OriginType')
class LocalOrigin(Origin[OriginType], Generic[OriginType]):
def __init__(self, value: OriginType):
assert isinstance(value, HashMentionable)
self.value: OriginType = value
def resolve(self) -> OriginType:
return self.value

View File

@ -0,0 +1,20 @@
from typing import Generic, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.origin import Origin
from rainbowadn.hashing.rainbow_factory import RainbowFactory
__all__ = ('MetaOrigin',)
OriginType = TypeVar('OriginType')
class MetaOrigin(Generic[OriginType]):
def origin(self, factory: RainbowFactory[OriginType], point: bytes) -> Origin[OriginType]:
raise NotImplementedError
def hash_point(self, factory: RainbowFactory[OriginType], point: bytes) -> HashPoint[OriginType]:
assert isinstance(factory, RainbowFactory)
assert isinstance(point, bytes)
assert len(point) == HashPoint.HASH_LENGTH
return HashPoint(factory, point, self.origin(factory, point))

View File

@ -1,13 +1,14 @@
from typing import Generic, Iterable, TypeVar from typing import Generic, Iterable, TypeVar
from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hash_point_format import hash_point_format 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.hashresolver import HashResolver
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.hashing.nullability.notnull import NotNull
from rainbowadn.hashing.nullability.null import Null from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.nullability.nullable import Nullable from rainbowadn.hashing.nullability.nullable import Nullable
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin
__all__ = ('NullableReference', 'NullableReferenceFactory',) __all__ = ('NullableReference', 'NullableReferenceFactory',)
@ -53,11 +54,11 @@ class NullableReference(RecursiveMentionable, Generic[ReferencedType]):
def off(cls, value: ReferencedType) -> 'NullableReference[ReferencedType]': def off(cls, value: ReferencedType) -> 'NullableReference[ReferencedType]':
return cls.of(HashPoint.of(value)) return cls.of(HashPoint.of(value))
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
if isinstance(self.reference, Null): if isinstance(self.reference, Null):
return f'-' return f'-'
elif isinstance(self.reference, NotNull): elif isinstance(self.reference, NotNull):
return f'{hash_point_format(self.reference.value, resolver, tab)}' return f'{hash_point_format(self.reference.value, tab)}'
else: else:
raise TypeError raise TypeError
@ -76,12 +77,15 @@ class NullableReferenceFactory(RainbowFactory[NullableReference[FReferencedType]
assert isinstance(factory, RainbowFactory) assert isinstance(factory, RainbowFactory)
self.factory = factory self.factory = factory
def from_bytes(self, source: bytes) -> NullableReference[FReferencedType]: def from_bytes(self, source: bytes, resolver: HashResolver) -> NullableReference[FReferencedType]:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
if source == HashPoint.NULL_HASH: if source == HashPoint.NULL_HASH:
return NullableReference(Null(), self.factory) return NullableReference(Null(), self.factory)
else: else:
return NullableReference.of(HashPoint(self.factory, source, Null())) return NullableReference.of(
ResolverOrigin(self.factory, source, resolver).hash_point()
)
def loose(self) -> RainbowFactory[NullableReference[FReferencedType]]: def loose(self) -> RainbowFactory[NullableReference[FReferencedType]]:
return self return self

View File

@ -0,0 +1,10 @@
from typing import Generic, TypeVar
__all__ = ('Origin',)
OriginType = TypeVar('OriginType')
class Origin(Generic[OriginType]):
def resolve(self) -> OriginType:
raise NotImplementedError

View File

@ -1,5 +1,7 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashresolver import HashResolver
__all__ = ('RainbowFactory',) __all__ = ('RainbowFactory',)
FHashMentioned = TypeVar('FHashMentioned') FHashMentioned = TypeVar('FHashMentioned')
@ -8,5 +10,5 @@ FHashMentioned = TypeVar('FHashMentioned')
class RainbowFactory(Generic[FHashMentioned]): class RainbowFactory(Generic[FHashMentioned]):
"""вперёд, уроды, вас ждут заводы""" """вперёд, уроды, вас ждут заводы"""
def from_bytes(self, source: bytes) -> FHashMentioned: def from_bytes(self, source: bytes, resolver: HashResolver) -> FHashMentioned:
raise NotImplementedError raise NotImplementedError

View File

@ -3,7 +3,6 @@ from typing import Iterable
from rainbowadn.hashing.hashmentionable import HashMentionable from rainbowadn.hashing.hashmentionable import HashMentionable
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
__all__ = ('RecursiveMentionable',) __all__ = ('RecursiveMentionable',)
@ -12,8 +11,7 @@ class RecursiveMentionable(HashMentionable, abc.ABC):
def points(self) -> Iterable[HashPoint]: def points(self) -> Iterable[HashPoint]:
raise NotImplementedError raise NotImplementedError
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'(recursive {self.__class__.__name__})' return f'(recursive {self.__class__.__name__})'

View File

@ -18,8 +18,8 @@ def reduce_nullable_reference(
assert isinstance(reference, NullableReference) assert isinstance(reference, NullableReference)
assert isinstance(resolver, HashResolver) assert isinstance(resolver, HashResolver)
if isinstance(reference.reference, Null): if isinstance(reference.reference, Null):
return reference.factory.from_bytes(HashPoint.NULL_HASH) return reference.factory.from_bytes(HashPoint.NULL_HASH, resolver)
elif isinstance(reference.reference, NotNull): elif isinstance(reference.reference, NotNull):
return resolver.resolve(reference.reference.value) return reference.reference.value.resolve()
else: else:
raise TypeError raise TypeError

View File

@ -0,0 +1,28 @@
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
__all__ = ('ResolverMetaOrigin',)
OriginType = TypeVar('OriginType')
class ResolverMetaOrigin(MetaOrigin[OriginType], Generic[OriginType]):
def __init__(self, resolver: HashResolver):
assert isinstance(resolver, HashResolver)
self.resolver = resolver
def origin(self, factory: RainbowFactory[OriginType], point: bytes) -> Origin[OriginType]:
assert isinstance(factory, RainbowFactory)
assert isinstance(point, bytes)
assert len(point) == HashPoint.HASH_LENGTH
return ResolverOrigin(factory, point, self.resolver)
def migrate(self, hash_point: HashPoint[OriginType]) -> HashPoint[OriginType]:
assert isinstance(hash_point, HashPoint)
return self.hash_point(hash_point.factory, hash_point.point)

View File

@ -0,0 +1,37 @@
from typing import Generic, TypeVar
from rainbowadn.hashing.hashmentionable import HashMentionable
from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.origin import Origin
from rainbowadn.hashing.rainbow_factory import RainbowFactory
__all__ = ('ResolverOrigin',)
OriginType = TypeVar('OriginType')
class ResolverOrigin(Origin[OriginType], Generic[OriginType]):
def __init__(
self,
factory: RainbowFactory[OriginType],
point: bytes,
resolver: HashResolver
):
assert isinstance(factory, RainbowFactory)
assert isinstance(point, bytes)
assert isinstance(resolver, HashResolver)
self.factory = factory
self.point = point
self.resolver = resolver
def resolve(self) -> OriginType:
resolved: bytes = self.resolver.resolve_bytes(self.point)
assert isinstance(resolved, bytes)
mentioned: OriginType = self.factory.from_bytes(resolved[HashPoint.HASH_LENGTH:], self.resolver)
assert isinstance(mentioned, HashMentionable)
assert mentioned.__topology_hash__() == resolved[:HashPoint.HASH_LENGTH]
return mentioned
def hash_point(self) -> HashPoint[OriginType]:
return HashPoint(self.factory, self.point, self)

View File

@ -2,6 +2,7 @@ import abc
from typing import Generic, Type, TypeVar from typing import Generic, Type, TypeVar
from rainbowadn.hashing.hashmentionable import HashMentionable from rainbowadn.hashing.hashmentionable import HashMentionable
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
__all__ = ('StaticMentionable', 'StaticFactory',) __all__ = ('StaticMentionable', 'StaticFactory',)
@ -11,7 +12,7 @@ StaticMentioned = TypeVar('StaticMentioned')
class StaticMentionable(HashMentionable, abc.ABC): class StaticMentionable(HashMentionable, abc.ABC):
@classmethod @classmethod
def from_bytes(cls: Type[StaticMentioned], source: bytes) -> StaticMentioned: def from_bytes(cls: Type[StaticMentioned], source: bytes, resolver: HashResolver) -> StaticMentioned:
raise NotImplementedError raise NotImplementedError
def __factory__(self) -> RainbowFactory[StaticMentioned]: def __factory__(self) -> RainbowFactory[StaticMentioned]:
@ -24,11 +25,12 @@ class StaticMentionable(HashMentionable, abc.ABC):
class StaticFactory(RainbowFactory[StaticMentioned], Generic[StaticMentioned]): class StaticFactory(RainbowFactory[StaticMentioned], Generic[StaticMentioned]):
def __init__(self, cls: Type[StaticMentioned]): def __init__(self, cls: Type[StaticMentioned]):
self.cls = cls self.cls: Type[StaticMentioned] = cls
def from_bytes(self, source: bytes) -> StaticMentioned: def from_bytes(self, source: bytes, resolver: HashResolver) -> StaticMentioned:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
if issubclass(self.cls, StaticMentionable): if issubclass(self.cls, StaticMentionable):
return self.cls.from_bytes(source) return self.cls.from_bytes(source, resolver)
else: else:
raise TypeError raise TypeError

View File

@ -2,5 +2,5 @@ from rainbowadn.hashing.hashresolver import HashResolver
class FailResolver(HashResolver): class FailResolver(HashResolver):
def _resolve(self, point: bytes) -> bytes: def resolve_bytes(self, point: bytes) -> bytes:
raise TypeError('fail-resolver always fails') raise TypeError('fail-resolver always fails')

View File

@ -4,7 +4,6 @@ from rainbowadn.chain.abstractreductionchainmetafactory import AbstractReduction
from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface from rainbowadn.chain.chaincollectioninterface import ChainCollectionInterface
from rainbowadn.data.collection.stack.stack import Stack, StackFactory from rainbowadn.data.collection.stack.stack import Stack, StackFactory
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.v13.bankprotocol import BankProtocol from rainbowadn.v13.bankprotocol import BankProtocol
from rainbowadn.v13.bankstate import BankState from rainbowadn.v13.bankstate import BankState
@ -28,22 +27,18 @@ class BankChain(Generic[BlockType]):
self.chain = chain self.chain = chain
self.reference = self.chain.reference self.reference = self.chain.reference
assert isinstance(self.reference, NullableReference) assert isinstance(self.reference, NullableReference)
self.resolver = self.chain.resolver
assert isinstance(self.resolver, HashResolver)
@classmethod @classmethod
def empty( def empty(
cls, cls,
factory: AbstractReductionChainMetaFactory[BlockType, NullableReference[Stack[Transaction]], BankState], factory: AbstractReductionChainMetaFactory[BlockType, NullableReference[Stack[Transaction]], BankState]
resolver: HashResolver
) -> 'BankChain[BlockType]': ) -> 'BankChain[BlockType]':
assert isinstance(factory, AbstractReductionChainMetaFactory) assert isinstance(factory, AbstractReductionChainMetaFactory)
assert isinstance(resolver, HashResolver)
return cls( return cls(
factory.factory( factory.factory(
NullableReferenceFactory(StackFactory(Transaction.factory()).loose()).loose(), NullableReferenceFactory(StackFactory(Transaction.factory()).loose()).loose(),
BankState.factory(), BankState.factory(),
BankProtocol(resolver), BankProtocol(),
).empty() ).empty()
) )
@ -53,17 +48,15 @@ class BankChain(Generic[BlockType]):
factory: AbstractReductionChainMetaFactory[BlockType, NullableReference[Stack[Transaction]], BankState], factory: AbstractReductionChainMetaFactory[BlockType, NullableReference[Stack[Transaction]], BankState],
reference: NullableReference[ reference: NullableReference[
BlockType BlockType
], ]
resolver: HashResolver
) -> 'BankChain[BlockType]': ) -> 'BankChain[BlockType]':
assert isinstance(factory, AbstractReductionChainMetaFactory) assert isinstance(factory, AbstractReductionChainMetaFactory)
assert isinstance(reference, NullableReference) assert isinstance(reference, NullableReference)
assert isinstance(resolver, HashResolver)
return cls( return cls(
factory.factory( factory.factory(
NullableReferenceFactory(StackFactory(Transaction.factory()).loose()).loose(), NullableReferenceFactory(StackFactory(Transaction.factory()).loose()).loose(),
BankState.factory(), BankState.factory(),
BankProtocol(resolver), BankProtocol(),
).from_reference( ).from_reference(
reference reference
) )
@ -76,6 +69,7 @@ class BankChain(Generic[BlockType]):
) )
def adds(self, transactions: list[Transaction]) -> 'BankChain[BlockType]': def adds(self, transactions: list[Transaction]) -> 'BankChain[BlockType]':
assert isinstance(transactions, list)
return self.add( return self.add(
Stack.off( Stack.off(
Transaction.factory(), Transaction.factory(),
@ -87,4 +81,4 @@ class BankChain(Generic[BlockType]):
return self.chain.verify() return self.chain.verify()
def __str__(self): def __str__(self):
return self.reference.str(self.resolver, 0) return self.reference.str(0)

View File

@ -26,18 +26,18 @@ class BankProtocol(ReductionProtocol[NullableReference[Stack[Transaction]], Bank
reduction: Reduction[NullableReference[Stack[Transaction]], BankState] reduction: Reduction[NullableReference[Stack[Transaction]], BankState]
) -> ReductionResult[NullableReference[Stack[Transaction]], BankState]: ) -> ReductionResult[NullableReference[Stack[Transaction]], BankState]:
assert isinstance(reduction, Reduction) assert isinstance(reduction, Reduction)
bank_state: BankState = self.resolver.resolve(reduction.accumulator) bank_state: BankState = reduction.accumulator.resolve()
assert isinstance(bank_state, BankState) assert isinstance(bank_state, BankState)
reference: Nullable[HashPoint[Stack[Transaction]]] = self.resolver.resolve(reduction.reductor).reference reference: Nullable[HashPoint[Stack[Transaction]]] = reduction.reductor.resolve().reference
assert isinstance(reference, Nullable) assert isinstance(reference, Nullable)
if isinstance(reference, Null): if isinstance(reference, Null):
return Reduced(HashPoint.of(bank_state.loose())) return Reduced(HashPoint.of(bank_state.without_miner()))
elif isinstance(reference, NotNull): elif isinstance(reference, NotNull):
stack: Stack[Transaction] = self.resolver.resolve(reference.value) stack: Stack[Transaction] = reference.value.resolve()
assert isinstance(stack, Stack) assert isinstance(stack, Stack)
return Reduction( return Reduction(
HashPoint.of(stack.previous), HashPoint.of(stack.previous),
HashPoint.of(bank_state.push(stack.element, self.resolver)) HashPoint.of(bank_state.push(stack.element))
) )
else: else:
raise TypeError raise TypeError
@ -61,4 +61,4 @@ class BankProtocol(ReductionProtocol[NullableReference[Stack[Transaction]], Bank
def header_filter(self, state: HashPoint[BankState]) -> HashPoint[BankState]: def header_filter(self, state: HashPoint[BankState]) -> HashPoint[BankState]:
assert isinstance(state, HashPoint) assert isinstance(state, HashPoint)
return HashPoint.of(self.resolver.resolve(state).loose().advance(self.resolver)) return HashPoint.of(state.resolve().without_miner().advance())

View File

@ -16,6 +16,7 @@ from rainbowadn.hashing.nullability.nullable import Nullable
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin
from rainbowadn.hashing.static import StaticFactory, StaticMentionable from rainbowadn.hashing.static import StaticFactory, StaticMentionable
from rainbowadn.v13.algo import MINT_CONST from rainbowadn.v13.algo import MINT_CONST
from rainbowadn.v13.subject import Subject from rainbowadn.v13.subject import Subject
@ -48,8 +49,9 @@ class BankState(RecursiveMentionable, StaticMentionable):
return bytes(self.minted) + bytes(self.used) + bytes(self.miner) + bytes(self.length) return bytes(self.minted) + bytes(self.used) + bytes(self.miner) + bytes(self.length)
@classmethod @classmethod
def from_bytes(cls, source: bytes) -> 'BankState': def from_bytes(cls, source: bytes, resolver: HashResolver) -> 'BankState':
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
reference_factory: RainbowFactory[ reference_factory: RainbowFactory[
NullableReference[BinaryTree[KeyMetadata[Coin, Integer]]] NullableReference[BinaryTree[KeyMetadata[Coin, Integer]]]
] = NullableReferenceFactory( ] = NullableReferenceFactory(
@ -62,15 +64,15 @@ class BankState(RecursiveMentionable, StaticMentionable):
).loose() ).loose()
assert isinstance(reference_factory, RainbowFactory) assert isinstance(reference_factory, RainbowFactory)
return cls( return cls(
reference_factory.from_bytes(source[:HashPoint.HASH_LENGTH]), reference_factory.from_bytes(source[:HashPoint.HASH_LENGTH], resolver),
reference_factory.from_bytes(source[HashPoint.HASH_LENGTH:2 * HashPoint.HASH_LENGTH]), reference_factory.from_bytes(source[HashPoint.HASH_LENGTH:2 * HashPoint.HASH_LENGTH], resolver),
NullableReferenceFactory( NullableReferenceFactory(
StaticFactory(Subject) StaticFactory(Subject)
).from_bytes(source[2 * HashPoint.HASH_LENGTH:3 * HashPoint.HASH_LENGTH]), ).from_bytes(source[2 * HashPoint.HASH_LENGTH:3 * HashPoint.HASH_LENGTH], resolver),
HashPoint(Integer.factory(), source[3 * HashPoint.HASH_LENGTH:], Null()) ResolverOrigin(Integer.factory(), source[3 * HashPoint.HASH_LENGTH:], resolver).hash_point()
) )
def loose(self) -> 'BankState': def without_miner(self) -> 'BankState':
return BankState( return BankState(
self.minted, self.minted,
self.used, self.used,
@ -78,20 +80,18 @@ class BankState(RecursiveMentionable, StaticMentionable):
self.length self.length
) )
def advance(self, resolver: HashResolver) -> 'BankState': def advance(self) -> 'BankState':
assert isinstance(resolver, HashResolver)
return BankState( return BankState(
self.minted, self.minted,
self.used, self.used,
NullableReference(Null(), self.miner.factory), NullableReference(Null(), self.miner.factory),
HashPoint.of(Integer(resolver.resolve(self.length).integer + 1)) HashPoint.of(Integer(self.length.resolve().integer + 1))
) )
def push(self, transaction: HashPoint[Transaction], resolver: HashResolver) -> 'BankState': def push(self, transaction: HashPoint[Transaction]) -> 'BankState':
assert isinstance(transaction, HashPoint) assert isinstance(transaction, HashPoint)
assert isinstance(resolver, HashResolver)
transaction_resolved = resolver.resolve(transaction) transaction_resolved = transaction.resolve()
assert isinstance(transaction_resolved, Transaction) assert isinstance(transaction_resolved, Transaction)
miner: Nullable[HashPoint[Subject]] = self.miner.reference miner: Nullable[HashPoint[Subject]] = self.miner.reference
@ -103,21 +103,21 @@ class BankState(RecursiveMentionable, StaticMentionable):
else: else:
raise TypeError raise TypeError
assert transaction_resolved.verify(resolver, mint) assert transaction_resolved.verify(mint)
transaction_data: TransactionData = resolver.resolve(transaction_resolved.data) transaction_data: TransactionData = transaction_resolved.data.resolve()
assert isinstance(transaction_data, TransactionData) assert isinstance(transaction_data, TransactionData)
minted: ActiveBinaryTree[Coin, Integer] = ActiveBinaryTree( minted: ActiveBinaryTree[Coin, Integer] = ActiveBinaryTree(
AVLBTBP(HashComparator(resolver, Fail())), self.minted AVLBTBP(HashComparator(Fail())), self.minted
) )
assert isinstance(minted, ActiveBinaryTree) assert isinstance(minted, ActiveBinaryTree)
used: ActiveBinaryTree[Coin, Integer] = ActiveBinaryTree( used: ActiveBinaryTree[Coin, Integer] = ActiveBinaryTree(
AVLBTBP(HashComparator(resolver, Fail())), self.used AVLBTBP(HashComparator(Fail())), self.used
) )
assert isinstance(used, ActiveBinaryTree) assert isinstance(used, ActiveBinaryTree)
in_coin: HashPoint[Coin] in_coin: HashPoint[Coin]
for in_coin in transaction_data.iter_in_coins(resolver): for in_coin in transaction_data.iter_in_coins():
assert isinstance(in_coin, HashPoint) assert isinstance(in_coin, HashPoint)
assert isinstance(minted.query_tree().query(in_coin), NotNull) assert isinstance(minted.query_tree().query(in_coin), NotNull)
assert isinstance(used.query_tree().query(in_coin), Null) assert isinstance(used.query_tree().query(in_coin), Null)
@ -125,7 +125,7 @@ class BankState(RecursiveMentionable, StaticMentionable):
assert isinstance(used, ActiveBinaryTree) assert isinstance(used, ActiveBinaryTree)
coin: Coin coin: Coin
for coin, miner in transaction_resolved.iter_coins(resolver, mint, miner): for coin, miner in transaction_resolved.iter_coins(mint, miner):
assert isinstance(coin, Coin) assert isinstance(coin, Coin)
assert isinstance(miner, Nullable) assert isinstance(miner, Nullable)
assert isinstance(minted.query_tree().query(HashPoint.of(coin)), Null) assert isinstance(minted.query_tree().query(HashPoint.of(coin)), Null)
@ -139,17 +139,16 @@ class BankState(RecursiveMentionable, StaticMentionable):
self.length self.length
) )
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'(' \ return f'(' \
f'{tabulate(tab + 1)}bank' \ f'{tabulate(tab + 1)}bank' \
f'{tabulate(tab + 1)}(miner)' \ f'{tabulate(tab + 1)}(miner)' \
f'{tabulate(tab + 1)}{self.miner.str(resolver, tab + 1)}' \ f'{tabulate(tab + 1)}{self.miner.str(tab + 1)}' \
f'{tabulate(tab + 1)}(minted)' \ f'{tabulate(tab + 1)}(minted)' \
f'{tabulate(tab + 1)}{self.minted.str(resolver, tab + 1)}' \ f'{tabulate(tab + 1)}{self.minted.str(tab + 1)}' \
f'{tabulate(tab + 1)}(used)' \ f'{tabulate(tab + 1)}(used)' \
f'{tabulate(tab + 1)}{self.used.str(resolver, tab + 1)}' \ f'{tabulate(tab + 1)}{self.used.str(tab + 1)}' \
f'{tabulate(tab + 1)}(length)' \ f'{tabulate(tab + 1)}(length)' \
f'{tabulate(tab + 1)}{resolver.resolve(self.length)}' \ f'{tabulate(tab + 1)}{self.length.resolve()}' \
f'{tabulate(tab)})' f'{tabulate(tab)})'

View File

@ -28,7 +28,7 @@ class Signature(Atomic):
) )
@classmethod @classmethod
def from_bytes(cls, source: bytes) -> 'Signature': def _from_bytes(cls, source: bytes) -> 'Signature':
assert isinstance(source, bytes) assert isinstance(source, bytes)
return cls(source) return cls(source)

View File

@ -14,7 +14,7 @@ class Subject(Atomic):
assert isinstance(self.public_key, PublicKey) assert isinstance(self.public_key, PublicKey)
@classmethod @classmethod
def from_bytes(cls, source: bytes) -> 'Subject': def _from_bytes(cls, source: bytes) -> 'Subject':
assert isinstance(source, bytes) assert isinstance(source, bytes)
return cls(VerifyKey(source)) return cls(VerifyKey(source))

View File

@ -13,6 +13,7 @@ from rainbowadn.hashing.nullability.nullable import Nullable
from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory from rainbowadn.hashing.nullability.nullablereference import NullableReference, NullableReferenceFactory
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin
from rainbowadn.hashing.static import StaticMentionable from rainbowadn.hashing.static import StaticMentionable
from rainbowadn.v13.signature import Signature from rainbowadn.v13.signature import Signature
from rainbowadn.v13.subject import Subject from rainbowadn.v13.subject import Subject
@ -33,6 +34,8 @@ class CoinData(RecursiveMentionable, StaticMentionable):
@classmethod @classmethod
def of(cls, owner: Subject, value: int) -> 'CoinData': def of(cls, owner: Subject, value: int) -> 'CoinData':
assert isinstance(owner, Subject)
assert isinstance(value, int)
return cls(HashPoint.of(owner), HashPoint.of(Integer(value))) return cls(HashPoint.of(owner), HashPoint.of(Integer(value)))
def points(self) -> Iterable[HashPoint]: def points(self) -> Iterable[HashPoint]:
@ -42,18 +45,18 @@ class CoinData(RecursiveMentionable, StaticMentionable):
return bytes(self.owner) + bytes(self.value) return bytes(self.owner) + bytes(self.value)
@classmethod @classmethod
def from_bytes(cls, source: bytes) -> 'CoinData': def from_bytes(cls, source: bytes, resolver: HashResolver) -> 'CoinData':
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return cls( return cls(
HashPoint(Subject.factory(), source[:HashPoint.HASH_LENGTH], Null()), ResolverOrigin(Subject.factory(), source[:HashPoint.HASH_LENGTH], resolver).hash_point(),
HashPoint(Integer.factory(), source[HashPoint.HASH_LENGTH:], Null()), ResolverOrigin(Integer.factory(), source[HashPoint.HASH_LENGTH:], resolver).hash_point(),
) )
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'{resolver.resolve(self.owner)}' \ return f'{self.owner.resolve()}' \
f'{tabulate(tab)}{resolver.resolve(self.value)}' f'{tabulate(tab)}{self.value.resolve()}'
class Coin(RecursiveMentionable, StaticMentionable): class Coin(RecursiveMentionable, StaticMentionable):
@ -77,25 +80,27 @@ class Coin(RecursiveMentionable, StaticMentionable):
return bytes(self.data) + bytes(self.origin) + bytes(self.index) return bytes(self.data) + bytes(self.origin) + bytes(self.index)
@classmethod @classmethod
def from_bytes(cls, source: bytes) -> 'Coin': def from_bytes(cls, source: bytes, resolver: HashResolver) -> 'Coin':
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return cls( return cls(
HashPoint(CoinData.factory(), source[:HashPoint.HASH_LENGTH], Null()), ResolverOrigin(CoinData.factory(), source[:HashPoint.HASH_LENGTH], resolver).hash_point(),
HashPoint(Transaction.factory(), source[HashPoint.HASH_LENGTH:2 * HashPoint.HASH_LENGTH], Null()), ResolverOrigin(
HashPoint(Integer.factory(), source[2 * HashPoint.HASH_LENGTH:], Null()), Transaction.factory(), source[HashPoint.HASH_LENGTH:2 * HashPoint.HASH_LENGTH], resolver
).hash_point(),
ResolverOrigin(Integer.factory(), source[2 * HashPoint.HASH_LENGTH:], resolver).hash_point(),
) )
def __str__(self): def __str__(self):
return f'(coin)' return f'(coin)'
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'(' \ return f'(' \
f'{tabulate(tab + 1)}coin' \ f'{tabulate(tab + 1)}coin' \
f'{tabulate(tab + 1)}{hash_point_format(self.data, resolver, tab + 1)}' \ f'{tabulate(tab + 1)}{hash_point_format(self.data, tab + 1)}' \
f'{tabulate(tab + 1)}(origin)' \ f'{tabulate(tab + 1)}(origin)' \
f'{tabulate(tab + 1)}{resolver.resolve(self.index)}' \ f'{tabulate(tab + 1)}{self.index.resolve()}' \
f'{tabulate(tab)})' f'{tabulate(tab)})'
@ -119,24 +124,23 @@ class TransactionData(RecursiveMentionable, StaticMentionable):
return bytes(self.in_coins) + bytes(self.out_coins) return bytes(self.in_coins) + bytes(self.out_coins)
@classmethod @classmethod
def from_bytes(cls, source: bytes) -> 'TransactionData': def from_bytes(cls, source: bytes, resolver: HashResolver) -> 'TransactionData':
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return cls( return cls(
NullableReferenceFactory( NullableReferenceFactory(
StackFactory(Coin.factory()).loose() StackFactory(Coin.factory()).loose()
).from_bytes(source[:HashPoint.HASH_LENGTH]), ).from_bytes(source[:HashPoint.HASH_LENGTH], resolver),
NullableReferenceFactory( NullableReferenceFactory(
StackFactory(CoinData.factory()).loose() StackFactory(CoinData.factory()).loose()
).from_bytes(source[HashPoint.HASH_LENGTH:]), ).from_bytes(source[HashPoint.HASH_LENGTH:], resolver),
) )
def _verify_signatures( def _verify_signatures(
self, self,
resolver: HashResolver,
in_coins: NullableReference[Stack[Coin]], in_coins: NullableReference[Stack[Coin]],
signatures: NullableReference[Stack[Signature]], signatures: NullableReference[Stack[Signature]],
) -> bool: ) -> bool:
assert isinstance(resolver, HashResolver)
assert isinstance(in_coins, NullableReference) assert isinstance(in_coins, NullableReference)
assert isinstance(signatures, NullableReference) assert isinstance(signatures, NullableReference)
if isinstance(in_coins.reference, Null): if isinstance(in_coins.reference, Null):
@ -144,17 +148,17 @@ class TransactionData(RecursiveMentionable, StaticMentionable):
return True return True
elif isinstance(in_coins.reference, NotNull): elif isinstance(in_coins.reference, NotNull):
assert isinstance(signatures.reference, NotNull) assert isinstance(signatures.reference, NotNull)
in_coins_stack: Stack[Coin] = resolver.resolve(in_coins.reference.value) in_coins_stack: Stack[Coin] = in_coins.reference.value.resolve()
assert isinstance(in_coins_stack, Stack) assert isinstance(in_coins_stack, Stack)
signatures_stack: Stack[Signature] = resolver.resolve(signatures.reference.value) signatures_stack: Stack[Signature] = signatures.reference.value.resolve()
assert isinstance(signatures_stack, Stack) assert isinstance(signatures_stack, Stack)
coin: Coin = resolver.resolve(in_coins_stack.element) coin: Coin = in_coins_stack.element.resolve()
assert isinstance(coin, Coin) assert isinstance(coin, Coin)
coin_data: CoinData = resolver.resolve(coin.data) coin_data: CoinData = coin.data.resolve()
assert isinstance(coin_data, CoinData) assert isinstance(coin_data, CoinData)
owner: Subject = resolver.resolve(coin_data.owner) owner: Subject = coin_data.owner.resolve()
assert isinstance(owner, Subject) assert isinstance(owner, Subject)
signature: Signature = resolver.resolve(signatures_stack.element) signature: Signature = signatures_stack.element.resolve()
assert isinstance(signature, Signature) assert isinstance(signature, Signature)
return signature.verify( return signature.verify(
owner, owner,
@ -163,12 +167,11 @@ class TransactionData(RecursiveMentionable, StaticMentionable):
else: else:
raise TypeError raise TypeError
def iter_in_coins(self, resolver: HashResolver) -> Iterable[HashPoint[Coin]]: def iter_in_coins(self) -> Iterable[HashPoint[Coin]]:
assert isinstance(resolver, HashResolver)
in_coins: NullableReference[Stack[Coin]] = self.in_coins in_coins: NullableReference[Stack[Coin]] = self.in_coins
assert isinstance(in_coins, NullableReference) assert isinstance(in_coins, NullableReference)
while isinstance(in_coins.reference, NotNull): while isinstance(in_coins.reference, NotNull):
in_coins_stack: Stack[Coin] = resolver.resolve(in_coins.reference.value) in_coins_stack: Stack[Coin] = in_coins.reference.value.resolve()
assert isinstance(in_coins_stack, Stack) assert isinstance(in_coins_stack, Stack)
coin: HashPoint[Coin] = in_coins_stack.element coin: HashPoint[Coin] = in_coins_stack.element
assert isinstance(coin, HashPoint) assert isinstance(coin, HashPoint)
@ -177,27 +180,19 @@ class TransactionData(RecursiveMentionable, StaticMentionable):
assert isinstance(in_coins, NullableReference) assert isinstance(in_coins, NullableReference)
assert isinstance(in_coins.reference, Null) assert isinstance(in_coins.reference, Null)
def _total_in(self, resolver: HashResolver) -> int: def _total_in(self) -> int:
assert isinstance(resolver, HashResolver)
total_in = 0 total_in = 0
coin: HashPoint[Coin] coin: HashPoint[Coin]
for coin in self.iter_in_coins(resolver): for coin in self.iter_in_coins():
assert isinstance(coin, HashPoint) assert isinstance(coin, HashPoint)
total_in += resolver.resolve( total_in += coin.resolve().data.resolve().value.resolve().integer
resolver.resolve(
resolver.resolve(
coin
).data
).value
).integer
return total_in return total_in
def iter_out_coins(self, resolver: HashResolver) -> Iterable[HashPoint[CoinData]]: def iter_out_coins(self) -> Iterable[HashPoint[CoinData]]:
assert isinstance(resolver, HashResolver)
out_coins: NullableReference[Stack[CoinData]] = self.out_coins out_coins: NullableReference[Stack[CoinData]] = self.out_coins
assert isinstance(out_coins, NullableReference) assert isinstance(out_coins, NullableReference)
while isinstance(out_coins.reference, NotNull): while isinstance(out_coins.reference, NotNull):
out_coins_stack: Stack[CoinData] = resolver.resolve(out_coins.reference.value) out_coins_stack: Stack[CoinData] = out_coins.reference.value.resolve()
assert isinstance(out_coins_stack, Stack) assert isinstance(out_coins_stack, Stack)
coin: HashPoint[CoinData] = out_coins_stack.element coin: HashPoint[CoinData] = out_coins_stack.element
assert isinstance(coin, HashPoint) assert isinstance(coin, HashPoint)
@ -206,48 +201,38 @@ class TransactionData(RecursiveMentionable, StaticMentionable):
assert isinstance(out_coins, NullableReference) assert isinstance(out_coins, NullableReference)
assert isinstance(out_coins.reference, Null) assert isinstance(out_coins.reference, Null)
def _total_out(self, resolver: HashResolver) -> int: def _total_out(self) -> int:
assert isinstance(resolver, HashResolver)
total_out = 0 total_out = 0
coin: HashPoint[CoinData] coin: HashPoint[CoinData]
for coin in self.iter_out_coins(resolver): for coin in self.iter_out_coins():
assert isinstance(coin, HashPoint) assert isinstance(coin, HashPoint)
total_out += resolver.resolve( total_out += coin.resolve().value.resolve().integer
resolver.resolve(
coin
).value
).integer
return total_out return total_out
def _verify_values(self, resolver: HashResolver, mint: int) -> bool: def _verify_values(self, mint: int) -> bool:
assert isinstance(resolver, HashResolver)
assert isinstance(mint, int) assert isinstance(mint, int)
assert self._total_out(resolver) <= self._total_in(resolver) + mint assert self._total_out() <= self._total_in() + mint
return True return True
def extra(self, resolver: HashResolver, mint: int) -> int: def extra(self, mint: int) -> int:
assert isinstance(resolver, HashResolver)
assert isinstance(mint, int) assert isinstance(mint, int)
return self._total_in(resolver) + mint - self._total_out(resolver) return self._total_in() + mint - self._total_out()
def verify( def verify(
self, self,
resolver: HashResolver,
signatures: NullableReference[Stack[Signature]], signatures: NullableReference[Stack[Signature]],
mint: int mint: int
) -> bool: ) -> bool:
assert isinstance(resolver, HashResolver)
assert isinstance(signatures, NullableReference) assert isinstance(signatures, NullableReference)
assert isinstance(mint, int) assert isinstance(mint, int)
return self._verify_signatures(resolver, self.in_coins, signatures) and self._verify_values(resolver, mint) return self._verify_signatures(self.in_coins, signatures) and self._verify_values(mint)
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'(in)' \ return f'(in)' \
f'{tabulate(tab)}{self.in_coins.str(resolver, tab)}' \ f'{tabulate(tab)}{self.in_coins.str(tab)}' \
f'{tabulate(tab)}(out)' \ f'{tabulate(tab)}(out)' \
f'{tabulate(tab)}{self.out_coins.str(resolver, tab)}' f'{tabulate(tab)}{self.out_coins.str(tab)}'
class Transaction(RecursiveMentionable, StaticMentionable): class Transaction(RecursiveMentionable, StaticMentionable):
@ -270,33 +255,31 @@ class Transaction(RecursiveMentionable, StaticMentionable):
return bytes(self.data) + bytes(self.signatures) return bytes(self.data) + bytes(self.signatures)
@classmethod @classmethod
def from_bytes(cls, source: bytes) -> 'Transaction': def from_bytes(cls, source: bytes, resolver: HashResolver) -> 'Transaction':
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
signature_factory: RainbowFactory[Signature] = Signature.factory() signature_factory: RainbowFactory[Signature] = Signature.factory()
assert isinstance(signature_factory, RainbowFactory) assert isinstance(signature_factory, RainbowFactory)
stack_factory: RainbowFactory[Stack[Signature]] = StackFactory(signature_factory).loose() stack_factory: RainbowFactory[Stack[Signature]] = StackFactory(signature_factory).loose()
assert isinstance(stack_factory, RainbowFactory) assert isinstance(stack_factory, RainbowFactory)
return cls( return cls(
HashPoint(TransactionData.factory(), source[:HashPoint.HASH_LENGTH], Null()), ResolverOrigin(TransactionData.factory(), source[:HashPoint.HASH_LENGTH], resolver).hash_point(),
NullableReferenceFactory(stack_factory).from_bytes(source[HashPoint.HASH_LENGTH:]), NullableReferenceFactory(stack_factory).from_bytes(source[HashPoint.HASH_LENGTH:], resolver),
) )
def iter_coins( def iter_coins(
self, self,
resolver: HashResolver,
mint: int, mint: int,
miner: Nullable[HashPoint[Subject]] miner: Nullable[HashPoint[Subject]]
) -> Iterable[tuple[Coin, Nullable[HashPoint[Subject]]]]: ) -> Iterable[tuple[Coin, Nullable[HashPoint[Subject]]]]:
transaction_data = resolver.resolve(self.data) transaction_data = self.data.resolve()
assert isinstance(transaction_data, TransactionData) assert isinstance(transaction_data, TransactionData)
index = 0 index = 0
out_coin: HashPoint[CoinData] out_coin: HashPoint[CoinData]
for out_coin in transaction_data.iter_out_coins(resolver): for out_coin in transaction_data.iter_out_coins():
assert isinstance(out_coin, HashPoint) assert isinstance(out_coin, HashPoint)
if isinstance(miner, Null): if isinstance(miner, Null):
miner = NotNull( miner = NotNull(out_coin.resolve().owner)
resolver.resolve(out_coin).owner
)
assert isinstance(miner, Nullable) assert isinstance(miner, Nullable)
coin: Coin = Coin(out_coin, self.hash_point, HashPoint.of(Integer(index))) coin: Coin = Coin(out_coin, self.hash_point, HashPoint.of(Integer(index)))
assert isinstance(coin, Coin) assert isinstance(coin, Coin)
@ -307,7 +290,7 @@ class Transaction(RecursiveMentionable, StaticMentionable):
HashPoint.of( HashPoint.of(
CoinData( CoinData(
miner.value, miner.value,
HashPoint.of(Integer(transaction_data.extra(resolver, mint))) HashPoint.of(Integer(transaction_data.extra(mint)))
) )
), ),
self.hash_point, self.hash_point,
@ -318,29 +301,28 @@ class Transaction(RecursiveMentionable, StaticMentionable):
def coins( def coins(
self, self,
resolver: HashResolver,
mint: int, mint: int,
miner: Nullable[HashPoint[Subject]] miner: Nullable[HashPoint[Subject]]
) -> list[Coin]: ) -> list[Coin]:
return [coin for coin, _ in self.iter_coins(resolver, mint, miner)]
def verify(self, resolver: HashResolver, mint: int):
assert isinstance(resolver, HashResolver)
assert isinstance(mint, int) assert isinstance(mint, int)
data: TransactionData = resolver.resolve(self.data) assert isinstance(miner, Nullable)
return [coin for coin, _ in self.iter_coins(mint, miner)]
def verify(self, mint: int):
assert isinstance(mint, int)
data: TransactionData = self.data.resolve()
assert isinstance(data, TransactionData) assert isinstance(data, TransactionData)
return data.verify(resolver, self.signatures, mint) return data.verify(self.signatures, mint)
def __str__(self): def __str__(self):
return f'(transaction)' return f'(transaction)'
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'(' \ return f'(' \
f'{tabulate(tab + 1)}transaction' \ f'{tabulate(tab + 1)}transaction' \
f'{tabulate(tab + 1)}{hash_point_format(self.data, resolver, tab + 1)}' \ f'{tabulate(tab + 1)}{hash_point_format(self.data, tab + 1)}' \
f'{tabulate(tab + 1)}{self.signatures.str(resolver, tab + 1)}' \ f'{tabulate(tab + 1)}{self.signatures.str(tab + 1)}' \
f'{tabulate(tab)})' f'{tabulate(tab)})'
@classmethod @classmethod

View File

@ -4,16 +4,16 @@ from typing import Iterable, Sequence
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.hashing.localmetaorigin import LocalMetaOrigin
from rainbowadn.hashing.nullability.null import Null from rainbowadn.hashing.localorigin import LocalOrigin
from rainbowadn.hashing.nullability.nullable import Nullable from rainbowadn.hashing.metaorigin import MetaOrigin
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolvermetaorigin import ResolverMetaOrigin
from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres
__all__ = ('WeakReferenceIndexSetBTree', 'WrisbtFactory',) __all__ = ('WeakReferenceIndexSetBTree', 'WrisbtFactory',)
from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres
class WeakReferenceIndexSetBTree(RecursiveMentionable): class WeakReferenceIndexSetBTree(RecursiveMentionable):
def __init__( def __init__(
@ -22,7 +22,7 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
height: int, height: int,
parametres: WrisbtParametres, parametres: WrisbtParametres,
root: bool, root: bool,
cache: tuple[HashPoint['WeakReferenceIndexSetBTree'], ...] cache: tuple[MetaOrigin['WeakReferenceIndexSetBTree'], ...]
): ):
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(height, int) assert isinstance(height, int)
@ -63,17 +63,13 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
assert len(cache) == self.children assert len(cache) == self.children
self.cache = cache self.cache = cache
if self.balanced():
self._hash_point = HashPoint.of(self)
def hash_point(self) -> HashPoint['WeakReferenceIndexSetBTree']:
return self._hash_point
def full(self) -> bool: def full(self) -> bool:
return self.keys == 2 * self.keymin + 1 return self.keys == 2 * self.keymin + 1
def bytes_no(self, index: int, start: int, size: int) -> bytes: def bytes_no(self, index: int, start: int, size: int) -> bytes:
assert isinstance(index, int) assert isinstance(index, int)
assert isinstance(start, int)
assert isinstance(size, int)
assert 0 <= index < self.length assert 0 <= index < self.length
return self.source[start + size * index:start + size * (index + 1)] return self.source[start + size * index:start + size * (index + 1)]
@ -82,25 +78,21 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
assert 0 <= index < self.keys assert 0 <= index < self.keys
return self.bytes_no(index, 0, self.keysize) return self.bytes_no(index, 0, self.keysize)
def cached_no(self, index: int) -> Nullable['WeakReferenceIndexSetBTree']: def cached_no(self, index: int) -> MetaOrigin['WeakReferenceIndexSetBTree']:
assert isinstance(index, int) assert isinstance(index, int)
assert 0 <= index < self.children assert 0 <= index < self.children
assert not self.leaf assert not self.leaf
cached: Nullable[WeakReferenceIndexSetBTree] = self.cache[index] cached: MetaOrigin[WeakReferenceIndexSetBTree] = self.cache[index]
assert isinstance(cached, Nullable) assert isinstance(cached, MetaOrigin)
if isinstance(cached, NotNull):
tree: WeakReferenceIndexSetBTree = cached.value
assert self.bytes_no(index, self.keyend, HashPoint.HASH_LENGTH) == tree.hash_point().point
return cached return cached
def child_no(self, index: int) -> HashPoint['WeakReferenceIndexSetBTree']: def child_no(self, index: int) -> HashPoint['WeakReferenceIndexSetBTree']:
assert isinstance(index, int) assert isinstance(index, int)
assert 0 <= index < self.children assert 0 <= index < self.children
assert not self.leaf assert not self.leaf
return HashPoint( return self.cached_no(index).hash_point(
WrisbtFactory(self.height - 1, self.parametres, False), WrisbtFactory(self.height - 1, self.parametres, False),
self.bytes_no(index, self.keyend, HashPoint.HASH_LENGTH), self.bytes_no(index, self.keyend, HashPoint.HASH_LENGTH)
self.cached_no(index)
) )
def balanced(self) -> bool: def balanced(self) -> bool:
@ -159,8 +151,7 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
self.range(self.keymin + 1, 2 * self.keymin + 1), self.range(self.keymin + 1, 2 * self.keymin + 1),
) )
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
formatted = f'{self.height}' \ formatted = f'{self.height}' \
@ -168,13 +159,12 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
for key_index in range(self.keys): for key_index in range(self.keys):
formatted += f'{tabulate(tab + 1)}{self.key_no(key_index).hex()}' formatted += f'{tabulate(tab + 1)}{self.key_no(key_index).hex()}'
for child_index in range(self.children): for child_index in range(self.children):
formatted += f'{tabulate(tab + 1)}{hash_point_format(self.child_no(child_index), resolver, tab + 1)}' formatted += f'{tabulate(tab + 1)}{hash_point_format(self.child_no(child_index), tab + 1)}'
return f'{formatted}' \ return f'{formatted}' \
f'{tabulate(tab)})' f'{tabulate(tab)})'
def contains(self, resolver: HashResolver, key: bytes) -> bool: def contains(self, key: bytes) -> bool:
assert isinstance(resolver, HashResolver)
assert isinstance(key, bytes) assert isinstance(key, bytes)
assert len(key) == self.keysize assert len(key) == self.keysize
@ -191,12 +181,11 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
assert key > self.key_no(index - 1) assert key > self.key_no(index - 1)
if self.leaf: if self.leaf:
return False return False
child: WeakReferenceIndexSetBTree = resolver.resolve(self.child_no(index)) child: WeakReferenceIndexSetBTree = self.child_no(index).resolve()
assert isinstance(child, WeakReferenceIndexSetBTree) assert isinstance(child, WeakReferenceIndexSetBTree)
return child.contains(resolver, key) return child.contains(key)
def add(self, resolver: HashResolver, key: bytes) -> 'WeakReferenceIndexSetBTree': def add(self, key: bytes) -> 'WeakReferenceIndexSetBTree':
assert isinstance(resolver, HashResolver)
assert isinstance(key, bytes) assert isinstance(key, bytes)
assert len(key) == self.keysize assert len(key) == self.keysize
@ -219,9 +208,9 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
self.root, self.root,
() ()
) )
child: WeakReferenceIndexSetBTree = resolver.resolve(self.child_no(index)) child: WeakReferenceIndexSetBTree = self.child_no(index).resolve()
assert isinstance(child, WeakReferenceIndexSetBTree) assert isinstance(child, WeakReferenceIndexSetBTree)
child: WeakReferenceIndexSetBTree = child.add(resolver, key) child: WeakReferenceIndexSetBTree = child.add(key)
assert isinstance(child, WeakReferenceIndexSetBTree) assert isinstance(child, WeakReferenceIndexSetBTree)
if child.full(): if child.full():
left, middle, right = child.split() left, middle, right = child.split()
@ -236,16 +225,22 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
+ +
self.source[self.keysize * index:self.keyend + HashPoint.HASH_LENGTH * index] self.source[self.keysize * index:self.keyend + HashPoint.HASH_LENGTH * index]
+ +
bytes(left.hash_point()) bytes(HashPoint.of(left))
+ +
bytes(right.hash_point()) bytes(HashPoint.of(right))
+ +
self.source[self.keyend + HashPoint.HASH_LENGTH * (index + 1):] self.source[self.keyend + HashPoint.HASH_LENGTH * (index + 1):]
), ),
self.height, self.height,
self.parametres, self.parametres,
self.root, self.root,
self.cache[:index] + (NotNull(left), NotNull(right)) + self.cache[index + 1:] (
self.cache[:index]
+
(LocalMetaOrigin(LocalOrigin(left)), LocalMetaOrigin(LocalOrigin(right)))
+
self.cache[index + 1:]
)
) )
else: else:
return WeakReferenceIndexSetBTree( return WeakReferenceIndexSetBTree(
@ -259,20 +254,26 @@ class WeakReferenceIndexSetBTree(RecursiveMentionable):
self.height, self.height,
self.parametres, self.parametres,
self.root, self.root,
self.cache[:index] + (NotNull(child),) + self.cache[index + 1:] (
self.cache[:index]
+
(LocalMetaOrigin(LocalOrigin(child)),)
+
self.cache[index + 1:]
)
) )
def iter_keys(self, resolver: HashResolver) -> Iterable[bytes]: def iter_keys(self) -> Iterable[bytes]:
if self.leaf: if self.leaf:
for key_index in range(self.keys): for key_index in range(self.keys):
yield self.key_no(key_index) yield self.key_no(key_index)
else: else:
for index in range(self.length): for index in range(self.keys * 2 + 1):
real_index, mode = divmod(index, 2) real_index, mode = divmod(index, 2)
if mode: if mode:
yield self.key_no(real_index) yield self.key_no(real_index)
else: else:
yield from resolver.resolve(self.child_no(real_index)).iter_keys(resolver) yield from self.child_no(real_index).resolve().iter_keys()
class KeyView(Sequence[WeakReferenceIndexSetBTree]): class KeyView(Sequence[WeakReferenceIndexSetBTree]):
@ -297,12 +298,15 @@ class WrisbtFactory(RainbowFactory[WeakReferenceIndexSetBTree]):
self.parametres = parametres self.parametres = parametres
self.root = root self.root = root
def from_bytes(self, source: bytes) -> WeakReferenceIndexSetBTree: def from_bytes(self, source: bytes, resolver: HashResolver) -> WeakReferenceIndexSetBTree:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return WeakReferenceIndexSetBTree( return WeakReferenceIndexSetBTree(
source, source,
self.height, self.height,
self.parametres, self.parametres,
self.root, self.root,
(Null(),) * (len(source) // (HashPoint.HASH_LENGTH + self.parametres.keysize) + 1) if self.height else () (
ResolverMetaOrigin(resolver),
) * (len(source) // (HashPoint.HASH_LENGTH + self.parametres.keysize) + 1) if self.height else ()
) )

View File

@ -2,7 +2,6 @@ from typing import Generic, TypeVar
from rainbowadn.chain.blockchainprotocol import BlockChainProtocol from rainbowadn.chain.blockchainprotocol import BlockChainProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.wrisbt.wrisbtindex import WrisbtIndex, WrisbtIndexFactory from rainbowadn.wrisbt.wrisbtindex import WrisbtIndex, WrisbtIndexFactory
from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres
@ -24,7 +23,6 @@ class WrisbtChainProtocol(
): ):
def __init__( def __init__(
self, self,
resolver: HashResolver,
total_factory: RainbowFactory[TargetType], total_factory: RainbowFactory[TargetType],
keymin: int keymin: int
): ):
@ -33,7 +31,7 @@ class WrisbtChainProtocol(
assert keymin >= 2 assert keymin >= 2
self.keymin = keymin self.keymin = keymin
super().__init__( super().__init__(
WrisbtProtocol(resolver, keymin), WrisbtProtocol(keymin),
total_factory, total_factory,
WrisbtIndexFactory(keymin) WrisbtIndexFactory(keymin)
) )
@ -43,4 +41,5 @@ class WrisbtChainProtocol(
return WrisbtRootFactory(WrisbtParametres(self.keymin, HashPoint.HASH_LENGTH)) return WrisbtRootFactory(WrisbtParametres(self.keymin, HashPoint.HASH_LENGTH))
def actual_state(self, state: WrisbtIndex) -> HashPoint[WrisbtRoot]: def actual_state(self, state: WrisbtIndex) -> HashPoint[WrisbtRoot]:
assert isinstance(state, WrisbtIndex)
return state.total return state.total

View File

@ -3,9 +3,9 @@ from typing import Iterable
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.null import Null
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin
from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres
from rainbowadn.wrisbt.wrisbtroot import WrisbtRoot, WrisbtRootFactory from rainbowadn.wrisbt.wrisbtroot import WrisbtRoot, WrisbtRootFactory
@ -36,12 +36,11 @@ class WrisbtIndex(RecursiveMentionable):
def __factory__(self) -> RainbowFactory['WrisbtIndex']: def __factory__(self) -> RainbowFactory['WrisbtIndex']:
return WrisbtIndexFactory(self.keymin) return WrisbtIndexFactory(self.keymin)
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'(index)' \ return f'(index)' \
f'{tabulate(tab)}{hash_point_format(self.total, resolver, tab)}' \ f'{tabulate(tab)}{hash_point_format(self.total, tab)}' \
f'{tabulate(tab)}{hash_point_format(self.delta, resolver, tab)}' f'{tabulate(tab)}{hash_point_format(self.delta, tab)}'
class WrisbtIndexFactory(RainbowFactory[WrisbtIndex]): class WrisbtIndexFactory(RainbowFactory[WrisbtIndex]):
@ -54,10 +53,11 @@ class WrisbtIndexFactory(RainbowFactory[WrisbtIndex]):
) )
assert isinstance(self.root_factory, RainbowFactory) assert isinstance(self.root_factory, RainbowFactory)
def from_bytes(self, source: bytes) -> WrisbtIndex: def from_bytes(self, source: bytes, resolver: HashResolver) -> WrisbtIndex:
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver)
return WrisbtIndex( return WrisbtIndex(
HashPoint(self.root_factory, source[:HashPoint.HASH_LENGTH], Null()), ResolverOrigin(self.root_factory, source[:HashPoint.HASH_LENGTH], resolver).hash_point(),
HashPoint(self.root_factory, source[HashPoint.HASH_LENGTH:], Null()), ResolverOrigin(self.root_factory, source[HashPoint.HASH_LENGTH:], resolver).hash_point(),
self.keymin self.keymin
) )

View File

@ -2,7 +2,6 @@ from typing import TypeVar
from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol from rainbowadn.chain.states.activestateprotocol import ActiveStateProtocol
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.wrisbt.wrisbtindex import WrisbtIndex from rainbowadn.wrisbt.wrisbtindex import WrisbtIndex
from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres
from rainbowadn.wrisbt.wrisbtroot import WrisbtRoot from rainbowadn.wrisbt.wrisbtroot import WrisbtRoot
@ -13,12 +12,10 @@ TargetType = TypeVar('TargetType')
class WrisbtProtocol(ActiveStateProtocol[TargetType, WrisbtIndex]): class WrisbtProtocol(ActiveStateProtocol[TargetType, WrisbtIndex]):
def __init__(self, resolver: HashResolver, keymin: int): def __init__(self, keymin: int):
assert isinstance(resolver, HashResolver)
assert isinstance(keymin, int) assert isinstance(keymin, int)
assert keymin >= 2 assert keymin >= 2
self.keymin = keymin self.keymin = keymin
super().__init__(resolver)
def _initial_state(self) -> HashPoint[WrisbtIndex]: def _initial_state(self) -> HashPoint[WrisbtIndex]:
return HashPoint.of( return HashPoint.of(
@ -36,18 +33,18 @@ class WrisbtProtocol(ActiveStateProtocol[TargetType, WrisbtIndex]):
) -> HashPoint[WrisbtIndex]: ) -> HashPoint[WrisbtIndex]:
assert isinstance(previous, HashPoint) assert isinstance(previous, HashPoint)
assert isinstance(header, HashPoint) assert isinstance(header, HashPoint)
index = self.resolver.resolve(previous) index: WrisbtIndex = previous.resolve()
assert isinstance(index, WrisbtIndex) assert isinstance(index, WrisbtIndex)
empty: WrisbtRoot = WrisbtRoot.empty(WrisbtParametres(self.keymin, HashPoint.HASH_LENGTH)) empty: WrisbtRoot = WrisbtRoot.empty(WrisbtParametres(self.keymin, HashPoint.HASH_LENGTH))
assert isinstance(empty, WrisbtRoot) assert isinstance(empty, WrisbtRoot)
total: WrisbtRoot = self.resolver.resolve(index.total) total: WrisbtRoot = index.total.resolve()
assert isinstance(total, WrisbtRoot) assert isinstance(total, WrisbtRoot)
return HashPoint.of( return HashPoint.of(
WrisbtIndex( WrisbtIndex(
HashPoint.of(total.index(self.resolver, header, empty)), HashPoint.of(total.index(header, empty)),
HashPoint.of(empty.index(self.resolver, header, total)), HashPoint.of(empty.index(header, total)),
index.keymin index.keymin
) )
) )

View File

@ -5,16 +5,16 @@ from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate
from rainbowadn.hashing.hashmentionable import HashMentionable from rainbowadn.hashing.hashmentionable import HashMentionable
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.nullability.notnull import NotNull from rainbowadn.hashing.localmetaorigin import LocalMetaOrigin
from rainbowadn.hashing.nullability.null import Null from rainbowadn.hashing.localorigin import LocalOrigin
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
from rainbowadn.hashing.resolverorigin import ResolverOrigin
from rainbowadn.wrisbt.weakreferenceindexsetbtree import WeakReferenceIndexSetBTree, WrisbtFactory from rainbowadn.wrisbt.weakreferenceindexsetbtree import WeakReferenceIndexSetBTree, WrisbtFactory
from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres
__all__ = ('WrisbtRoot', 'WrisbtRootFactory',) __all__ = ('WrisbtRoot', 'WrisbtRootFactory',)
from rainbowadn.wrisbt.wrisbtparametres import WrisbtParametres
class WrisbtRoot(RecursiveMentionable): class WrisbtRoot(RecursiveMentionable):
def __init__(self, root: HashPoint[WeakReferenceIndexSetBTree], height: int, parametres: WrisbtParametres): def __init__(self, root: HashPoint[WeakReferenceIndexSetBTree], height: int, parametres: WrisbtParametres):
@ -39,29 +39,26 @@ class WrisbtRoot(RecursiveMentionable):
assert isinstance(parametres, WrisbtParametres) assert isinstance(parametres, WrisbtParametres)
return WrisbtRoot(HashPoint.of(WeakReferenceIndexSetBTree(b'', 0, parametres, True, ())), 0, parametres) return WrisbtRoot(HashPoint.of(WeakReferenceIndexSetBTree(b'', 0, parametres, True, ())), 0, parametres)
def str(self, resolver: HashResolver, tab: int) -> str: def str(self, tab: int) -> str:
assert isinstance(resolver, HashResolver)
assert isinstance(tab, int) assert isinstance(tab, int)
return f'(root)' \ return f'(root)' \
f'{tabulate(tab)}{self.height}' \ f'{tabulate(tab)}{self.height}' \
f'{tabulate(tab)}{hash_point_format(self.root, resolver, tab)}' f'{tabulate(tab)}{hash_point_format(self.root, tab)}'
def contains(self, resolver: HashResolver, key: bytes) -> bool: def contains(self, key: bytes) -> bool:
assert isinstance(resolver, HashResolver)
assert isinstance(key, bytes) assert isinstance(key, bytes)
assert len(key) == self.parametres.keysize assert len(key) == self.parametres.keysize
root: WeakReferenceIndexSetBTree = resolver.resolve(self.root) root: WeakReferenceIndexSetBTree = self.root.resolve()
assert isinstance(root, WeakReferenceIndexSetBTree) assert isinstance(root, WeakReferenceIndexSetBTree)
return root.contains(resolver, key) return root.contains(key)
def add(self, resolver: HashResolver, key: bytes) -> 'WrisbtRoot': def add(self, key: bytes) -> 'WrisbtRoot':
assert isinstance(resolver, HashResolver)
assert isinstance(key, bytes) assert isinstance(key, bytes)
assert len(key) == self.parametres.keysize assert len(key) == self.parametres.keysize
root: WeakReferenceIndexSetBTree = resolver.resolve(self.root).add(resolver, key) root: WeakReferenceIndexSetBTree = self.root.resolve().add(key)
assert isinstance(root, WeakReferenceIndexSetBTree) assert isinstance(root, WeakReferenceIndexSetBTree)
if root.full(): if root.full():
@ -74,7 +71,7 @@ class WrisbtRoot(RecursiveMentionable):
root.height + 1, root.height + 1,
root.parametres, root.parametres,
True, True,
(NotNull(left), NotNull(right)) (LocalMetaOrigin(LocalOrigin(left)), LocalMetaOrigin(LocalOrigin(right)))
) )
assert isinstance(root, WeakReferenceIndexSetBTree) assert isinstance(root, WeakReferenceIndexSetBTree)
return self.of(root) return self.of(root)
@ -84,28 +81,27 @@ class WrisbtRoot(RecursiveMentionable):
assert isinstance(root, WeakReferenceIndexSetBTree) assert isinstance(root, WeakReferenceIndexSetBTree)
return cls(HashPoint.of(root), root.height, root.parametres) return cls(HashPoint.of(root), root.height, root.parametres)
def keys(self, resolver: HashResolver) -> list[bytes]: def keys(self) -> list[bytes]:
return list(resolver.resolve(self.root).iter_keys(resolver)) return list(self.root.resolve().iter_keys())
def index( def index(
self, resolver: HashResolver, target: HashPoint, exclude: Optional['WrisbtRoot'] self, target: HashPoint, exclude: Optional['WrisbtRoot']
) -> 'WrisbtRoot': ) -> 'WrisbtRoot':
assert isinstance(resolver, HashResolver)
assert isinstance(target, HashPoint) assert isinstance(target, HashPoint)
if exclude is None: if exclude is None:
exclude = self.empty(self.parametres) exclude = self.empty(self.parametres)
assert isinstance(exclude, WrisbtRoot) assert isinstance(exclude, WrisbtRoot)
key: bytes = target.point key: bytes = target.point
assert isinstance(key, bytes) assert isinstance(key, bytes)
if exclude.contains(resolver, key) or self.contains(resolver, key): if exclude.contains(key) or self.contains(key):
return self return self
tree = self tree = self
value: HashMentionable = resolver.resolve(target) value: HashMentionable = target.resolve()
assert isinstance(value, HashMentionable) assert isinstance(value, HashMentionable)
if isinstance(value, RecursiveMentionable): if isinstance(value, RecursiveMentionable):
for hash_point in value.points(): for hash_point in value.points():
tree = tree.index(resolver, hash_point, exclude) tree = tree.index(hash_point, exclude)
tree = tree.add(resolver, key) tree = tree.add(key)
return tree return tree
@ -114,12 +110,15 @@ class WrisbtRootFactory(RainbowFactory[WrisbtRoot]):
assert isinstance(parametres, WrisbtParametres) assert isinstance(parametres, WrisbtParametres)
self.parametres = parametres self.parametres = parametres
def from_bytes(self, source: bytes) -> WrisbtRoot: def from_bytes(self, source: bytes, resolver: HashResolver) -> WrisbtRoot:
assert isinstance(source, bytes) assert isinstance(source, bytes)
height: int = Integer.from_bytes(source[HashPoint.HASH_LENGTH:]).integer assert isinstance(resolver, HashResolver)
height: int = Integer.from_bytes(source[HashPoint.HASH_LENGTH:], resolver).integer
assert isinstance(height, int) assert isinstance(height, int)
return WrisbtRoot( return WrisbtRoot(
HashPoint(WrisbtFactory(height, self.parametres, True), source[:HashPoint.HASH_LENGTH], Null()), ResolverOrigin(
WrisbtFactory(height, self.parametres, True), source[:HashPoint.HASH_LENGTH], resolver
).hash_point(),
height, height,
self.parametres self.parametres
) )