Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
fix linting, typing, sort import
Browse files Browse the repository at this point in the history
  • Loading branch information
ChihChengLiang committed Apr 16, 2019
1 parent ae03f0c commit 150155d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 54 deletions.
54 changes: 30 additions & 24 deletions eth2/beacon/chains/base.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
from abc import (
ABC,
abstractmethod
abstractmethod,
)
import logging
from typing import (
TYPE_CHECKING,
Tuple,
Type,
)

import logging

from eth_typing import (
Hash32,
from eth._utils.datatypes import (
Configurable,
)
from eth_utils import (
encode_hex,
ValidationError,
from eth.db.backends.base import (
BaseAtomicDB,
)

from eth.db.backends.base import BaseAtomicDB
from eth.exceptions import (
BlockNotFound,
)
from eth.validation import (
validate_word,
)

from eth._utils.datatypes import (
Configurable,
from eth_typing import (
Hash32,
)
from eth_utils import (
ValidationError,
encode_hex,
)

from eth2._utils.ssz import (
validate_imported_block_unchanged,
)

from eth2.beacon.db.chain import ( # noqa: F401
from eth2.beacon.db.chain import (
BaseBeaconChainDB,
BeaconChainDB,
)
from eth2.beacon.exceptions import (
BlockClassError,
StateMachineNotFound,
)
from eth2.beacon.state_machines.base import BeaconStateMachine # noqa: F401
from eth2.beacon.types.blocks import (
BaseBeaconBlock,
)
from eth2.beacon.types.states import BeaconState
from eth2.beacon.types.states import (
BeaconState,
)
from eth2.beacon.typing import (
FromBlockParams,
Slot,
Expand All @@ -53,14 +54,19 @@
validate_slot,
)

if TYPE_CHECKING:
from eth2.beacon.state_machines.base import ( # noqa: F401
BaseBeaconStateMachine,
)


class BaseBeaconChain(Configurable, ABC):
"""
The base class for all BeaconChain objects
"""
chaindb = None # type: BaseBeaconChainDB
chaindb_class = None # type: Type[BaseBeaconChainDB]
sm_configuration = None # type: Tuple[Tuple[Slot, Type[BeaconStateMachine]], ...]
sm_configuration = None # type: Tuple[Tuple[Slot, Type[BaseBeaconStateMachine]], ...]
chain_id = None # type: int

#
Expand Down Expand Up @@ -89,18 +95,18 @@ def from_genesis(cls,
@abstractmethod
def get_state_machine_class(
cls,
block: BaseBeaconBlock) -> Type['BeaconStateMachine']:
block: BaseBeaconBlock) -> Type['BaseBeaconStateMachine']:
pass

@abstractmethod
def get_state_machine(self, at_block: BaseBeaconBlock=None) -> 'BeaconStateMachine':
def get_state_machine(self, at_block: BaseBeaconBlock=None) -> 'BaseBeaconStateMachine':
pass

@classmethod
@abstractmethod
def get_state_machine_class_for_block_slot(
cls,
slot: Slot) -> Type['BeaconStateMachine']:
slot: Slot) -> Type['BaseBeaconStateMachine']:
pass

#
Expand Down Expand Up @@ -224,7 +230,7 @@ def _from_genesis_block(cls,
# StateMachine API
#
@classmethod
def get_state_machine_class(cls, block: BaseBeaconBlock) -> Type['BeaconStateMachine']:
def get_state_machine_class(cls, block: BaseBeaconBlock) -> Type['BaseBeaconStateMachine']:
"""
Returns the ``StateMachine`` instance for the given block slot number.
"""
Expand All @@ -233,7 +239,7 @@ def get_state_machine_class(cls, block: BaseBeaconBlock) -> Type['BeaconStateMac
@classmethod
def get_state_machine_class_for_block_slot(
cls,
slot: Slot) -> Type['BeaconStateMachine']:
slot: Slot) -> Type['BaseBeaconStateMachine']:
"""
Return the ``StateMachine`` class for the given block slot number.
"""
Expand All @@ -246,7 +252,7 @@ def get_state_machine_class_for_block_slot(
return sm_class
raise StateMachineNotFound("No StateMachine available for block slot: #{0}".format(slot))

def get_state_machine(self, at_block: BaseBeaconBlock=None) -> 'BeaconStateMachine':
def get_state_machine(self, at_block: BaseBeaconBlock=None) -> 'BaseBeaconStateMachine':
"""
Return the ``StateMachine`` instance for the given block number.
"""
Expand Down
34 changes: 19 additions & 15 deletions eth2/beacon/chains/testnet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
from typing import ( # noqa: F401
Tuple,
Type,
)

from typing import (
TYPE_CHECKING,
)
from eth2.beacon.chains.base import (
BeaconChain,
)
from eth2.beacon.state_machines.base import ( # noqa: F401
BaseBeaconStateMachine,
)
from eth2.beacon.state_machines.forks.xiao_long_bao import (
XiaoLongBaoStateMachine,
)
from eth2.beacon.typing import ( # noqa: F401
Slot,
)

from .constants import GENESIS_SLOT, TESTNET_CHAIN_ID

if TYPE_CHECKING:
from eth2.beacon.typing import ( # noqa: F401
Slot,
)
from eth2.beacon.state_machines.base import ( # noqa: F401
BaseBeaconStateMachine,
)
from typing import ( # noqa: F401
Tuple,
Type,
)


TESTNET_SM_CONFIGURATION = (
(GENESIS_SLOT, XiaoLongBaoStateMachine),
)
) # type: Tuple[Tuple[Slot, Type[BaseBeaconStateMachine]], ...]


class BaseTestnetChain:
sm_configuration = TESTNET_SM_CONFIGURATION # type: Tuple[Tuple[Slot, Type[BaseBeaconStateMachine]], ...] # noqa: E501
chain_id = TESTNET_CHAIN_ID # type: int
sm_configuration = TESTNET_SM_CONFIGURATION
chain_id = TESTNET_CHAIN_ID


class TestnetChain(BaseTestnetChain, BeaconChain):
Expand Down
20 changes: 5 additions & 15 deletions eth2/beacon/state_machines/forks/xiao_long_bao/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from typing import ( # noqa: F401,
Type
)

from eth2.beacon.state_machines.base import (
BeaconStateMachine,
)
Expand All @@ -15,15 +11,9 @@
from eth2.beacon.state_machines.forks.serenity.states import (
SerenityBeaconState,
)
from eth2.beacon.state_machines.state_transitions import ( # noqa: F401,
BaseStateTransition,
)
from eth2.beacon.types.blocks import ( # noqa: F401,
from eth2.beacon.types.blocks import (
BaseBeaconBlock,
)
from eth2.beacon.types.states import ( # noqa: F401,
BeaconState,
)
from eth2.beacon.typing import (
FromBlockParams,
)
Expand All @@ -35,12 +25,12 @@

class XiaoLongBaoStateMachine(BeaconStateMachine):
# fork name
fork = 'xiao_long_bao' # type: str
fork = 'xiao_long_bao'

# classes
block_class = SerenityBeaconBlock # type: Type[BaseBeaconBlock]
state_class = SerenityBeaconState # type: Type[BeaconState]
state_transition_class = SerenityStateTransition # type: Type[BaseStateTransition]
block_class = SerenityBeaconBlock
state_class = SerenityBeaconState
state_transition_class = SerenityStateTransition
config = XIAO_LONG_BAO_CONFIG

# methods
Expand Down

0 comments on commit 150155d

Please sign in to comment.