推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
cr4fun
V2EX  ›  Python

写个教材:从 0 开始,用 Python 写区块链

  •  
  •   cr4fun · Aug 7, 2018 · 3472 views
    This topic created in 2974 days ago, the information mentioned may be changed or developed.

    现在放在 github 上面,目前写到第 4 课了,每一课单独一个文件夹。

    目前实现了简单的区块链,准备每天更新一课。

    https://github.com/OpensourceBooks/blockchain

    6 replies  •  2018-08-09 19:18:14 +08:00
    nine99
        1
    nine99  
       Aug 7, 2018
    放[]里就是区块链了吗,真搞笑
    cr4fun
        2
    cr4fun  
    OP
       Aug 7, 2018
    @nine99 一个区块的哈希和前一个哈希能对上,就形成了区块链。
    VVVVVEX
        3
    VVVVVEX  
       Aug 7, 2018
    KV 数据库了解下
    cr4fun
        4
    cr4fun  
    OP
       Aug 7, 2018 via iPhone
    @VVVVVEX python 的轻量级 dbm 如何? 或者你建议用 redis ?
    adkudao
        5
    adkudao  
       Aug 8, 2018
    不错, 大力支持, 希望楼主能坚持下去!
    cr4fun
        6
    cr4fun  
    OP
       Aug 9, 2018
    最新更新:

    区块链两个节点之间可以同步数据了。

    但是,还没有完成数据验证。



    下一节课,将要写完数据验证。

    增加了节点同步的区块链
    增加一个 list,保存节点。
    ```
    nodes=[]
    ```
    为了方便同步数据,我们要增加一个接口,可以获知区块链高度。

    http://localhost:8080/blocks/height

    这样,即可得到区块链的高度。当目标节点的区块链高度大于本地区块链高度时,才去同步。

    查看节点

    http://localhost:8080/nodes

    添加节点

    http://localhost:8080/nodes/add/localhost/9000

    得到:
    ```
    [
    {
    "ip": "localhost",
    "port": 9000
    }
    ]
    ```
    在 8080 的节点中加入另一个节点 8081

    http://localhost:8080/nodes/add/localhost/8081

    查看 8080 节点

    http://localhost:8080/nodes

    在 8081 的区块链中加一条信息

    http://localhost:8081/say/jerry2

    在 8080 节点中同步

    http://localhost:8080/blocks/sync

    查看节点

    如果没同步:
    ```
    "no synced"
    ```

    如果同步了:
    ```
    "synced"
    ```
    http://localhost:8080/blocks/all


    详情,在 https://github.com/OpensourceBooks/blockchain/blob/master/5/readme.md
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1118 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 17:30 · PVG 01:30 · LAX 10:30 · JFK 13:30
    ♥ Do have faith in what you're doing.