Skip to content

Commit

Permalink
doc: add docstring to storage module and disk storage
Browse files Browse the repository at this point in the history
  • Loading branch information
rezamahdi committed Feb 24, 2022
1 parent bf20346 commit 15780e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/pyzantium/storage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
"""
``storage`` module contains classes to store blocks and other information about
a blockchain. Conceptually, storage has two parts:
#. A storage pool that just stores raw blocks.
#. An index to track the squence of blocks by hash.
Altogh raw filesystem storing of blocks in most cases is enough, but someone
may need to store blocks (or chain's index) in a database, leveldb, i.e.
To support this customization, pyzantium separates blockchain from it's storage.
Note that this class is an abstract class and doesn't contain any implementation
so is not instantiniatable.
"""

from abc import ABC, abstractmethod


Expand Down
10 changes: 8 additions & 2 deletions src/pyzantium/storage/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ class DiskStorage(Storage):
name is infered from two beggining letters of block's hash.
#. A file named `index` is stored in root directory of storage that is
a simple text file with hashes of blocks sorted by time in it (most
a simple text file with hashes of blocks sorted by time in it (most
recent last) to accelerate access to blocks
:param path: Path to store blocks and index.
:param creeate: Whether to create a new storage or open an existing one.
:param error_if_missing:
If this param is set to ``True`` and a storage allready exist in
``path``, then an exception will raise.
"""

def __init__(
Expand All @@ -44,6 +50,6 @@ def __init__(
mkdir(self._path)

self._index_file = open(self._path + "/index", "r")

def __getitem__(self, hash: bytes):
return super().__getitem__(hash)

0 comments on commit 15780e3

Please sign in to comment.