区块链c端应用小程序_区块链如何真正起作用? 我建立了一个应用程序向您展示。...
区块链c端应用小程序
by Sean Han
通过肖恩·韩
区块链如何真正起作用? 我建立了一个应用程序向您展示。 (How does blockchain really work? I built an app to show you.)
According to Wikipedia, a blockchain is:
根据维基百科,一个区块链是:
A distributed database that is used to maintain a continuously growing list of records, called blocks.
一种分布式数据库,用于维护不断增长的记录列表(称为块) 。
That sounds nice, but how does it work?
听起来不错,但如何运作?
To illustrate a blockchain, we will use an open source command-line interface called Blockchain CLI.
为了说明区块链,我们将使用一个名为Blockchain CLI的开源命令行界面。
I also built a browser-based version of this here.
我还在这里构建了基于浏览器的版本 。
安装命令行界面版本 (Installing the Command-Line Interface version)
If you haven’t already, install Node.js.
如果尚未安装Node.js。
Then run the following in your terminal:
然后在终端中运行以下命令:
# Clone this repository
$ git clone https://github.com/seanseany/blockchain-cli# Go into the repository
$ cd blockchain-cli# Install dependencies
$ npm install# Run the app
$ npm start
You should see ? Welcome to Blockchain CLI!a
nd a blockchain →
prompt ready to take commands.
你应该看到? Welcome to Blockchain CLI!a
? Welcome to Blockchain CLI!a
和ab lockchain →
提示准备好接受命令。
块是什么样的? (What does a block look like?)
To see your current blockchain, enter blockchain
or bc
into the command prompt. You should see a block like the image below.
要查看您当前的区块链,请在命令提示符下输入blockchain
或bc
。 您应该看到如下图所示的块。
Index (Block #): Which block is it? (Genesis block has index 0)
索引(块号):它是哪个块? (创世记块的索引为0)
Hash: Is the block valid?
哈希:该区块有效吗?
Previous Hash: Is the previous block valid?
上一个哈希:上一个区块有效吗?
Timestamp: When was the block added?
时间戳记:什么时候添加了该区块?
Data: What information is stored on the block?
数据:块上存储了什么信息?
Nonce: How many iterations did we go through before we found a valid block?
Nonce:在找到有效块之前,我们经历了几次迭代?
创世块 (Genesis Block)
Every blockchain will start with the? Genesis Block.
As you will see later, each block on the blockchain is dependent on the previous block. So, the Genesis block is needed to mine our first block.
每个区块链都将以? Genesis Block.
? Genesis Block.
如您将在后面看到的,区块链上的每个块都依赖于前一个块。 因此,需要Genesis区块来挖掘我们的第一个区块。
开采新区块时会发生什么? (What happens when a new block is mined?)
Let’s mine our first block. Enter mine freeCodeCamp♥︎
into the prompt.
让我们开采我们的第一个街区。 在提示中输入mine freeCodeCamp♥︎
。
The blockchain looks at the latest block on the blockchain for the index and previous hash. In this case Genesis block is the latest block.
区块链将查看区块链上的最新区块以获取索引和先前的哈希值。 在这种情况下,Genesis块是最新的块。
Index: o+1 = 1
索引: o + 1 = 1
Previous Hash: 0000018035a828da0…
上一个哈希: 0000018035a828da0…
Timestamp: When the block is added
时间戳:添加块时
Data: freeCodeCamp❤
数据: freeCodeCamp❤
Hash: ??
哈希:
Nonce: ??
Nonce: ??
哈希是如何计算的? (How is the hash calculated?)
A hash value is a numeric value of a fixed length that uniquely identifies data.
哈希值是唯一标识数据的固定长度的数字值 。
The hash is calculated by taking the index, previous block hash, timestamp, block data, and nonce as input.
通过将索引,先前的块哈希,时间戳,块数据和随机数作为输入来计算哈希。
CryptoJS.SHA256(index + previousHash + timestamp + data + nonce)
The SHA256 algorithm will calculate a unique hash, given those inputs. The same inputs will always return the same hash.
给定这些输入,SHA256算法将计算唯一的哈希。 相同的输入将始终返回相同的哈希。
您是否注意到区块哈希中的四个前导0? (Did you notice the four leading 0’s in the block hash?)
The four leading 0’s is a minimum requirement for a valid hash. The number of leading 0’s required is called difficulty.
有效散列的最低要求是四个前导0。 所需的前导0的数字称为难度 。
function isValidHashDifficulty(hash, difficulty) {for (var i = 0, b = hash.length; i < b; i ++) {if (hash[i] !== '0') {break;}}return i >= difficulty;
}
This is also known as the Proof-of-Work system.
这也称为工作量证明系统 。
什么是随机数? (What’s a nonce?)
A nonce is a number used to find a valid hash.
随机数是用于查找有效哈希的数字。
let nonce = 0;
let hash;
let input;while(!isValidHashDifficulty(hash)) { nonce = nonce + 1;input = index + previousHash + timestamp + data + nonce;hash = CryptoJS.SHA256(input)
}
The nonce iterates until the hash is valid. In our case, a valid hash has at least four leading 0’s. The process of finding a nonce that corresponds to a valid hash is mining.
随机数迭代直到哈希有效为止。 在我们的情况下,有效哈希至少具有四个前导0。 查找与有效哈希对应的随机数的过程是采矿 。
As the difficulty increases, the number of possible valid hashes decreases. With less possible valid hashes, it takes more processing power to find a valid hash.
随着难度的增加 ,有效哈希的数量会减少 。 有效哈希越少,查找有效哈希就需要更多处理能力。
为什么这么重要? (Why does this matter?)
It matters because it keeps the blockchain immutable.
这很重要,因为它使区块链保持不变。
If we have the following blockchain A → B → C, and someone wants to change data on Block A. This is what happens:
如果我们有以下区块链A→B→C,并且有人想要更改区块A上的数据,则会发生这种情况:
- Data changes on Block A.数据在A块上更改。
- Block A’s hash changes because data is used to calculate the hash.块A的哈希值发生变化,因为数据用于计算哈希值。
- Block A becomes invalid because its hash no longer has four leading 0’s.块A无效,因为其哈希不再具有四个前导0。
- Block B’s hash changes because Block A’s hash was used to calculate Block B’s hash.块B的哈希值发生变化,因为使用了块A的哈希值来计算块B的哈希值。
- Block B becomes invalid because its hash no longer has four leading 0's.块B无效,因为其哈希不再具有四个前导0。
- Block C’s hash changes because Block B’s hash was used to calculate Block C’s hash.块C的哈希值发生变化,因为使用了块B的哈希值来计算块C的哈希值。
- Block C becomes invalid because its hash no longer has four leading 0's.块C无效,因为其哈希不再具有四个前导0。
The only way to mutate a block would be to mine the block again, and all the blocks after. Since new blocks are always being added, it’s nearly impossible to mutate the blockchain.
变异方块的唯一方法是再次挖掘该方块,然后再挖掘所有方块。 由于总是会添加新的块,因此几乎不可能对区块链进行变异。
I hope this tutorial was helpful for you!
希望本教程对您有所帮助!
If you would like to checkout a web version of the demo, head on over to http://blockchaindemo.io
如果您想查看该演示的网络版本,请转到http://blockchaindemo.io
翻译自: https://www.freecodecamp.org/news/how-does-blockchain-really-work-i-built-an-app-to-show-you-6b70cd4caf7d/
区块链c端应用小程序
相关文章:

HDU 4913 Least common multiple
/* hdu4913 Least common multiple http://acm.hdu.edu.cn/showproblem.php?pid4913 离散化 线段树 统计逆序数思想 tips: 1、线段树中一定要到处都取模,否则wa。。。 2、lazy是乘积的形式出现,不是加和*/ #include <cstdio> #include <algori…

JS ES6 实用笔记
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 这篇博文我会一直更新。 一.导出导入的两中方式 1.export //demo1.js export const a 6 导入语法为: import {a} form demo1 2.export default //demo2.js export default const b 6 …

extjs editgrid增加一行
Ext.onReady(function(){ /* * EditorGridPanel的工作过程 * 1、用户点击单元格 * 2、单元格按照预设的组件显示单元格的内容并处于编辑状态 * 3、离开单元格的编辑状态 * 4、更新编辑后的内容,出现三角号表示已经被修改过 * 5、程序内部变化:将记录设置…

unity 骨骼击碎_保证击碎$ 100挑战的创新策略
unity 骨骼击碎by Glenn Gonda由Glenn Gonda 保证击碎$ 100挑战的创新策略 (A Creative Strategy Guaranteed to Crush the $100 Challenge) Before I became a software engineer, I made my living as a recording studio engineer. I have a non-traditional background an…

mac下安装libpng环境
用go写一个爬虫工具时需要使用一个go的库,而这个库有需要使用libpng库,不然编译就会提示说 png.h找不到等之类的信息,于是想到应该和windows一样需要安装gcc环境,然后让gcc里安装libpng这个库, 解决办法: 终…

linux oracle修改编码utf8
$ sqlplus /nolog SQL> connect sys/oracle as sysdba SQL> startup 如何设置ORACLE数据库的编码(ZHS16GBK)修改成UTF8 SQL> shutdown immediate; SQL> startup mount; SQL> alter system enable restricted session; SQL> alter sy…

Vue.js 数据绑定渲染Demo
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 <div id"app">{{ message }} </div>var app new Vue({el: #app,data: {message: Hello Vue!} })Hello Vue!

angular搭建项目步骤_建立健康的Angular项目应采取的步骤
angular搭建项目步骤by Ashish Gaikwad通过Ashish Gaikwad 建立健康的Angular项目应采取的步骤 (Steps you should take to build a healthy Angular project) 使用Jenkins SonarQube创建您的“ Angular Fitbit” (Create your “Angular Fitbit” with Jenkins SonarQube) …

数据库的三大范式和事物
来源:http://blog.csdn.net/w__yi/article/details/19934319 1.1 第一范式(1NF)无重复的列 1.2 第二范式(2NF)属性完全依赖于主键 [ 消除部分子函数依赖 ] 1.3 第三范式(3NF)属性不依赖于其它非…

过滤器和包装器
作者:禅楼望月 过滤器要做的事情 请求过滤器 完成安全检查 重新格式化请求首部或体 建立请求审计或日志响应过滤器 压缩响应流 追加或修改响应流 创建一个完全不同的响应注意不能把过滤器的顺序依赖性硬编码进程序中,它应该由DD控制。 过滤器很像Servlet…

Missing space before value for key 'path'vue.js解决空格报错
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 找到 webpack.base.config.js文件注释掉下面的东西!! module: { rules: [ /*{ test: /\.(js|vue)$/, loader: eslint-loader, enforce: "p…

现代hy-9600音响_从音响工程师到软件工程师-为什么我要学习编码
现代hy-9600音响by Kalalau Cantrell通过Kalalau Cantrell 从音响工程师到软件工程师-为什么我要学习编码 (From Sound Engineer to Software Engineer — Why I’m Learning to Code) I seriously started teaching myself to code several months ago. I say “seriously” …

微信服务号、公众号、企业号注册
转载于:https://www.cnblogs.com/zhoulaoshi/p/6536850.html

a标签onclick事件解析
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 简单介绍<a>标签的常用点击事件的写法及作用 a href"javascript:void(0);" οnclick"js_method()" //javascript:void(0);作用是返回undefined,地址不发生跳转&am…

安卓版文字扫描识别软件
安卓版文字扫描识别软件 文字识别软件被越来越多的人使用,在使用的过程中也发现了一些问题。总结这些问题发现,很多人对软件能够批量识别这个问题比较关注。如果实现批量识别就可以节省时间。但是一些软件还不能实现批量识别,还有的软件能够做…

中级前端笔试_在短短8个月内如何获得中级前端开发人员的角色
中级前端笔试by Matthew Burfield通过马修伯菲尔德(Matthew Burfield) 在短短8个月内如何获得中级前端开发人员的角色 (How I got a mid-level front end developer role in just 8 months) Three weeks ago I landed a mid-level front-end developer role at a startup. Our…

用stm32f10x建立新的工程重要步骤
stm32f10x系列新建空的工程主要原理: 1.添加启动文件 不同的芯片类型的启动文件的容量是不同的,选择适合该芯片的容量作为启动文件。 注意:启动文件是汇编语言编写的,所以文件的后缀名为.s 2.添加时钟配置 配置文件 stm32f10x.的系…

随机生成6位图片验证码
1. [代码][C#]代码 /// <summary> /// PicHandler1 的摘要说明 /// </summary> public class PicHandler1 : IHttpHandler, IRequiresSessionState { private string mCheckNo string.Empty; protected ImgBuilder _ImgBuilder new I…

html 页面传值
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 直接上代码,JS保存全局变量的三种方式。 创建一个新的JS文件, //quanju.js window.localStorage.JQa"JQA"; window.localStorage.setItem(JQb,JQB);//利用localStora…

node.js的开发流程_Node.js子流程:您需要了解的一切
node.js的开发流程by Samer Buna通过Samer Buna Node.js子流程:您需要了解的一切 (Node.js Child Processes: Everything you need to know) 如何使用spawn(),exec(),execFile()和fork() (How to use spawn(), exec(), execFile(), and fork…

对象存在性检测集中管理
在中大型业务系统中, 常常需要从数据库中查询某个实体对象。 在进行处理之前, 必须先检测该实体是否存在,以增强系统的健壮性。 不过, 检测代码充斥在主业务流程中又会大大降低业务逻辑的清晰性, 最好集中起来进行管理…

20155204 2016-2017-2 《Java程序设计》第3周学习总结
20155204 2016-2017-2 《Java程序设计》第3周学习总结 教材学习内容总结 一个原始码中可以有多个类定义,但只能有一个公开类。留心Scanner对于每一种类型的nextxxxx()方法以Java开头的都是API提供的类使用Integer.valueOf()也是为基本类型建立打包器的方式之一Integ…

js表单提交,支持图片上传,包含后端php代码
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 <html><head><meta http-equiv"Content-Type" content"charsetutf-8" /><title>图片上传成功</title></head><body><form name"…

如何破解汽车-快速的速成课程
by Kenny Kuchera肯尼库切拉(Kenny Kuchera) 如何破解汽车-快速的速成课程 (How to hack a car — a quick crash-course) The goal of this article is to get you started hacking cars — fast, cheap, and easy. In order to do this, we’ll spoof the RPM gauge as an e…

367. Valid Perfect Square
题目: Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt. Example 1: Input: 16 Returns: TrueExample 2: Input: 14 Returns: False 链接…

使用reuseport和recvmmsg优化UDP服务器
http://skoo.me/system/2014/03/18/udp-server-performance/ http://www.helplib.net/s/linux.die/65_3223/man-2-recvmmsg.shtml recvmmsg(2) - Linux man page转载于:https://www.cnblogs.com/jingzhishen/p/4145732.html

js把for循环出来的数据存入数组
微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 var obj [];for(var i 0;i<obj.length;i){arr.push(obj[i]);}; console.obj(arr); 1:obj是一个数组对象 2:push()方法是数组的栈底添加 意思是往数组的底部添加 3:…

flexbox布局_这是您可以使用FlexBox制作的5种布局
flexbox布局The CSS Flexible Box Layout — Flexbox — provides a simple solution to the design and layout problems designers and developers have faced with CSS. Let me show you how to use it to generate some common layouts and challenges that you will face …

数据结构之线性表
数据结构之线性表 目录 概述顺表特点 顺表的操作 准备 创建顺表 查询顺表长度 遍历顺表 按序查找 按值查找 插入 删除 链表实际使用概述 线性表是一种线性的存储结构,表头有唯一后继元素,表尾有唯一前驱元素,表中的元素既有前驱又有后继 顺表…

【BZOJ-3456】城市规划 CDQ分治 + NTT
题目链接 http://www.lydsy.com/JudgeOnline/problem.php?id3456 Solution 这个问题可以考虑dp,利用补集思想 N个点的简单图总数量为$2^{\binom{N}{2}}$,要求的是简单联通图,所以可以用总量减不连通的。 不连通的可以通过枚举与某个固定点的…