-
Notifications
You must be signed in to change notification settings - Fork 0
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
3 changed files
with
30 additions
and
6 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
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,23 +1,47 @@ | ||
from ctypes import Union | ||
import hashlib | ||
from .storage import Storage | ||
from cryptography.hazmat.primitives import hashes | ||
from typing import Union | ||
from .block import Block | ||
from .storage import Storage | ||
|
||
__all__ = ["Chain"] | ||
|
||
|
||
class Chain: | ||
def __init__(self, *, hash: str, storage: Storage) -> None: | ||
self._hash = hashlib[hash] if type(hash) == str else hash | ||
""" | ||
Central class to handle bolckchain machinary over ``Storage`` | ||
This class hides storage and provide a higher level of bolckchain operation | ||
that eases other operations like mining and block validation. | ||
:param hash: The hash algorithm used in this blokchain | ||
:param storage: storage of this blockchain | ||
""" | ||
|
||
def __init__(self, *, hash: hashes.HashAlgorithm, storage: Storage) -> None: | ||
self._hash = hash | ||
self._storage = storage | ||
self._last_hash = storage[-1] | ||
|
||
def new_block(self) -> Block: | ||
"""Generate an empty block with preset properties | ||
:rtype: pyzantium.Block | ||
""" | ||
block = Block() | ||
# TODO: Generate a block and initialize it's preveiuse hash | ||
|
||
@property | ||
def storage(self): | ||
"""Storage of this chain""" | ||
return self._storage | ||
|
||
@property | ||
def hash(self): | ||
"""Hash algorithm of this blockchain""" | ||
return self._hash | ||
|
||
@property | ||
def last_block_hash(self): | ||
"""Hash of last block""" | ||
return self._last_hash |