本文采取图文并茂的方式,带你了解区块链的相关知识,并附有各种开发语言实现源码,作为参考,小伙伴们,坐好了,发车了!!!
This paper is graphically xff0c; takes you to the relevant knowledge of the block chain xff0c; is accompanied by the development language source xff0c; refers xff0c; partners xff0c; sits well xff0c; xff01; xff01; xff01; xff01; xff01; xff01; xff01;
区块链技术的前世今生
1991年,由Stuart Haber和W. Scott Stornetta第一次提出关于区块的加密保护链产品,随后分别由Ross J. Anderson与Bruce Schneier&John Kelsey分别在在1996年和1998年发表。与此同时,Nick Szabo在1998年进行了电子货币分散化的机制研究,他称此为比特金。2000年,Stefan Konst发表了加密保护链的统一理论,并提出了一整套实施方案。
xff0c, 1991; first proposed by Stuart Haber and W. Scott Stornetta for an encryption protection chain for blocks xff0c; then published by Ross J. Anderson and Bruce Schneier & John Kelsey in 1996 and 1998, respectively. Meanwhile, xff0c; Nick Szabo conducted a study of the mechanism for decentralization of electronic currencies in 1998 xff0c; he called it Bitkin. 2000 xff0c; Stefan Konst published a unified theory for the encryption protection chain xff0c; and proposed a set of implementation programmes.
2008年由中本聪第一次提出了区块链的概念,在随后的几年中,成为了电子货币比特币的核心组成部分:作为所有交易的公共账簿。通过利用点对点网络和分布式时间戳服务器,区块链数据库能够进行自主管理。为比特币而发明的区块链使它成为第一个解决重复消费问题的数字货币。比特币的设计已经成为其他应用程序的灵感来源。
The concept of block chains xff0c was first proposed in 2008 by China; xff0c in subsequent years; became a central component of the electronic currency bitcoin xff1a; as a public book of accounts for all transactions. Automation is possible through the use of point-to-point networks and distributed time stamp servers xff0c; and the block chain database. The sector chain invented for Bitcoin makes it the first digital currency to address the problem of double consumption. Bitcoin design has become a source of inspiration for other applications.
2008年10月,在中本聪的原始论文中,“区块”和“链”这两个字是被分开使用的,而在被广泛使用时被合称为区块-链,到2016年才被变成一个词:“区块链”。在2014年8月,比特币的区块链文件大小达到了20千兆字节。
October 2008 xff0c; xff0c in the original medium-brain paper; the words xff0c; xff0c in the " block" and "chain" are used separately; when used widely, they are collectively referred to as blocks - chain xff0c; they were not converted into a word xff1a; "block chain " until 2016. In August 2014 xff0c; the size of the block chain file in Bitcoin reached 20 gigabytes.
到2014年,“区块链2.0”成为一个关于去中心化区块链数据库的术语。对这个第二代可编程区块链,经济学家们认为它的成就是“它是一种编程语言,可以允许用户写出更精密和智能的协议,因此,当利润达到一定程度的时候,就能够从完成的货运订单或者共享证书的分红中获得收益”。区块链2.0技术跳过了交易和“价值交换中担任金钱和信息仲裁的中介机构”。它们被用来使人们远离全球化经济,使隐私得到保护,使人们“将掌握的信息兑换成货币”,并且有能力保证知识产权的所有者得到收益。第二代区块链技术使存储个人的“永久数字ID和形象”成为可能,并且对“潜在的社会财富分配”不平等提供解决方案。14 -15截至2016年,区块链2.0链下交易仍旧需要通过Oracle,使任何“基于时间或市场条件[确实需要]的外部数据或事件与区块链交互”。
By 2014 xff0c; xff0c; xff0c; xff0c; ff0c; xff0c; xff0c; xff0c; xff0c; xff0c; xff0c; xff0c) when profits reach a certain level; xff0c; xff0c; returns from completed shipping orders or the dividends of shared certificates. xfff0c. The second generation of block chain technology skips the transaction and #x0c's “value exchange agency for money and information arbitration”; they are used to keep people away from the globalized economy xff0c; to protect privacy xff0c; to make the information available “to exchange money” xff 0c; and to ensure that all owners of intellectual property rights receive the benefits.
在2016年,俄罗斯联邦中央证券所(NSD)宣布了一个基于区块链技术的试点项目。许多在音乐产业中具有监管权的机构开始利用区块链技术建立测试模型,用来征收版税和世界范围内的版权管理。2016年7月,IBM在新加坡开设了一个区块链创新研究中心。2016年11月,世界经济论坛的一个工作组举行会议,讨论了关于区块链政府治理模式的发展。据Accenture的一份关于创新理论发展的调查中显示,2016年区块链在经济领域获得的13.5%使用率,使其达到了早期开发阶段。在2016年,行业贸易组织共创了全球区块链论坛,这就是电子商业商会的前身。
A pilot project based on block chain technology was announced. Many institutions with regulatory powers in the music industry began to use block chain technology to build test models & #xff0c; used to collect royalties and copyright management worldwide. July 2016 xff0c; IBM opened a block chain innovation research centre in Singapore. November 2016 xff0c; a working group of the World Economic Forum held a meeting xff0c; discussed the development of a governance model on block chain.
区块链概念
狭义来讲,区块链是一种按照时间顺序将数据区块以顺序相连的方式组合成的一种链式数据结构, 并以密码学方式保证的不可篡改和不可伪造的分布式账本。
xff0c in the narrow sense; block chains are a chain structure of data blocks in chronological order that are sequentially linked to each other xff0c; and irrevocable and non-false distributed accounts guaranteed by cryptography.
广义来讲,区块链技术是利用块链式数据结构来验证与存储数据、利用分布式节点共识算法来生成和更新数据、利用密码学的方式保证数据传输和访问的安全、利用由自动化脚本代码组成的智能合约来编程和操作数据的一种全新的分布式基础架构与计算范式。
Broadly xff0c; block chain technology is a completely new distributed base structure and computational paradigm for programming and operating data using a smart contract consisting of automated scripting codes, using a block-chain data structure to validate and store data, using distributed node consensus algorithms to generate and update data, using cryptography to secure data transmission and access.
图文解释
去中心化的概念与最早的网络概念很相似
区块链如何工作
漫画解释
从概念到底层技术
协议层
所谓的协议层,就是指代最底层的技术。这个层次通常是一个完整的区块链产品,类似于我们电脑的操作系统,它维护着网络节点,仅提供Api供调用。通常官方会提供简单的客户端(通称为钱包),这个客户端钱包功能也很简单,只能建立地址、验证签名、转账支付、查看余额等。这个层次是一切的基础,构建了网络环境、搭建了交易通道、制定了节点奖励规则,至于你要交易什么,想干什么,它一概不过问,也过问不了。典型的例子,自然是比特币,还有各种二代币,比如莱特币等,本书介绍的亿书币也是。这个层次,是现阶段开发者聚集的地方,这说明加密货币仍在起步当中。
The so-called protocol layer xff0c; this level is usually a complete block chain product xff0c; an operating system similar to our computer xff0c; it maintains a network node xff0c; it provides only Api for call. The official provides a simple client xff08; commonly known as a wallet xff09; xff0c; this client wallet function is simple xff0c; only addresses, signatures, transfers, balances, etc. can be established. This level is the basis of everything xff0c; the network environment is built, trade routes are built, nodes are set up xff0c; there are also two currencies xff0c; it is not much more than a question of xff0c; it is also an example of xff kkkkkpkpkpkpkpk; it is also an example of currency kkpkkkpkp; it is an example.
从用到的技术来说,协议层主要包括网络编程、分布式算法、加密签名、数据存储技术等4个方面,其中网络编程能力是大家选择编程语言的主要考虑因素,因为分布式算法基本上属于业务逻辑上的实现,什么语言都可以做到,加密签名技术是直接简单的使用(请看书中相关的加密解密文章,不建议自由发挥,没有过多的编码逻辑),数据库技术也主要在使用层面,只有点对点网络的实现和并发处理才是开发的难点,所以对于那些网络编程能力强,对并发处理简单的语言,人们就特别偏爱。也因此,Nodejs开发区块链应用,逐渐变得更加流行,Go语言也在逐渐兴起。
In terms of technology used xff0c; the protocol layer consists mainly of four aspects of network programming, distribution algorithms, encryption signatures, data storage techniques xff0c; where network programming capacity is the main consideration in the choice of programming languages xff0c; because distribution algorithms are essentially business logic xff0c; which can be used xff0c; where encryption signature technology is directly and simply used xff08; where relevant encryption decipher articles in books xff0c; where free exercise is not recommended xff0c; where there is no excess of xff09; xff0c; where database technology is mainly used xff0c; where only point-to-point realization and co-processing of the network are difficult to develop xfff0c; where therefore, the development of simple language xx0xx is also becoming more popular; and where the development of the dex_kx ffffx has become more popular;
上面的架构设计图里,我把这个层面进一步分成了存储层和网络层。数据存储可以相对独立,选择自由度大一些,可以单独来讨论。选择的原则无非是性能和易用性。我们知道,系统的整体性能,主要取决于网络或数据存储的I/O性能,网络I/O优化空间不大,但是本地数据存储的I/O是可以优化的。比如,比特币选择的是谷歌的LevelDB,据说这个数据库读写性能很好,但是很多功能需要开发者自己实现。目前,困扰业界的一个重大问题是,加密货币交易处理量远不如现在中心化的支付系统(银行等),除了I/O,需要全方位的突破。
The structure above is designed in xff0c; I have divided this dimension further into storage and network layers. Data storage can be relatively independent xff0c; data storage can be more liberal xff0c; it can be discussed separately. The selection is based on the principles of performance and ease of use. We know xff0c; the overall performance of the system xff0c; the I/O performance xff0c; I/O optimized space is less than xff0c; but I/O storage of local data is optimized. For example, xff0c; Bitco chooses the current centralised payment system xff08; bank et. al.
分布式算法、加密签名等都要在实现点对点网络的过程中加以使用,所以自然是网络层的事情,也是编码的重点和难点,《Nodejs开发加密货币》全书分享的基本上就是这部分的内容。当然,也有把点对点网络的实现单独分开的,把节点查找、数据传输和验证等逻辑独立出来,而把共识算法、加密签名、数据存储等操作放在一起组成核心层。无论怎么组合,这两个部分都是最核心、最底层的部分,都是协议层的内容。
Distributive algorithms, encryption signatures, etc. are all used to achieve point-to-point networks xff0c; so it is naturally a network layer thing xff0c; it is also a code focus and difficulty xff0c; Nodejs Development of Encrypted Currency is basically shared in this part of the book. Of course xff0c; there are also xff0c that separates point-to-point networks; xff0c that separates node search, data transmission and validation logic; and xff0c that combines operations such as consensus algorithms, encryption signatures, data storage and so on.
扩展层
这个层面类似于电脑的驱动程序,是为了让区块链产品更加实用。目前有两类,一是各类交易市场,是法币兑换加密货币的重要渠道,实现简单,来钱快,成本低,但风险也大。二是针对某个方向的扩展实现,比如基于亿书侧链,可为第三方出版机构、论坛网站等内容生产商提供定制服务等。特别值得一提的就是大家听得最多的“智能合约”的概念,这是典型的扩展层面的应用开发。所谓“智能合约”就是“可编程合约”,或者叫做“合约智能化”,其中的“智能”是执行上的智能,也就是说达到某个条件,合约自动执行,比如自动转移证券、自动付款等,目前还没有比较成型的产品,但不可否认,这将是区块链技术重要的发展方向。
This level is similar to that of a computer driver xff0c; it is intended to make block chain products more practical. There are currently two types of xff0c; xff0c; xff0c; xff0c; xff0c; xyff0c; xff0c; xff0c; but the risk is also significant. xff0c; e.g., xxxff0c; intellectual is an executive smartness x0c; xxxxxxxx; xxxxxfx; fffffff; this is not yet an automatic technology transfer; x x c; ffffff ; etc.
扩展层使用的技术就没有什么限制了,可以包括很多,上面提到的分布式存储、机器学习、VR、物联网、大数据等等,都可以使用。编程语言的选择上,可以更加自由,因为可以与协议层完全分离,编程语言也可以与协议层使用的开发语言不相同。在开发上,除了在交易时与协议层进行交互之外,其他时候尽量不要与协议层的开发混在一起。这个层面与应用层更加接近,也可以理解为B/S架构的产品中的服务端(Server)。这样不仅在架构设计上更加科学,让区块链数据更小,网络更独立,同时也可以保证扩展层开发不受约束。
The technology used in the extended layer does not limit xff0c; it can include many xff0cs; distributed storage, machine learning, VR, object networking, big data, etc. xff0c; it can be used. The choice of programming language xff0c; it can be freer xff0c; it can be understood that xff0c can be completely separated from the protocol layer; programming language can be different from the development language used in the protocol layer. xff0c is developed; xff0c is developed in addition to interacting with the protocol layer at the time of the transaction; xff0c is used as little as possible with the protocol layer; this level is closer to the application level xff0c; it can also be understood that the service end of the B/S structure xff08; Serverff09; this way not only allows for a more scientific design of the architecture xff0c; making sector chain data smaller xff0c; network xff0c is more independent; and can also ensure that development is not constrained.
从这个层面来看,区块链可以架构开发任何类型的产品,不仅仅是用在金融行业。在未来,随着底层协议的更加完善,任何需要第三方支付的产品都可以方便的使用区块链技术;任何需要确权、征信和追溯的信息,都可以借助区块链来实现。我个人觉得,这个目标应该很快就能实现。
At this level, xff0c; block chains can structure the development of any type of product xff0c; not just in the financial sector. In the future xff0c; xff0c; as the bottom-of-the-line agreements improve xff0c; any product that requires third-party payment can easily use block chain technology xff1b; any information xff0c that requires certainty, message and retroactive information xff0c; it can be achieved through block chains. I personally think xff0c; this goal should be achieved soon.
应用层
这个层面类似于电脑中的各种软件程序,是普通人可以真正直接使用的产品,也可以理解为B/S架构的产品中的浏览器端(Browser)。这个层面的应用,目前几乎是空白。市场亟待出现这样的应用,引爆市场,形成真正的扩张之势,让区块链技术快速走进寻常百姓,服务于大众。大家使用的各类轻钱包(客户端),应该算作应用层最简单、最典型的应用。很快,亿书将基于亿书网络推出文档协作工具,这个就是典型的应用层的产品。
This level is similar to the various software programs in computers & #xff0c; a product that can be used directly by ordinary people & #xff0c; a browser end & #xff08; Browser) applications at this level & #xff0c; currently almost blank. The market is in need of such applications & #xff0c; the detonating market & #xff0c; the formation of a real expansionary & xff0c; the rapid entry of block chain technology into the normal population #xff0c; serving the general population. The kinds of light wallets used are #xff08; the client end #xff09; #xff0c; the simplest and most typical application should be counted.
限于当前区块链技术的发展,亿书只能从协议层出发,把目标指向应用层,同时为第三方开发者提供扩展层的强大支持。这样做既可以避免贪多,又可以避免无法落地,是真正理性的开发路线。因为纯粹的开发协议层或扩展层,无法真正理解和验证应用层,会脱离实际,让第三方开发者很难使用。如果仅仅考虑应用层,市面上又找不到真正牢固、易用的协议层或扩展层的产品。所以,我们只好全面发力,采取完全开源开放的态度,通过社区的力量,共同去做一件有意义的事情,也算为中国区块链技术发展做点技术积累和微薄贡献。
Limited to the development of the current block chain technology xff0c; billion books can only start from the protocol layer xff0c; target the application level xff0c; and provide powerful support to third-party developers. This would avoid greed and xff0c; avoid landlessness xff0c; and a genuinely rational development route. Because of the pure development agreement layer or extension layer xff0c; failure to truly understand and validate the application layer xff0c; separation from the actual xff0c; making it difficult for third-party developers to use it.
编程实现
很多小伙伴,习惯结合自己的技术背景,来理解上面的架构设计。这里,结合具体的编程语言,简单介绍几款产品,仅供参考。
Many small partners & #xff0c; used to combine their technical background & #xff0c; used to understand the architecture above. Here & #xff0c; combined with specific programming language & #xff0c; briefly describing several products & #xff0c; for information only.
(1)C/C++
这两个语言是无法逾越的,任何开发遇到瓶颈,基本上都会找到它们,自然应该排在第一位要介绍的。同时,区块链技术的鼻祖,比特币(协议层)就是用C++语言开发的,而且目前为止,没有比比特币更加成功的区块链产品。所以,无论你使用什么语言开发,在正式进入这个行业的过程中,都应该先研究研究比特币。比特币官方客户端钱包用的Qt,第三方钱包有Python语言开发的,特别是第三方整理的开发库(Api包)很多是Nodejs设计的。比特币的架构,与上面的架构设计基本相同,另外,因为共识算法采用的是工作量证明机制(PoW:Proof of work),还有一些特殊的挖矿的过程。其他竞争币都是直接来自比特币的分支,所以编程语言相同,具体的技术选型和技术实现上可能有所改进,比如:莱特币,使用了其他的加密算法。
The two languages are unstoppable xff0c; any development encounters bottlenecks xff0c; they are basically found xff0c; nature should be ranked first. At the same time xff0c; Noose xff0c of block chain technology; Bitcoin xff08; Protocol layer xff09; C43; xff0c; xffoc of language development; so far xff0c; no more successful sector chain product than Bitcoco; so xff0c; development of xff0c; Apox; xffoc; study of Bitco; official customer wallets of Bitcoin; x#ff#ff#x; other x#0x; ffx#jpx; pffffffx; #0xxxxxx; xxxxxxxxx#pjpfx; ffffffx; pjfffffx.p.p.x.x.x.x.x.x.p.x.p.x.x.x.p.x.x.x.x.p.p.p.p.p.x.p.x.p.p.p.p.k.x.x.x.x.p.f.f.p.f.p.f.f.f.
官方网站:https://bitcoin.org/
源码库:https://github.com/bitcoin
(2)Nodejs/Javascript
Nodejs平台强大的网络编程能力,以及js脚本语言的简单快捷,在区块链领域自然少不了它的身影。亿书便是这样一个区块链产品,亿书币是它的协议层,使用了著名的express开发框架,基于http协议开发而成。同时,它采用了授权股权证明机制(DPoS),算法上的改进,让它在处理交易时更加轻量,处理能力大大提升。它提供了强大的协作机制,为数字出版、版权保护提供了便利;扩展了侧链功能,可以基于它开发任何去中心化的应用,从而为专业作者、博客爱好者和开发者提供很多方便。《Nodejs开发加密货币》这本书完整分享了它的源码,从区块链基础概念到代码实现,从基本原理到开发设计思路,都做了比较详细的探索,目前为止,从协议层面深入代码讲解区块链技术实现的书籍极少,这算作一本。
The great network programming capacity of the Nodejs platform xff0c; and the simple quickness of the js script language xff0c; it naturally does not lose sight of it in the area of block chains. The billion books are such a block chain product xff0c; the billion books are its compact layer xff0c; it uses the famous express development framework xff0c; it is developed on the basis of the http protocol. xff0c; it has adopted an enabling equity certification mechanism xff08; xffff09; xff0c; algorithms improvements xff0c; it has been made lighter when dealing with transactions xff0c; it has provided a powerful collaborative mechanism xffoc; it has facilitated digital publishing, copyright protection ff1b; it has expanded its side-chain functionality #x0x; it has developed a base of technology from which is currently zero to zero; it has been able to develop any centralized applications xff0c; it has been able to achieve a significant number of #xx#ff#dex.ff.
源码库:https://github.com/Ebookcoin
(3)Python
如果是Python语言爱好者,我建议研究研究以太坊(Ethereum)的Python实现。尽管因为The Dao事件闹得沸沸扬扬,但从技术实现的角度来说,仍然值得参考学习。以太坊官方定位为一种开发管理分布式应用的平台,主攻方向就是“智能合约”,并为其定制了一种编程语言Solidity。以太坊的核心是以太坊虚拟机(EVM),允许用户按照自己的意愿创建操作。以太坊给出了Go、Java、Python等多语言的实现。其中以python为基础的实现主要包括三个部分:Pyethapp是客户端部分;pyethereum是核心库,实现了区块链、以太坊模拟机和挖矿等功能;pydevp2p是点对点网络库,实现了节点发现、合约代码传输、加密签名等功能,这三者组合在一起就是完整的区块链实现,后面两个核心库共同组成了协议层。另外,go-ethereum是go语言的完整实现;Ethereum(J) 是纯Java实现,它作为可以嵌入任何Java/Scala项目的库提供。客户端方面,还有Rust、Ruby、Javascript等语言的实现。
If it is a Python language lover & #xff0c; if it is a Python language lover & #xff08; Etheeum) Python; although it has a boiling #xff0c; but from the point of technological realization xff0c; it is worth learning. If it is officially located as a platform for the development of a distributed application of management & #xff0c; the main direction of the attack is the “smart contract” & xff0c; customizes a programming language solidity for it. The core of the cell is a virtual machine #xff08; xffc; ffec; allows users to create operations according to their wishes.
源码库:https://github.com/ethereum/pyethapp
(4)Go
在多核时代,Go语言备受喜爱,它可以让你用同步方式轻松实现高并发,特别是在分布式系统、网络编程等领域,应用非常广。所以,在区块链开发领域,也有很多使用Go语言的项目。其中,由linux基金会主导的超级账本(HyperLeger),版本库的名字叫Fabric,就是其中一个。该项目试图为新一代的事务应用创建一种开放的分布式账本标准,支持许可式区块链(这种方式可能无法再现比特币那种强大的网络效应)。Fabric的开发环境建立在VirtualBox虚拟机上,部署环境可以自建网络,也可以直接部署在BlueMix上,部署方式可docker化,支持用Go和JavaScript开发智能合约。它采用PBFT分布式算法,网络编程方面用gRPC来做P2P通讯,使用 Protocol Buffer来序列化要传递的数据结构。在架构设计上,Fabric可能与比特币等区块链产品有所不同,但是上述基本组成部分还是不可或缺的。
In the multi-nuclear era xff0c; in Go, popular xff0c; it allows you to easily achieve high and high distribution xff0c by synchronizing; in particular in the area of distribution systems, network programming xff0c; very widely applied. So xff0c; in the area of block development xff0c; in the area of area development xff0c; in the Go language xff0c; in the superbook xff08, dominated by the Linux Foundation; in the form of HyperLeger xff09; xff0c; version Fabrić #xff0c; in the form of a basic network based on VirtualBox; in the form of an open distribution book for the new generation of services #xffp; in the form of a permit block #xff #ff08; in the form of a network designed to recreate the above-mentioned xff09; in the form of a network #Päxfx0; in the form of a basic network based on the Fabriic; in the use of vtox & & & & & & & & #tbrfffffts; in the use of & & & #txxffffts; in the use of #s.
官方网站:https://www.hyperledger.org/
源码库:https://github.com/hyperledger
注意:本文仅代表博主个人观点,供大家参考,欢迎大家评论指正,部分知识点和图片均来自于网络,博主不承担任何责任。转载请注明出处。
notes xff1a; only represents the blogger's personal views xff0c; for information xff0c; welcome comments xff0c; some points of knowledge and pictures are from the network xff0c; the owner does not assume any responsibility.
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论