more inlining
This commit is contained in:
parent
280b035ba1
commit
e745eb7c54
@ -1,4 +1,4 @@
|
||||
from typing import Any, Generic, Iterable, TypeAlias, TypeVar
|
||||
from typing import Any, Generic, Iterable, Optional, TypeAlias, TypeVar
|
||||
|
||||
from rainbowadn.atomic import *
|
||||
from rainbowadn.collection.comparison import *
|
||||
@ -9,6 +9,7 @@ from rainbowadn.core import *
|
||||
from rainbowadn.flow.core import *
|
||||
from rainbowadn.flow.primitive import *
|
||||
from rainbowadn.flow.verification.core import *
|
||||
from rainbowadn.inlining import *
|
||||
from rainbowadn.nullability import *
|
||||
from ._binaryflow import *
|
||||
from ._flowtree import *
|
||||
@ -82,7 +83,7 @@ class FlowStandard(
|
||||
return await self.protocolized.tree.reference.str(tab)
|
||||
|
||||
|
||||
class FlowStandardFactory(RainbowFactory[FlowStandard[KeyT]], Generic[KeyT]):
|
||||
class FlowStandardFactory(Inlining[FlowStandard[KeyT]], Generic[KeyT]):
|
||||
def __init__(
|
||||
self,
|
||||
factory: RainbowFactory[BinaryTree[KeyMetadata[KeyT, Integer]]],
|
||||
@ -90,9 +91,14 @@ class FlowStandardFactory(RainbowFactory[FlowStandard[KeyT]], Generic[KeyT]):
|
||||
):
|
||||
assert isinstance(factory, RainbowFactory)
|
||||
assert isinstance(comparator, Comparator)
|
||||
self.factory = factory
|
||||
self.factory: Inlining[
|
||||
NullableReference[BinaryTree[KeyMetadata[KeyT, Integer]]]
|
||||
] = NullableReferenceFactory(factory).loose()
|
||||
self.comparator = comparator
|
||||
|
||||
def size(self) -> Optional[int]:
|
||||
return self.factory.size()
|
||||
|
||||
@classmethod
|
||||
def of(cls, factory: RainbowFactory[KeyT], comparator: Comparator[KeyT]) -> 'FlowStandardFactory[KeyT]':
|
||||
assert isinstance(factory, RainbowFactory)
|
||||
@ -128,6 +134,6 @@ class FlowStandardFactory(RainbowFactory[FlowStandard[KeyT]], Generic[KeyT]):
|
||||
return FlowStandard(
|
||||
ActiveBinaryTree(
|
||||
self.protocol(self.comparator),
|
||||
NullableReferenceFactory(self.factory).from_bytes(source, resolver)
|
||||
self.factory.from_bytes(source, resolver)
|
||||
).protocolized()
|
||||
)
|
||||
|
@ -8,7 +8,6 @@ from rainbowadn.collection.keyvalue import *
|
||||
from rainbowadn.core import *
|
||||
from rainbowadn.flow.core import *
|
||||
from rainbowadn.flow.verification.core import *
|
||||
# from rainbowadn.inlining import *
|
||||
from rainbowadn.v13 import *
|
||||
from ._flowstandard import *
|
||||
from ._resolvemapper import *
|
||||
@ -19,14 +18,18 @@ __all__ = ('FlowCoinData', 'FlowCoin', 'FlowTransactionData', 'FlowTransaction',
|
||||
class FlowCoinData(RecursiveMentionable, StaticMentionable):
|
||||
def __init__(
|
||||
self,
|
||||
owner: HashPoint[Subject],
|
||||
owner: Subject,
|
||||
value: HashPoint[Integer]
|
||||
):
|
||||
assert isinstance(owner, HashPoint)
|
||||
assert isinstance(owner, Subject)
|
||||
assert isinstance(value, HashPoint)
|
||||
self.owner = owner
|
||||
self.value = value
|
||||
|
||||
@classmethod
|
||||
def size(cls) -> int:
|
||||
return Subject.size() + HashPoint.HASH_LENGTH
|
||||
|
||||
async def int_value(self) -> int:
|
||||
return (await self.value.resolve()).integer
|
||||
|
||||
@ -34,10 +37,10 @@ class FlowCoinData(RecursiveMentionable, StaticMentionable):
|
||||
def of(cls, owner: Subject, value: int) -> 'FlowCoinData':
|
||||
assert isinstance(owner, Subject)
|
||||
assert isinstance(value, int)
|
||||
return cls(HashPoint.of(owner), HashPoint.of(Integer(value)))
|
||||
return cls(owner, HashPoint.of(Integer(value)))
|
||||
|
||||
def points(self) -> Iterable[HashPoint]:
|
||||
return [self.owner, self.value]
|
||||
return [self.value]
|
||||
|
||||
def __bytes__(self):
|
||||
return bytes(self.owner) + bytes(self.value)
|
||||
@ -46,21 +49,16 @@ class FlowCoinData(RecursiveMentionable, StaticMentionable):
|
||||
def from_bytes(cls, source: bytes, resolver: HashResolver) -> 'FlowCoinData':
|
||||
assert isinstance(source, bytes)
|
||||
assert isinstance(resolver, HashResolver)
|
||||
separation = Subject.size()
|
||||
return cls(
|
||||
ResolverOrigin(Subject.factory(), source[:HashPoint.HASH_LENGTH], resolver).hash_point(),
|
||||
ResolverOrigin(Integer.factory(), source[HashPoint.HASH_LENGTH:], resolver).hash_point(),
|
||||
Subject.from_bytes(source[:separation], resolver),
|
||||
ResolverOrigin(Integer.factory(), source[separation:], resolver).hash_point(),
|
||||
)
|
||||
|
||||
async def str(self, tab: int) -> str:
|
||||
assert isinstance(tab, int)
|
||||
owner_str, value_str = await gather(
|
||||
hash_point_format(self.owner, tab),
|
||||
hash_point_format(self.value, tab),
|
||||
)
|
||||
assert isinstance(owner_str, str)
|
||||
assert isinstance(value_str, str)
|
||||
return f'{owner_str}' \
|
||||
f'{tabulate(tab)}{value_str}'
|
||||
return f'{self.owner}' \
|
||||
f'{tabulate(tab)}{await hash_point_format(self.value, tab)}'
|
||||
|
||||
|
||||
class FlowCoin(RecursiveMentionable, StaticMentionable):
|
||||
@ -109,8 +107,8 @@ class FlowCoin(RecursiveMentionable, StaticMentionable):
|
||||
async def int_value(self) -> int:
|
||||
return await (await self.data_resolved()).int_value()
|
||||
|
||||
async def owner_resolved(self) -> Subject:
|
||||
return await (await self.data_resolved()).owner.resolve()
|
||||
async def owner(self) -> Subject:
|
||||
return (await self.data_resolved()).owner
|
||||
|
||||
|
||||
class FlowTransactionData(RecursiveMentionable, StaticMentionable):
|
||||
@ -151,7 +149,7 @@ class FlowTransactionData(RecursiveMentionable, StaticMentionable):
|
||||
assert isinstance(signature, Signature)
|
||||
assert_true(
|
||||
signature.verify(
|
||||
await coin.owner_resolved(),
|
||||
await coin.owner(),
|
||||
self.hash_point
|
||||
)
|
||||
)
|
||||
@ -253,7 +251,7 @@ class CVMapper(Mapper[FlowCoin, bool]):
|
||||
assert isinstance(element, FlowCoin)
|
||||
assert_true(
|
||||
await self.signatures.contains(
|
||||
HashPoint.of(await KeyValue.off((await element.data.resolve()).owner, HashPoint.of(Signature.empty()))),
|
||||
HashPoint.of(KeyValue.of(await element.owner(), Signature.empty())),
|
||||
exact=False
|
||||
)
|
||||
)
|
||||
@ -298,6 +296,10 @@ class FlowTransaction(RecursiveMentionable, StaticMentionable):
|
||||
self.hash_point = HashPoint.of(self)
|
||||
assert isinstance(self.hash_point, HashPoint)
|
||||
|
||||
@classmethod
|
||||
def size(cls) -> int:
|
||||
return 3 * HashPoint.HASH_LENGTH
|
||||
|
||||
def points(self) -> Iterable[HashPoint]:
|
||||
return [*self.data.points(), *self.signatures.points()]
|
||||
|
||||
|
@ -88,5 +88,5 @@ class NullableReferenceFactory(Inlining[NullableReference[Referenced]], Generic[
|
||||
ResolverMetaOrigin(resolver).hash_point(self.factory, source)
|
||||
)
|
||||
|
||||
def loose(self) -> RainbowFactory[NullableReference[Referenced]]:
|
||||
def loose(self) -> Inlining[NullableReference[Referenced]]:
|
||||
return self
|
||||
|
@ -48,7 +48,7 @@ async def _generate_transaction(
|
||||
break
|
||||
coin = await minted.pop().resolve()
|
||||
in_coins.append(coin)
|
||||
keys.append(reverse[(await coin.owner_resolved()).verify_key])
|
||||
keys.append(reverse[(await coin.owner()).verify_key])
|
||||
transaction = await FlowTransaction.make(
|
||||
in_coins,
|
||||
[
|
||||
@ -151,8 +151,12 @@ preset_long = dict(blocks=64, subjects=(4, 8), transactions=(8, 16), caching=Tru
|
||||
preset_short = dict(blocks=16, subjects=(4, 8), transactions=(8, 16), caching=True, delay=.5)
|
||||
|
||||
if __name__ == '__main__':
|
||||
random.seed(659918)
|
||||
try:
|
||||
asyncio.run(
|
||||
trace(
|
||||
preset_long
|
||||
)
|
||||
)
|
||||
except KeyboardInterrupt:
|
||||
print('interrupted')
|
||||
|
Loading…
Reference in New Issue
Block a user