37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from typing import TypeVar
|
|
|
|
from rainbowadn.core import *
|
|
from rainbowadn.nullability import *
|
|
from .activestateprotocol import *
|
|
|
|
__all__ = ('MetaReductionStateProtocol',)
|
|
|
|
HeaderType = TypeVar('HeaderType')
|
|
StateType = TypeVar('StateType')
|
|
|
|
|
|
class MetaReductionStateProtocol(ActiveStateProtocol[HeaderType, StateType]):
|
|
def _initial_state(self) -> HashPoint[StateType]:
|
|
raise NotImplementedError
|
|
|
|
async def _derive(
|
|
self,
|
|
previous: HashPoint[StateType],
|
|
header: HashPoint[HeaderType],
|
|
) -> HashPoint[StateType]:
|
|
raise NotImplementedError
|
|
|
|
async def derive(
|
|
self,
|
|
previous: NullableReference[StateType],
|
|
header: HashPoint[HeaderType],
|
|
) -> HashPoint[StateType]:
|
|
assert isinstance(previous, NullableReference)
|
|
assert isinstance(header, HashPoint)
|
|
if previous.null():
|
|
previous_state: HashPoint[StateType] = self._initial_state()
|
|
else:
|
|
previous_state: HashPoint[StateType] = previous.hashpoint()
|
|
assert isinstance(previous_state, HashPoint)
|
|
return await self._derive(previous_state, header)
|