Skip to content

Commit

Permalink
fix: dependency to cryptography
Browse files Browse the repository at this point in the history
  • Loading branch information
rezamahdi committed Feb 25, 2022
1 parent 15780e3 commit 1e3d561
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ packages = find:
package_dir =
=src
install_requires =
crypto
cryptography

[options.extras_require]
dev =
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
packages=setuptools.find_packages(where="src"),
package_dir={"": "src"},
python_requires=">=3.7",
install_requires=["crypto"],
install_requires=["cryptography"],
extras_require={
"dev": ["pytest", "pytest-cov", "pytest-mock"],
"fastapi": ["fastapi"],
Expand Down
32 changes: 28 additions & 4 deletions src/pyzantium/chain.py
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

0 comments on commit 1e3d561

Please sign in to comment.