Skip to content

Commit

Permalink
Add ethereum
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengxu committed Dec 6, 2017
1 parent 9795999 commit 3178fbe
Show file tree
Hide file tree
Showing 53 changed files with 75 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

blockchain.db

.DS_Store

_book/
node_modules/

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Blockchain Tutorial

:point_right: [目录](SUMMARY.md)

:point_right: 使用 [gitbook](https://liuchengxu.gitbooks.io/blockchain-tutorial/content/) 阅读
:point_right: 使用 [gitbook](https://liuchengxu.gitbooks.io/blockchain-tutorial/content/) 阅读(可能需要翻墙)

## TODO

Expand Down
63 changes: 35 additions & 28 deletions SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,57 @@
# Summary

----

## Bitcoin

* [引言](README.md)

----
### Part 2

* [基本原型](bitcoin/part-1/basic-prototype.md)
* [区块](bitcoin/part-1/block.md)
* [区块链](bitcoin/part-1/blockchain.md)

## Part 1
### Part 3

* [基本原型](part-1/basic-prototype.md)
* [区块](part-1/block.md)
* [区块链](part-1/blockchain.md)
* [工作量证明](bitcoin/part-2/proof-of-work.md)
* [哈希](bitcoin/part-2/hashing.md)
* [实现](bitcoin/part-2/implementation.md)

### Part 4

## Part 2
* [持久化和命令行接口](bitcoin/part-3/persistence-and-cli.md)
* [持久化](bitcoin/part-3/persistence.md)
* [命令行接口](bitcoin/part-3/cli.md)

* [工作量证明](part-2/proof-of-work.md)
* [哈希](part-2/hashing.md)
* [实现](part-2/implementation.md)
### Part 5

## Part 3
* [交易(1)](bitcoin/part-4/transactions-1.md)
* [交易输入](bitcoin/part-4/txin.md)
* [交易输出](bitcoin/part-4/txout.md)
* [UTXO](bitcoin/part-4/utxo.md)

* [持久化和命令行接口](part-3/persistence-and-cli.md)
* [持久化](part-3/persistence.md)
* [命令行接口](part-3/cli.md)
### Part 6

## Part 4
* [地址](bitcoin/part-5/address.md)
* [实现](bitcoin/part-5/implementation.md)

* [交易(1)](part-4/transactions-1.md)
* [交易输入](part-4/txin.md)
* [交易输出](part-4/txout.md)
* [UTXO](part-4/utxo.md)
### Part 7

## Part 5
* [交易(2)](bitcoin/part-6/transactions-2.md)
* [奖励](bitcoin/part-6/subsidy.md)
* [UTXO 集](bitcoin/part-6/utxo-set.md)
* [Merkle 树](bitcoin/part-6/merkle.md)

* [地址](part-5/address.md)
* [实现](part-5/implementation.md)
### Part 8

## Part 6
* [网络](bitcoin/part-7/network.md)

* [交易(2)](part-6/transactions-2.md)
* [奖励](part-6/subsidy.md)
* [UTXO 集](part-6/utxo-set.md)
* [Merkle 树](part-6/merkle.md)
## Ethereum

## Part 7
* [设计原理](ethereum/design-rationale.md)

* [网络](part-7/network.md)
## Others

----

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added bitcoin/part-4/img/blockchain-info-tx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions bitcoin/part-4/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BINARY := blockchain

build:
@echo "====> Go build"
@go build -o $(BINARY)

.PHONY: build
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions part-4/transactions-1.md → bitcoin/part-4/transactions-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ account(账户)会存储用户信息,里面包括了个人信息和余额

一笔交易由一些输入(input)和输出(output)组合而来:

![tx](./img/blockchain-info-tx.png)

点击 [这里](https://blockchain.info/zh-cn/tx/b6f6b339b546a13822192b06ccbdd817afea5311845f769702ae2912f7d94ab5) 在 blockchain.info 查看上图中的交易信息。

```go
type Transaction struct {
ID []byte
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions part-4/txout.md → bitcoin/part-4/txout.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
交易(1)
========

每一笔比特币交易都会创造输出,输出都会被区块链记录下来。给某个人发送比特币,实际上意味着创造新的 UTXO 并注册到那个人的地址,可以为他所用。

## 交易输出

让我们先从输出(output)开始:
Expand All @@ -12,6 +14,11 @@ type TXOutput struct {
}
```

输出主要包含两部分:

1. 一定量的比特币(`Value`)
2. 一个锁定脚本(`ScriptPubKey`),要花这笔钱,必须要解锁该脚本。

实际上,正是输出里面存储了“币”(注意,也就是上面的 `Value` 字段)。而这里的存储,指的是用一个数学难题对输出进行锁定,这个难题被存储在 `ScriptPubKey` 里面。在内部,比特币使用了一个叫做 *Script* 的脚本语言,用它来定义锁定和解锁输出的逻辑。虽然这个语言相当的原始(这是为了避免潜在的黑客攻击和滥用而有意为之),并不复杂,但是我们也并不会在这里讨论它的细节。你可以在[这里](https://en.bitcoin.it/wiki/Script) 找到详细解释。

>在比特币中,`value` 字段存储的是 *satoshi* 的数量,而不是 BTC 的数量。一个 *satoshi* 等于一百万分之一的 BTC(0.00000001 BTC),这也是比特币里面最小的货币单位(就像是 1 分的硬币)。
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions ethereum/design-rationale.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### 账户模型与 UTXO

比特币,及其很多的继任者,将用户的余额存储在一个基于 UTXO(unspent transaction output)的数据结构中,系统的整个状态由一个“未花费输出,unspent output” 的集合构成。那么 UTXO 到底是什么呢?简单来说,UTXO 就是人民币,就是 “coin”。有多少 UTXO,就有多少人民币。跟人民币的区别在于:

- “面值”,人民币的面值有 1 元,5 元,20 元,100 元等等是固定的,但是理论上,UTXO 的“面值”可以使任意正数。
- 新的人民币由政府的印钞机产生,新的 UTXO 由交易产生。

每个 UTXO 都有一个所有者和一个值,一笔交易会花费一些 UTXO,并创造出一些新的 UTXO,使用 UTXO 模型的交易在验证上有限制:

1. 引用的每个输入必须是有效的,而且还没有被花费
2. 对于每个输入,交易必须有一个跟输入所有者匹配的签名
3. 总输入必须大于或等于总输出

在 UTXO 系统中,一个用户的“余额”实际上并不直接存在,而是通过计算得来。一个用户有一个私钥,这个私钥生成一个有效的签名,这个签名能够解锁的所有币的总和就是“余额”。

以太坊摒弃了 UTXO 模型,采用了一种更简单的方式:账户模型。


https://github.com/ethereum/wiki/wiki/Design-Rationale/37be78fa7b726d36156c537b757c874b7aa5705
Binary file removed part-3/src/blockchain.db
Binary file not shown.
17 changes: 0 additions & 17 deletions part-4/src/Makefile

This file was deleted.

0 comments on commit 3178fbe

Please sign in to comment.