黑基网 首页 教程 编程开发 查看内容

做一个简单的Python加密货币来了解比特币如何工作

2018-1-22 12:44| 投稿: xiaotiger |来自: 互联网

摘要: 在github上发现有大牛用python做了一个加密货币,发出来给大家一起研究研究。。只是一个非常简单的,不安全的和不完整的实现在Python中作为教育材料的加密货币的区块链。换句话说,一个简单的比特币克隆。SimpleCoin ...

在github上发现有大牛用python做了一个加密货币,发出来给大家一起研究研究。。

只是一个非常简单的,不安全的和不完整的实现在Python中作为教育材料的加密货币的区块链。换句话说,一个简单的比特币克隆。

SimpleCoin

只是一个非常简单,不安全和不完整的区块链实现的Python加密货币。这个项目的目标是使一个工作区块链货币,保持简单,可以作为教育材料。

这个项目只是为了好玩。如果你想制作自己的加密货币,你应该看一下比特币仓库。

什么是区块链?

看看比特币组织wiki网站,我们可以找到这个定义:

块链是由参与基于比特币协议的系统的所有节点共享的交易数据库。货币区块链的完整副本包含以货币执行的每个交易。有了这些信息,人们就可以发现历史上任何一个地点的每个地址都有多少价值。

您可以在原始比特币纸上找到更多信息。

如何运行它

首先,安装requirements.txt

pip install -r requirements.txt

那么你有两个选择:

  • 运行miner.py成为一个节点,并开始挖掘

  • 运行wallet.py成为用户并发送事务(发送事务必须运行一个节点,换句话说,你也必须运行miner.py

重要:不要在Python IDLE中运行它,在控制台中运行它。在miner.py使用并行处理没有在Python IDLE工作。

这个代码如何工作?

有两个主要的脚本:

  • miner.py

  • wallet.py

Miner.py

这个文件可能是最重要的。运行它将创建一个节点(如服务器)。从这里你可以连接到区块链和处理交易(其他用户发送)通过挖掘。作为这项工作的奖励,你收到一些硬币。存在的节点越多,区块链就越安全。

miner.py 有2个进程并行运行:

  1. 第一个流程负责采矿,更新新的区块链,并找到工作证明

  2. 第二个进程运行烧瓶服务器,对等节点和用户可以连接请求整个区块链或者提交新的事务。

并行进程不能在Python IDLE中运行,因此请确保从控制台运行它。

Wallet.py

这个文件是为那些不想成为一个节点,但简单的用户。运行这个文件允许你生成一个新地址,发送硬币并检查你的交易记录(记住,如果你在本地服务器上运行这个文件,你将需要一个“矿工”来处理你的交易)。

源码地址:https://github.com/cosme12/SimpleCoin

, groupId: 6513060428573049358, itemId: 6513060428573049358, type: 2, subInfo: { isOriginal: false, source: 程序狼, time: 2018-01-21 08:06:38 }, tagInfo: { tags: [{"name":"编程语言"},{"name":"Python"},{"name":"比特币"},{"name":"数字货币"},{"name":"GitHub"}], groupId: 6513060428573049358, itemId: 6513060428573049358, repin: 0, }, has_extern_link: 0 }, commentInfo: { groupId: 6513060428573049358, itemId: 6513060428573049358, comments_count: 5, ban_comment: 0 }, mediaInfo: { uid: 6725356429, name: 程序狼, avatar: //p7.pstatp.com/large/470a00032f201039b7fc, openUrl: /c/user/6725356429/, follow: false }, pgcInfo: {"media_info":{"open_url":"/c/user/6725356429/","avatar_url":"https://p7.pstatp.com/large/470a00032f201039b7fc","media_id":1576478771575822,"name":"程序狼","user_verified":false},"articles":[{"item_id":"6513060428573049358","url":"/item/6513060428573049358","title":"做一个简单的Python加密货币来了解比特币如何工作"},{"item_id":"6513059530492871171","url":"/item/6513059530492871171","title":"Bootstrap 4发布了,有什么新特点呢"},{"item_id":"6512355266292351491","url":"/item/6512355266292351491","title":"用AI来表达人类基因组"},{"item_id":"6511811907253436932","url":"/item/6511811907253436932","title":"比特币和以太坊在重新陷入监管压力的恐惧之后大跌"}]}, feedInfo: { url: /api/pc/feed/, category: __all__, initList: [{"comments_count":7,"media_avatar_url":"//p3.pstatp.com/large/10960/3939185734","is_feed_ad":false,"is_diversion_page":false,"title":"IBM高管:区块链将为制造商和零售商创造巨大价值","single_mode":true,"gallary_image_count":2,"middle_mode":true,"has_video":false,"video_duration_str":null,"source_url":"/group/6513118325239710222/","source":"创业家","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/5b0f000e76eb37ce351a","group_id":"6513118325239710222","is_related":true,"media_url":"/c/user/5842869539/"},{"comments_count":12,"media_avatar_url":"//p1.pstatp.com/large/13550018a452238fb80f","is_feed_ad":false,"is_diversion_page":false,"title":"Excel中最常用的12个函数|职场人做报表加速神器","single_mode":true,"gallary_image_count":15,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6513344440013160973/","source":"耀说","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":18,"image_url":"//p3.pstatp.com/list/190x124/5b40000195cc5d0baaac","group_id":"6513344440013160973","is_related":true,"media_url":"/c/user/54829141290/"},{"comments_count":46,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"有什么理由认为2018年1月16日和17日的崩盘后,比特币的价格会继续下跌?","single_mode":true,"gallary_image_count":0,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6512261838065893636/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/5ac40010de31e672d5cb","group_id":"6512261838065893636"},{"comments_count":24,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"比特币之外的下一个蓝海在哪里?","single_mode":true,"gallary_image_count":6,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6510123833435881732/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p9.pstatp.com/list/190x124/50ec0007dfffa59a096d","group_id":"6510123833435881732"},{"comments_count":141,"media_avatar_url":"//p3.pstatp.com/large/97e001d25c199ac5f57","is_feed_ad":false,"is_diversion_page":false,"title":"后区块链时代已来,洞悉区块链设备的现状与未来","single_mode":true,"gallary_image_count":3,"middle_mode":true,"has_video":false,"video_duration_str":null,"source_url":"/group/6512582704796533261/","source":"奢迷数码客","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/59440001e23c4b058f16","group_id":"6512582704796533261","is_related":true,"media_url":"/c/user/50219211435/"},{"comments_count":212,"media_avatar_url":"//p3.pstatp.com/large/78f001316cada92ee0f","is_feed_ad":false,"is_diversion_page":false,"title":"区块链挖矿高烧不退,细数行业四大最具潜力的矿机产品","single_mode":true,"gallary_image_count":4,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6511466460282356238/","source":"潮流科技范","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p1.pstatp.com/list/190x124/593a0003461ce44fe3f0","group_id":"6511466460282356238","is_related":true,"media_url":"/c/user/6955538216/"},{"comments_count":65,"media_avatar_url":"//p1.pstatp.com/large/249a0001ea600d4d6964","is_feed_ad":false,"is_diversion_page":false,"title":"斐讯天天链:大家都在谈的区块链技术,离我们生活并不远","single_mode":true,"gallary_image_count":1,"middle_mode":true,"has_video":false,"video_duration_str":null,"source_url":"/group/6512652557767148040/","source":"鲜闻早知道","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/59490002882fe58b51ad","group_id":"6512652557767148040","is_related":true,"media_url":"/c/user/59220798821/"},{"comments_count":83,"media_avatar_url":"//p3.pstatp.com/large/471100005fdf7183fc0e","is_feed_ad":false,"is_diversion_page":false,"title":"一起来搭个服务器吧,并实现自有域名访问!","single_mode":true,"gallary_image_count":13,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6513450943047008771/","source":"小K又来了","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/5b3f00029828336ec8d4","group_id":"6513450943047008771","is_related":true,"media_url":"/c/user/77547346040/"},{"comments_count":3,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"为什么不同平台的比特币钻石BCD价格相差好几倍?","single_mode":true,"gallary_image_count":3,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6512578690730164487/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/551900069485ba79f282","group_id":"6512578690730164487"},{"comments_count":4,"media_avatar_url":"//p1.pstatp.com/large/4e7b000191d1dcd4ea2a","is_feed_ad":false,"is_diversion_page":false,"title":"“中大型公司”支付服务架构演进之路,解决实际问题!","single_mode":true,"gallary_image_count":1,"middle_mode":true,"has_video":false,"video_duration_str":null,"source_url":"/group/6513049156070670855/","source":"JAVA高级分享","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/59490005d085e125bfc7","group_id":"6513049156070670855","is_related":true,"media_url":"/c/user/81456863481/"},{"comments_count":3,"media_avatar_url":"//p1.pstatp.com/large/17820006bed6f23ec1dd","is_feed_ad":false,"is_diversion_page":false,"title":"python学习之路(12):连接 Mysql 数据库及简单的增删改查回滚操作","single_mode":true,"gallary_image_count":13,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6513163636993688077/","source":"山顶洞洞人","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":2,"image_url":"//p3.pstatp.com/list/190x124/5945000523faf9cf38c8","group_id":"6513163636993688077","is_related":true,"media_url":"/c/user/52468413927/"},{"comments_count":0,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"如何给小白讲清楚比特币、区块链和ICO的区别?","single_mode":true,"gallary_image_count":1,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6512609901762576643/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p1.pstatp.com/list/190x124/50ec000a219885254231","group_id":"6512609901762576643"},{"comments_count":0,"is_related":true,"is_feed_ad":false,"is_diversion_page":false,"title":"徐小平布局区块链绝密信息遭泄漏,悬赏1比特币找到泄密者,你如何看待这件事?","single_mode":true,"gallary_image_count":5,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6513254134051766536/","source":"悟空问答","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/5519000725440dbdf20e","group_id":"6513254134051766536"},{"comments_count":71,"media_avatar_url":"//p4.pstatp.com/large/50aa000356b49be004a7","is_feed_ad":false,"is_diversion_page":false,"title":"不需要安装任何开发环境,在浏览器里面就能在线练习31种编程语言","single_mode":true,"gallary_image_count":9,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6512027159924572675/","source":"冰尘无极","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/59400003e4bc249987ac","group_id":"6512027159924572675","is_related":true,"media_url":"/c/user/74999065942/"},{"comments_count":12,"media_avatar_url":"//p3.pstatp.com/large/3e5d00003bd2d21c4b76","is_feed_ad":false,"is_diversion_page":false,"title":"Excel查找重复值神技能,使vlookup如虎添翼,逼格再生一级!","single_mode":true,"gallary_image_count":5,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6513514647058907662/","source":"Excel控","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":5,"image_url":"//p3.pstatp.com/list/190x124/5b430000de7af3e4ecff","group_id":"6513514647058907662","is_related":true,"media_url":"/c/user/71137123502/"},{"comments_count":2,"media_avatar_url":"//p1.pstatp.com/large/4ae50004fbe250060fc4","is_feed_ad":false,"is_diversion_page":false,"title":"JDBC、SQL注入攻击原理以及解决方案","single_mode":true,"gallary_image_count":15,"middle_mode":true,"has_video":false,"video_duration_str":null,"source_url":"/group/6513420490428645891/","source":"java交流","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":4,"image_url":"//p9.pstatp.com/list/190x124/5b3f00029b71ee239750","group_id":"6513420490428645891","is_related":true,"media_url":"/c/user/79132029943/"},{"comments_count":16,"media_avatar_url":"//p3.pstatp.com/large/470c0004f7aad2b6f682","is_feed_ad":false,"is_diversion_page":false,"title":"python中if __name__ == \"__main__\"你真的知道吗?","single_mode":true,"gallary_image_count":1,"middle_mode":true,"has_video":false,"video_duration_str":null,"source_url":"/group/6513347214717223432/","source":"从零开始学习Python","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":9,"image_url":"//p3.pstatp.com/list/190x124/59450005c381103915bf","group_id":"6513347214717223432","is_related":true,"media_url":"/c/user/6438756870/"},{"comments_count":14,"media_avatar_url":"//p9.pstatp.com/large/568100016b4cf0c9008f","is_feed_ad":false,"is_diversion_page":false,"title":"C语言之“编程超简单系列”:C语言面试的常客——“串口通信”","single_mode":true,"gallary_image_count":3,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6513462912332333582/","source":"进化中的程序猿","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"image_url":"//p3.pstatp.com/list/190x124/5b400002a6d5ca85916f","group_id":"6513462912332333582","is_related":true,"media_url":"/c/user/74357066923/"},{"comments_count":2,"media_avatar_url":"//p9.pstatp.com/large/2c65000c5d05ea367691","is_feed_ad":false,"is_diversion_page":false,"title":"Linux运维常用网络抓包工具tcpdump的介绍和使用","single_mode":true,"gallary_image_count":6,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6513409187966353927/","source":"海渊haiyuan","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":1,"image_url":"//p1.pstatp.com/list/190x124/5b42000065b85feda3ae","group_id":"6513409187966353927","is_related":true,"media_url":"/c/user/5797167091/"},{"media_avatar_url":"//p9.pstatp.com/large/2c65000c5d05ea367691","is_feed_ad":false,"is_diversion_page":false,"title":"Linux运维iptables中如何流程化编写iptables脚本","single_mode":false,"gallary_image_count":0,"middle_mode":false,"has_video":false,"video_duration_str":null,"source_url":"/group/6513140987039056388/","source":"海渊haiyuan","more_mode":null,"article_genre":"article","has_gallery":false,"video_play_count":0,"comments_count":4,"group_id":"6513140987039056388","is_related":true,"media_url":"/c/user/5797167091/"}] }, shareInfo: { shareUrl: https://m.toutiao.com/item/6513060428573049358/, abstract: 在github上发现有大牛用python做了一个加密货币,发出来给大家一起研究研究。。只是一个非常简单的,不安全的和不完整的实现在Python中作为教育材料的加密货币的区块链。换句话说,一个简单的比特币克隆。

小编推荐:欲学习电脑技术、系统维护、网络管理、编程开发和安全攻防等高端IT技术,请 点击这里 注册黑基账号,公开课频道价值万元IT培训教程免费学,让您少走弯路、事半功倍,好工作升职加薪!



免责声明:本文由投稿者转载自互联网,版权归原作者所有,文中所述不代表本站观点,若有侵权或转载等不当之处请联系我们处理,让我们一起为维护良好的互联网秩序而努力!联系方式见网站首页右下角。


鲜花

握手

雷人

路过

鸡蛋

相关阅读

最新评论

最新

返回顶部