Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rezamahdi committed Feb 24, 2022
0 parents commit feab09a
Show file tree
Hide file tree
Showing 25 changed files with 745 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Build
on: push
jobs:
clone:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
name: Setup python
with:
python-version: "3.x"
- run: |
pip install setuptools
pip install build
python -m build -n
148 changes: 148 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@

# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# VSCode
.vscode/

# End of https://www.toptal.com/developers/gitignore/api/python
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2022 Reza Mahdi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
109 changes: 109 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<h1 align="center">Pyzantium</h1>

<p align="center">
<a href="https://www.codefactor.io/repository/github/rezamahdi/pyzantium">
<img src="https://img.shields.io/codefactor/grade/github/rezamahdi/pyzantium?color=ff69b4&style=for-the-badge">
</a>
<a href="https://pypi.org/">
<img src="https://img.shields.io/pypi/v/pyzantium?style=for-the-badge">
</a>
<a href="https://pypi.org/project/pyzantium/">
<img src="https://img.shields.io/pypi/pyversions/pyzantium?style=for-the-badge">
</a>
<a href="/LICENSE">
<img src="https://img.shields.io/github/license/rezamahdi/pyzantium?color=darkred&style=for-the-badge">
</a>
<a href="https://github.com/rezamahdi/pyzantium/commits">
<img src="https://img.shields.io/github/last-commit/rezamahdi/pyzantium?style=for-the-badge">
</a>
<a href="https://github.com/rezamahdi/pyzantium/releases">
<img src="https://img.shields.io/github/release-date/rezamahdi/pyzantium?color=teal&style=for-the-badge">
</a>
<a href="https://github.com/rezamahdi/pyzantium/issues">
<img src="https://img.shields.io/github/issues-raw/rezamahdi/pyzantium?color=blueviolet&style=for-the-badge">
</a>
</p>

<p align="center">
<a href="https://github.com/rezamahdi/pyzantium/issues/new?assignees=rezamahdi&labels=bug&late=BUG_REPORT.md&title=%5BBUG%5D%3A">Report Bug
</a>
·
<a href="https://github.com/rezamahdi/pyzantium/issues/new?assignees=rezamahdi&labels=enhancement&late=FEATURE_REQUEST.md&title=%5BFEATURE%5D%3A">Request Feature
</a>
</p>

---

> 🔗 Python implementation and building blocks for blockchain
Pyzantium is a python module that let you implement blockchain whit various capabilityies
in your project.

The Module provide both high-level(`Blockchain`) and low-level(`Block`,`Consensus`, ...)
classes in order to be highly customizable.

---

- [1. Installation](#1-installation)
- [2. Usage](#2-usage)
- [3. License](#3-license)

## 1. Installation

The package is pip installable:
```bash
pip install pybchain
```

Or, you can download it and use `setuptools` to build it by hand:
```bash
git clone http://github.com/rezamahdi/pybchain
cd pybchain
python setup.py install
```


## 2. Usage

To initialize a blockchain, you must specify some info as agreement:

- Hash algorithm to use in blockchain.
- Wath type of data you want to store. Blockchain is capable of storing anythin
not only transactions.
- An authentication scheme. Common way to do this is using ECC. this part is optional.
- Endpoint to connect to other nodes. Common option is a HTTP api or json-rpc.

Whit having these options specified, you can initialize the node as this:

```python
from pyzantium import Chain, Block
from pyzantium.storage import Disk
from hashlib import sha_256

chain = Chain(
hash=sha_256,
storage=Disk(
"path/to/storage",
create=True
)
)
```

Next, in order to mine genesis block do this:
```python
genesis = Block(chain)
genesis.add_part(b'000000000000000000000000000') # or any other type of data.
# add more data parts...
genesis.finalize() # we don't use `mine` because it is named `forge` in PoS.

result = endpoint.broadcast_new_block(genesis)

if result.is_ok():
chain.append(genesis)
```

see [documentation](http://pyzantium.readthedocs.org) for more info

## 3. License
Copyright (c) Reza Mahdi 2022
This project is licensed under terms of MIT License (see LICENSE)
20 changes: 20 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
55 changes: 55 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = 'Pybchain'
copyright = '2022, Reza Mahdi'
author = 'Reza Mahdi'

# The full version, including alpha/beta/rc tags
release = '0.0.1'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

0 comments on commit feab09a

Please sign in to comment.