-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
394 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ venv | |
test-reports/ | ||
notes.txt | ||
.mypy_cache | ||
.eggs/ | ||
.eggs/ | ||
*.egg-info/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from typing import ( | ||
List, | ||
TYPE_CHECKING, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from .block import Block # noqa: F401 | ||
|
||
|
||
class Chain(): | ||
# Note, this is not an object defined in the v2.1 spec | ||
# this is a helper object to mask complexity in tracking | ||
# blocks | ||
|
||
def __init__(self, head: 'Block'=None, blocks: List['Block']=[]) -> None: | ||
self.head = head | ||
self.blocks = blocks | ||
self.chain = [] # type: List['Block'] | ||
|
||
# temp helper | ||
all_blocks_by_hash = { | ||
block.hash: block | ||
for block in self.blocks | ||
} | ||
|
||
if self.head: | ||
tmp = self.head | ||
self.chain.append(tmp) | ||
while all_blocks_by_hash.get(tmp.parent_hash, None): | ||
tmp = all_blocks_by_hash[tmp.parent_hash] | ||
self.chain.append(tmp) | ||
|
||
self.block_by_hash = { | ||
block.hash: block | ||
for block in self.chain | ||
} | ||
self.block_by_slot_number = { | ||
block.slot_number: block | ||
for block in self.chain | ||
} | ||
|
||
def __contains__(self, block: 'Block') -> bool: | ||
return bool(self.get_block_by_hash(block.hash)) | ||
|
||
def get_block_by_slot_number(self, slot_number: int) -> 'Block': | ||
return self.block_by_slot_number.get(slot_number, None) | ||
|
||
def get_block_by_hash(self, block_hash: bytes) -> 'Block': | ||
return self.block_by_hash.get(block_hash, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
from eth_utils import denoms | ||
|
||
from beacon_chain.beacon_typing.custom import ( | ||
Hash32, | ||
) | ||
|
||
|
||
WEI_PER_ETH = denoms.ether | ||
ZERO_HASH32 = Hash32(32 * b'\x00') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.