Python implementation of a basic blockchain (bitcoin inspired and simplified) functionality for learning purposes (python3/asyncio/xmlrpc).
For now, the best way to inspect working functionality is thru browsing unit and behave tests.
git clone https://github.com/mrkovec/coinpy.git
python -m pip install mypy
python -m pip install mypy_extensions
python -m pip install ecdsa
python -m pip install behave
python -m unittest discover
python -m behave
Also is possible to inspect nodes communication with:
runing first node
python -m coinpyd -bind :5001 -rpcbind :6001
runing second node
python -m coinpyd -bind :5002 -addnode :5001 -gen -rpcbind :6002
inspecting log outputs and afterwards quitting nodes
python -m coinpycli stop :6001
python -m coinpycli stop :6002
Functionality overview:
- output/transaction/block/ledger data and functionality design
+---------------+ +----------------------------+ +-----------------------------+
| output | | transaction | | block |
+---------------+ +----------------------------+ +-----------------------------+
| amount | | version | | version |
| pubaddr | | time_stamp | | nonce |
+-------+-------+ | +------------+-----------+ | | prev_block_id |
| | | inputs | outputs | | | height |
+-------v-------+ | +------------+-----------+ | | difficulty |
| output.id | | |output1.id | output1 | | | time_stamp |
+---------------+ | |output2.id +-----------+ | | +-----------------------+ |
| | . | . | | | | transactions | |
| | . | . | | | +-----------------------+ |
| | . +-----------+ | | | transaction1 | |
| |outputN.id | outputN | | | | transaction2 | |
| +------------+-----------+ | | | . | |
+--------------+-------------+ | | . | |
| | | | | transactionN | |
| +--------v-------+ | | +-----------------------+ |
| | signature | | +--------------+--------------+
| +----------------+ | |
| signature_pubkey | +--------------v--------------+
+--------------+-------------+ | block.id |
| +-----------------------------+
+--------------v-------------+
| transaction.id |
+----------------------------+
+--------------------------------------------------------------------------------------------------------------------------------+
| blockchain |
+--------------------------------------------------------------------------------------------------------------------------------+
| +--------------------------------------------+ +------------------------------------------+ |
| | blockN +-------------+ | blockN+1 +---->+
| +--------------------------------------------+ | +------------------------------------------+ |
+----->+ prev_block_id | +------------>+ prev_block_id | |
| +--------------------------------------------+ +------------------------------------------+ |
| | transactionN | | transactionN | |
| +--->+ inputM from pubadrA outputM to pubadrC +-+ ---->+ inputM from pubadrB outputM to pubadrD +--+ |
| | | inputM+1 from pubadrA | | | +------------------------------------------+ | |
| | |--------------------------------------------| | | | transactionN+1 | | |
| | | transactionN+1 | | | -->+ inputM from oubadrC outputM to pubadrD +--+ |
| | +->+ inputM from pubadrB outputM to pubadrC +-+ | | | | | |
| | | +--------------------------------------------+ | | | +------------------------------------------+ | |
+-|-|-------------------------------------------------|--------------------|-|------------------------------------------------|--+
| | | +---------------+ | | |
| | | |unspent outputs| | | |
| | | +---------------+ | | |
+-|-------------------------------------------------|------ pubadrA | | | |
| | | | | | |
+-------------------------------------------------|------ pubadrB -----+ | |
| | | | |
+-----> pubadrC -------+ |
| | |
| pubadrD <-------------------------------------------------------+
| |
+---------------+
- peer-to-peer functionality
- consensus rules
- block assembling, mining, announcing and chaining
- between nodes blockchain sync
- basic daemon / cli functionality
- fork detection & merging
- blockchain persistence
- wallet functionality
- NAT traversal
- IPFS