### 增加了一些查询功能、可以选择端口的参数
增加一个引入:
```
from argparse import ArgumentParser
```
启动代码如下:
```
parser = ArgumentParser()
parser.add_argument('-p', '--port', default=8080, type=int, help='port to listen on')
args = parser.parse_args()
port = args.port
app.run(debug=True,host='0.0.0.0',port=port)
```
我们启动区块链
```
python blockchain.py -p 9090
```
访问全部区块:
http://localhost:9090/blocks/all
```json
[
{
"data": "Genesis Block",
"hash": "74eaf9085aa458f99c724583e4314b361bae60bff74e4cb82f89c9ecaa671406",
"index": 0,
"previous_hash": 0,
"timestamp": 1533634910741
},
{
"data": "hello",
"hash": "41c28040287d26d66780f1175606fbf22d6a73c11355c64ae590b32d5e22d61b",
"index": 1,
"previous_hash": "74eaf9085aa458f99c724583e4314b361bae60bff74e4cb82f89c9ecaa671406",
"timestamp": 1533634910741
},
{
"data": "hi~",
"hash": "45aff7916c3410f9f93ac2a9dbcc24af33caa9120890ce0f1cabe02a3514b106",
"index": 2,
"previous_hash": "41c28040287d26d66780f1175606fbf22d6a73c11355c64ae590b32d5e22d61b",
"timestamp": 1533634910741
},
{
"data": "~",
"hash": "cd3d295b8c2c168830e24132f58073f2d39cee95fa6ae4d87a8be248fe8eaf3f",
"index": 3,
"previous_hash": "45aff7916c3410f9f93ac2a9dbcc24af33caa9120890ce0f1cabe02a3514b106",
"timestamp": 1533634910741
}
]
```
访问最新的区块:
http://localhost:9090/blocks/last
你能得到类似的结果:
```json
{
"data": "~",
"hash": "5b9d3b614c7e28a330a7ae6517d2132709725e9812dd8b80f7f8e702fd1bc4c3",
"index": 3,
"previous_hash": "2624e776d1adc8c2b99e42458f69957ab8f66477dff393a1c8f8b6b3da417672",
"timestamp": 1533632972579
}
```
其中index就是区块链的高度
访问index从1~3的区块
http://localhost:9090/blocks/1/3
你能得到类似的结果:
```json
[
{
"data": "hello",
"hash": "bbea6b876254a17d03cf154821be34be2ba782500da2b9310baa9d2f08567181",
"index": 1,
"previous_hash": "d2c6ff3b8ab521d7837ac64873f7228d9f7e96ce727cec2a815d135545c65f44",
"timestamp": 1533634461058
},
{
"data": "hi~",
"hash": "ad65bd6611bb84416766f231cfc87c86c885ad4f0a12bfa002c40119abd23b23",
"index": 2,
"previous_hash": "bbea6b876254a17d03cf154821be34be2ba782500da2b9310baa9d2f08567181",
"timestamp": 1533634461058
},
{
"data": "~",
"hash": "b2bc5f8762252de051c06eccd2cadeda43a200f1e834e0033e056b341d0688d6",
"index": 3,
"previous_hash": "ad65bd6611bb84416766f231cfc87c86c885ad4f0a12bfa002c40119abd23b23",
"timestamp": 1533634461058
}
]
```
访问index为2的区块
http://localhost:9090/blocks/2
你能得到类似的结果:
```json
{
"data": "hi~",
"hash": "ad65bd6611bb84416766f231cfc87c86c885ad4f0a12bfa002c40119abd23b23",
"index": 2,
"previous_hash": "bbea6b876254a17d03cf154821be34be2ba782500da2b9310baa9d2f08567181",
"timestamp": 1533634461058
}
```
没有合适的资源?快使用搜索试试~ 我知道了~
区块链blockchain教程.zip
共81个文件
py:39个
html:19个
md:15个
需积分: 2 0 下载量 131 浏览量
2024-05-10
23:06:42
上传
评论
收藏 284KB ZIP 举报
温馨提示
【课程说明】 第0课、最简单的区块链 第1课、拥有index和时间戳的区块链 第2课、一个能在浏览器访问的区块链 第3课、一个信息上链的功能 第4课、增加一些条件查询的区块链 第5课、可以多节点同步的区块链 第6课、同步节点时进行验证 第7课、签名数据上链 第8课、区块链浏览器 * 8.1 在8的版本上进行了更改,结构更扁平化,为了日后做kv数据的持久化。 第9课、hash上链 备注:8.2 文件夹经过测试有问题,不能执行。 8.1 没有测试。8、9、10文件夹内的程序是ok的。
资源推荐
资源详情
资源评论
收起资源包目录
【区块链】blockchain【程序员VIP专用】.zip (81个子文件)
blockchain【程序员VIP专用】
0
blockchain_err.svg 22KB
blockchain.svg 21KB
blockchain.py 927B
readme.md 2KB
8.1
blockchain.py 7KB
readme.md 652B
templates
find.html 440B
post.html 545B
index.html 1KB
generate.py 700B
client.py 2KB
test.py 1KB
10
blockchain.py 8KB
readme.md 651B
templates
find.html 440B
post.html 545B
index.html 1KB
generate.py 700B
client.py 2KB
test.py 1KB
md5.py 116B
8
blockchain.py 7KB
readme.md 654B
templates
find.html 440B
post.html 545B
index.html 1KB
generate.py 700B
client.py 2KB
test.py 1KB
9
blockchain.py 8KB
readme.md 651B
templates
find.html 440B
post.html 545B
index.html 1KB
generate.py 700B
client.py 2KB
test.py 1KB
md5.py 116B
1
blockchain.py 1KB
readme.md 970B
redis
blockchain.py 1KB
readme.md 389B
show_all_blockchain.py 568B
genesis.py 1KB
add_block.py 2KB
remove_all.py 187B
test.py 34B
2
blockchain.py 1KB
readme.md 220B
6
blockchain.py 5KB
readme.md 2KB
templates
index.html 496B
8.2
blockchain_helper.py 4KB
blockchain.py 4KB
readme.md 652B
templates
find.html 440B
post.html 545B
index.html 1KB
generate.py 700B
client.py 2KB
__pycache__
blockchain_helper.cpython-35.pyc 4KB
blockchain_helper.cpython-36.pyc 4KB
bc.cpython-35.pyc 4KB
test.py 1KB
requirements.txt 36B
images
wx.jpg 96KB
xq.jpg 181KB
README.md 2KB
5
blockchain.py 4KB
readme.md 926B
templates
index.html 496B
4
blockchain.py 2KB
readme.md 3KB
templates
index.html 449B
7
blockchain.py 6KB
readme.md 2KB
templates
index.html 496B
client.py 2KB
test.py 3KB
3
blockchain.py 1KB
readme.md 212B
共 81 条
- 1
资源评论
想念@思恋
- 粉丝: 959
- 资源: 108
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功