比特币程序

by Sean Han

通过肖恩·韩

比特币如何运作? 我建立了一个应用程序向您展示。 (How does bitcoin work? I built an app to show you.)

As Bitcoin rose to unprecedented levels, it caught my attention & curiosity. I wondered, how does bitcoin really work?

随着比特币涨到前所未有的水平,它引起了我的注意和好奇。 我想知道,比特币真的如何工作?

As I went down the blockchain rabbit hole, I found that many resources rarely go beyond the “revolutionary”, “distributed” and “immutable” dialogue. Many talk about the what, but not so much the why and how.

当我沿着区块链的兔子洞钻进去时,我发现许多资源很少超出“革命性”“分布式”“不变”对话。 许多人谈论什么 , 但不是什么原因方式

I resorted to reading technical papers and source code to uncover this black box. I started sharing what I learned by building apps that demonstrated the inner workings of the blockchain.

我求助于阅读技术论文和源代码来发现这个黑匣子。 我通过构建演示区块链内部工作原理的应用程序开始分享我学到的东西。

What I realized was bitcoin was just blockchain + transactions. This article will cover the transactions part of the equation. If you would like a refresher on blockchain, checkout Blockchain Demo or this article.

我意识到比特币只是区块链+交易。 本文将介绍等式的交易部分。 如果您想在区块链上复习一下,请查看Blockchain Demo或本文 。

A block on the blockchain has the following parts:

区块链上的区块包含以下部分:

  • Index (Block #1): Which block is it?

    索引 (第1块) 它是哪个块?

  • Hash (#00001834d29f33…): Is the block valid?

    哈希 (#00001834d29f33…) 区块有效吗?

  • Previous Hash (#000dc75…): Is the previous block valid?

    上一个哈希 (#000dc75…) 上一个块有效吗?

  • Timestamp (Tue, 19 Dec 2017 …): When was the block added?

    时间戳记 (2017年12月19日,星期二…) 什么时候添加了图块?

  • Data (I ❤️ freeCodeCamp): What information is stored on the block?

    数据 (I❤️freeCodeCamp) 块上存储了什么信息?

  • Nonce (1263): How many iterations did we go through before we found a valid block?

    Nonce (1263) 在找到有效块之前,我们经历了几次迭代?

Instead of having text (I ❤️ freeCodeCamp) as data, cryptocurrencies have transactions as data.

加密货币不是将文本 (I❤️freeCodeCamp)用作数据,而是将交易作为数据。

什么是交易? (What is a transaction?)

Transactions are a record of payment between two parties. When there is an exchange of value, a transaction is created to record it.

交易是双方之间付款的记录。 当存在价值交换时,将创建一个交易来记录它。

For example, let’s say Satoshi has 100 coins.

例如,假设中本聪有100个硬币。

He wants to pay Dean 5 coins, with a mining fee of 1 coin. He uses the 100 coins he has to make the transaction. He expects to have 94 coins in change.

他想付给Dean 5枚硬币,采矿费为1枚硬币。 他使用必须进行交易的100个硬币。 他预计将有94个硬币找零。

When Satoshi mines a new block with the transaction above, he is rewarded with 100 new coins.

当Satoshi在上述交易中开采一个新区块时,他将获得100个新硬币的奖励。

The example above will create the following transaction outputs (to be explained):

上面的示例将创建以下事务输出 (待解释):

Since the initial 100 coins Satoshi had was used as an input to create the above transaction, the initial 100 coins is now spent. (to be explained)

由于使用Satoshi最初的100个硬币作为创建上述交易的输入 ,因此现在已花费了最初的100个硬币。 (待解释)

The above concepts will be explained next.

接下来将解释以上概念。

三种交易类型: (Three types of transactions:)

  1. Reward — Satoshi rewarded with 100 coins for mining new block

    奖励 -中智奖励100枚硬币,用于挖掘新区块

  2. Regular — Satoshi paid Dean 5 coins with change of 94 coins

    常规 — Satoshi向Dean支付了5个硬币,其中有94个硬币找零

  3. Fee — Mining fee of 1 for whoever mines the transaction (Satoshi in example above)

    费用 -进行交易的任何人的挖矿费用为1(上例中为Satoshi)

交易 (Transaction)

A transaction consists of four parts:

交易包括四个部分:

  1. Inputs — Where value is coming from

    输入- 价值来自何处

  2. Outputs — Where value is going to

    输出- 价值将流向何处

  3. Hash —Uniquely identifies the transaction (using inputs & outputs)哈希-唯一标识交易(使用输入和输出)
  4. Type — Reward, Regular, or Fee类型-奖励,常规或费用

输出-价值将流向何处 (Outputs — Where value is going to)

An output has two parts:

输出分为两部分:

  1. Address — What is the public wallet address to send the coins to?地址-将硬币发送到的公共钱包地址是什么?
  2. Amount — How many coins?金额-多少个硬币?

输入-价值来自何处 (Inputs — Where value is coming from)

An input has to come from a previous output. However, an output can only be used as input once. When an output is used, it is considered to be spent. Outputs that have not been used as input are unspent.

输入必须来自先前的输出 。 但是,输出只能用作一次输入。 使用输出时,将认为已花费 。 尚未用作输入的输出未使用

An input has five parts:

输入包含五个部分:

  1. Transaction Hash —Transaction hash of the (unspent) output交易哈希-(未使用)输出的交易哈希
  2. Output Index — The index of the (unspent) output in the transaction输出索引-事务中(未用)输出的索引
  3. Amount — Amount of the (unspent) output金额-(未使用)输出的金额
  4. Address — Address of the (unspent) output地址-(未使用)输出的地址
  5. Signature — Signed by the Address’s private key签名-由地址的私钥签名

奖励交易 (Reward Transaction)

Reward transactions are created as a result of finding a valid block on the blockchain. As a result, reward transactions do not have any inputs because it creates new coins.

奖励交易的创建是在区块链上找到有效区块的结果。 结果,奖励交易没有任何输入,因为它创建了新硬币。

For example: Satoshi mined a new block with a mining reward of 100. The transaction on the block will look like this:

例如: Satoshi开采了一个新区块,其采矿奖励为100。该区块上的交易如​​下所示:

Type: Reward

类型:奖励

Inputs: None

输入:

Outputs:

输出:

  • Address: Satoshi’s public wallet address

    地址:中本聪的公开钱包地址

  • Amount: 100 (reward specified by the cryptocurrency)

    数量: 100(由加密货币指定的奖励)

Hash: ?(inputs + outputs) = 000abcdefg…

哈希: ?(输入+输出)= 000abcdefg…

定期交易 (Regular Transaction)

Regular transactions are transactions created when one party pays another.

常规交易是当一方付款给另一方时创建的交易。

Continued example: Satoshi uses the (unspent) output from the reward transaction as an input to pay Dean 5 coins. He specifies a mining fee of 1 coin.

续示例: Satoshi使用奖励交易的(未花费) 输出作为输入,以支付Dean 5个硬币。 他指定1枚硬币的采矿费。

Type: Regular

类型:常规

Inputs:

输入:

  • Transaction Hash: 000abcdefg… (hash of reward transaction above)

    交易哈希: 000abcdefg…(上述奖励交易的哈希)

  • Output Index: 0 (first index of output is 0)

    输出索引: 0(输出的第一个索引为0)

  • Amount: 100 (output amount)

    数量: 100(输出数量)

  • Address: Satoshi’s public wallet address (output address)

    地址:中本聪的公开钱包地址(输出地址)

  • Signature: Satoshi signs this input with his private key

    签名: Satoshi用​​他的私钥签署此输入

Outputs:

输出:

Output 1: (index 0)

输出1 :(索引0)

  • Address: Dean’s address

    地址 :院长的地址

  • Amount: 5 coins

    数量: 5个硬币

Output 2: (index 1)

输出2 :(索引1)

  • Address: Satoshi’s address

    地址:中本聪的地址

  • Amount: 94 coins= 100 - 5 (payment) - 1 (fee)

    数量: 94个硬币= 100-5(付款)-1(费用)

  1. The first output is the payment going to Dean.

    第一个输出是支付给Dean的款项

  2. The second output is the change going back to Satoshi

    第二个输出是回到Satoshi的更改

Because Satoshi’s reward transaction output (from the previous example) has been used as an input for this payment, it is now spent and cannot be used again. If it is used again, then there is double spending.

由于Satoshi的奖励交易输出(来自上一个示例)已用作此付款的输入,因此现在已用完,不能再次使用 。 如果再次使用它,则有双重支出 。

为什么不加起来呢??? (Why doesn’t it add up???)

The total input amount is 100.The total output amount is 5 + 94 = 99.

总输入量为100.总输出量为5 + 94 = 99。

In the example, Satoshi specified a mining fee of 1 coin. The difference between inputs and outputs of a regular transaction is the mining fee.

在示例中,中本聪指定了1枚硬币的采矿费。 正常交易的输入和输出之间的差额是采矿费

Inputs must be greater or equal to outputs. If inputs and outputs are equal, then there is no mining fee.

输入必须大于或等于输出。 如果投入和产出相等, 则不收取采矿费

费用交易 (Fee Transaction)

Whoever mines the above regular transaction will add the mining fee transaction. Because there was a deficit of 1 in the regular transaction, the fee amount is 1.

挖矿上述常规交易的任何人都将添加挖矿费用交易。 由于常规交易中存在1的赤字,因此费用金额为1。

Continued Example: Bob mines Satoshi and Dean’s transaction.

续例: Bob挖掘Satoshi和Dean的交易。

Type: Fee

类型:费用

Inputs: None

输入:无

Outputs:

输出:

  • Address: Bob’s public wallet address

    地址: Bob的公共钱包地址

  • Amount: 1 (fee, difference of regular transaction input and output)

    金额: 1(费用,常规交易输入和输出的差额)

Because Bob mined this transaction to the new block, there will be a reward transaction of 100 to Bob.

由于鲍勃将这笔交易开采到了新区块,因此鲍勃将获得100笔奖励交易。

在区块链上: (On the blockchain:)

最终余额: (Final Balances:)

Satoshi: 94 = 100 (reward) - 5 (payment) - 1 (fee)Dean: 5 (payment from Satoshi)Bob: 101 = 100 (reward from mining new block with transaction) + 1 (fee)

聪: 94 = 100(奖励)-5(支付)-1(费用)院长: 5 (从聪支付)鲍勃: 101 = 100(从交易中开采新区块获得的奖励)+ 1(费用)

Total currencies in circulation: 200 = 94 (Satoshi)+ 5 (Dean)+ 101 (Bob)

流通货币总数: 200 = 94(Satoshi)+ 5(Dean)+ 101(Bob)

Two blocks were mined, and each block has a reward of 100, so there should be 200 coins in circulation.

开采了两个区块,每个区块的奖励为100,因此应该有200个硬币在流通。

结论 (Conclusion)

On a new block, regular and fee inputs and output totals must equal. This ensures that only reward transactions generate new coins.

在一个新区块中, 常规和费用输入与输出总计必须相等 。 这样可以确保只有奖励交易才能生成新硬币。

Deficits from regular outputs are offset with fee transaction outputs. Leaving the only output surplus to be reward transactions.

常规产出的赤字被费用交易的产出抵消。 剩下的唯一产出盈余是奖励交易。

在http://coindemo.io上尝试一下 (Try it yourself at http://coindemo.io)

翻译自: https://www.freecodecamp.org/news/how-does-bitcoin-work-i-built-an-app-to-show-you-f9fcd50bdd0d/

比特币程序

比特币程序_比特币如何运作? 我建立了一个应用程序向您展示。相关推荐

  1. 区块链c端应用小程序_区块链如何真正起作用? 我建立了一个应用程序向您展示。...

    区块链c端应用小程序 by Sean Han 通过肖恩·韩 区块链如何真正起作用? 我建立了一个应用程序向您展示. (How does blockchain really work? I built ...

  2. 小程序制作预算_做一个小程序的大概预算是多少?做一个小程序大概多少钱?...

    做一个小程序的大概预算是多少?做一个小程序大概多少钱?下面跟随小编一起来看看吧! 小程序开发需要多少钱,这个要看你做什么样的小程序, 你对小程序的功能.框架.定位.交互.UI的要求是什么? 这些都需要 ...

  3. 我的第一个安卓应用程序_我如何设计我的第一个应用程序

    我的第一个安卓应用程序 by Daniel Novykov 丹尼尔·诺维科夫(Daniel Novykov) 我如何设计我的第一个应用程序 (How I Designed My First App) ...

  4. 微软小娜打开应用程序_利用您现有的Microsoft投资进行应用程序白名单

    微软小娜打开应用程序 Application Whitelisting? What Is It? 应用白名单? 它是什么? I consider a firewall to be a Yes / No ...

  5. python烟花小程序_七夕用python给男朋友写的小程序,感动哭了。

    tkinter做的GUI图形界面 登陆界面,输入账号密码点击照片登陆. 登陆界面 密码输入错误则出现以下弹窗: 试图关闭界面,则出现以下弹窗: image.png 输入密码登陆以后开始答题,请忽视这个 ...

  6. 全云端万能小程序_万能门店全云端独立版微信小程序源码V4.0.10,全五端源码下载...

    独立版万能门店全端云小程序是一款可以一键生成全端小程序(微信小程序.百度小程序.支付宝小程序.抖音/头条小程序.QQ 小程序)的平台, 平台集成了分销商城.会员卡券.知识付费.商户平台.同城论坛等功能 ...

  7. python编写统计选票的程序_使用python编写微信公众号发稿统计程序

    近日为学校公众号统计发稿情况,需统计本年度各部门分别所发稿件标题.时间.作者等. 首先考虑查看公众号后台有无统计功能,看到的界面如下: 每页只显示7天的消息,且没有部门作者信息.再看另一界面: 只统计 ...

  8. flask开发桌面应用程序_使用Microsoft Authenticatio将多个破折号应用程序嵌入Flask中...

    flask开发桌面应用程序 Full disclosure: I am not an expert in developing web applications. I don't even consi ...

  9. 一个公众号可以绑定几个小程序_微信开放平台可以绑定几个小程序和公众号?...

    微信开放平台可以绑定几个小程序和公众号?How many small programs and official accounts can be bound to the WeChat open pl ...

最新文章

  1. TYVJ 2002 扑克牌 题解
  2. Windows PowerShell下基础操作
  3. 遮罩层中的相对定位与绝对定位(Ajax)
  4. 使用javamail发信过程中的一些问题及解决方法
  5. spriteatlas 白屏的问题_Discuz白屏问题解决思
  6. leetcode 实现 strStr()
  7. iOS多线程: pthread、NSThread
  8. 最速下降法/steepest descent,牛顿法/newton,共轭方向法/conjugate direction,共轭梯度法/conjugate gradient 及其他
  9. 4.27 前端开发日报
  10. NeurIPS自动驾驶比赛结束,新加坡松下研究院申省梅团队夺冠...
  11. 科普硬解,软解,gpu,dsp等等的关系
  12. java代码实现短信接受验证码
  13. js中for(const i in/of arr/obj)和vue中v-for指令的区别
  14. 3D立体书架切换效果(一)
  15. 团队大事件-团队历程-团队记录~
  16. IPv6的被请求节点的组播地址
  17. 广州传智播客PHP课程师资队伍让同行望尘莫及
  18. 成都计算机编程学费,成都高朋大道附近人工智能编程学习学费收费标准情况
  19. 计算机与化学参考文献,实验学生论文,关于计算机对化学实验课的辅助作用相关参考文献资料-免费论文范文...
  20. 西门子MES解决方案

热门文章

  1. css的三种引入方式 1211
  2. DataReader对象的基本使用 c#
  3. tar打包的时候忽略一些目录
  4. FutureV接口CallableV接口的使用
  5. win10 安装mysql-5.7.19-winx64
  6. MySQL5.6 部署MHA
  7. DP! | 不要怂!
  8. 基于Vue 和 webpack的项目实现
  9. JSON for java入门总结
  10. 中关村-DIY电子书之Nook2 Root 完全操作手册