-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
5,716 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,100 @@ | ||
# solidity-zh | ||
# Solidity 官方文档中文版 | ||
|
||
欢迎各路区块链及以太坊领域的专家和爱好者参与这一翻译项目,我们会为每位翻译和校对人员署名。 | ||
|
||
## 特别介绍 | ||
|
||
[Solidity 官方文档](TOC.md)前一版已经翻译完成90%,内容需要更新。 | ||
|
||
前一版贡献者名单: | ||
|
||
* [少平](http://ethfans.org/shaoping) | ||
* [abao](http://ethfans.org/abao) | ||
* 志伟 | ||
* jinfengbc | ||
* 大青蛙 | ||
* [zhangyaning](http://ethfans.org/rubyu2) | ||
|
||
## 一起来参与 | ||
|
||
如果想做出贡献(翻译或者校对)的话,请加QQ群:195819423,谢谢! | ||
|
||
PS: 想探讨Solidity技术的可以加"Solidity技术交流群":549293015 | ||
|
||
## 内容来源 | ||
|
||
英文官方网站: | ||
<https://solidity.readthedocs.io/> | ||
|
||
官方GitHub仓库: | ||
<https://github.com/ethereum/solidity> | ||
|
||
中文版 GitHub 仓库: | ||
<https://github.com/jikexueyuanwiki/tensorflow-zh> | ||
|
||
|
||
## 参与步骤 | ||
|
||
* fork主仓库(<https://github.com/jikexueyuanwiki/tensorflow-zh>) | ||
* 按照章节认领翻译(每次申请一个章节)或者校对(可申请多个章节)在下面这个`README.md`里找还没有被人申请的章节,写上(@你的github号),给主仓库的`master`分支提pull request; | ||
* 提的 pull request 被确认,合并到主仓库后,代表你申请的章节*认领*完成,开始翻译或校对; | ||
* 翻译或校对的文件为README.md或者TOC.md中对应的md文件,请不要翻译/校对单独文件夹中的index.md | ||
* 翻译过程请参照 *翻译协作规范* (见下一节),完成翻译后提交 pull request 给主仓库的`master`分支; | ||
* 完成校对后同样提交 pull request 给主仓库的`master`分支; | ||
* 全部翻译/校对完成后,我们会生成PDF/ePub文档,放在极客学院Wiki平台发布,并为所有参与者署名! | ||
|
||
## 翻译协作规范 | ||
|
||
为了让大家协作顺畅,需要每一个人遵循如下协作规范~ | ||
|
||
- 如果对Markdown和GitHub不了解,请先阅读[如何使用Markdown](markdown.md)以及[如何使用GitHub](learn-github.md) | ||
- 使用Markdown进行翻译,文件名必须使用英文 | ||
- 翻译后的文档请放到SOURCE文件夹下的对应章节中,然后pull request即可 | ||
- 如遇到文中的图片,请统一放在SOURCE/images目录下 | ||
- 原文中的HTML标签及代码请不要修改、翻译 | ||
- 有其他任何问题都欢迎发issue,我们看到了会尽快回复 | ||
- 翻译人员需将对应的原文地址和翻译人姓名添加到译文末尾,审校人员需要将自己的名字添加到译文末尾,具体格式请参见样例: | ||
|
||
> 原文:[Color Palettes](http://www.google.com/design/spec/resources/color-palettes.html) 翻译:[iceskysl](https://github.com/iceskysl) 校对:[PoppinLp](https://github.com/poppinlp) | ||
## 校对规范 | ||
|
||
- 认领校对时请提供相关方面的专业背景说明,保证校对质量 | ||
- 文章通顺,适合人类阅读与理解,别让人以为是机翻 | ||
- 确保图片都能正常显示,且其相对地址都是SOURCE/images,图片存放正确 | ||
- 专有名词符合术语表中的翻译要求,拿不准的新词汇可以使用中文翻译后加括号内英文的形式 | ||
- 校对人员需有一定专业背景,保证译文无专业知识方面错误 | ||
- 请查看翻译人员是否将原文链接和翻译链接放到译文最下方,审校人员需要将自己的名字添加到译文末尾,具体格式请参见样例: | ||
|
||
> 原文:[Color Palettes](http://www.google.com/design/spec/resources/color-palettes.html) 翻译:[iceskysl](https://github.com/iceskysl) 校对:[PoppinLp](https://github.com/poppinlp) | ||
- 有任何问题请提Issues或到协同翻译群讨论,校对后提PR等待Merge,管理员通过后会在目录后面打√标识完成 | ||
|
||
## 参与者(按认领章节排序) | ||
|
||
### 翻译 & 校对 | ||
|
||
- [智能合约介绍](introduction-smart-contracts.md) 翻译:(待认领)校对: (待认领) | ||
- [安装Solidity](installing-solidity.md) 翻译:(待认领)校对: (待认领) | ||
- [Solidity 编程实例](solidity-example.md) 翻译:(待认领)校对: (待认领) | ||
- [深入理解 Solidity](solidity-depth.md) 翻译:(待认领)校对: (待认领) | ||
- [源文件的布局](layout-state-variables-storage.md) 翻译:(待认领)校对: (待认领) | ||
- [合约的结构](structure-contract.md) 翻译:(待认领)校对: (待认领) | ||
- [类型](types.md) 翻译:(待认领)校对: (待认领) | ||
- [单位和全局可用变量](units-globally-available-variables.md) 翻译:(待认领)校对: (待认领) | ||
- [表达式和控制结构](expressions-control-structures.md) | ||
翻译:(待认领)校对: (待认领) | ||
- [合约](contracts.md) 翻译:(待认领)校对: (待认领) | ||
- [杂项](miscellaneous.md) 翻译:(待认领)校对: (待认领) | ||
- [Security Considerations]()翻译:(待认领)校对: (待认领) | ||
- [编程规范](style-guide.md) 翻译:(待认领)校对: (待认领) | ||
- [通用模式](common-patterns.md) 翻译:(待认领)校对: (待认领) | ||
- [常见问题](frequently-asked-questions.md) 翻译:(待认领)校对: (待认领) | ||
|
||
## 进度记录 | ||
|
||
- 2016-8-26, 极客学院Wiki启动协同翻译,创建 GitHub 仓库,制定协同规范 | ||
|
||
## 感谢支持 | ||
|
||
## 离线版本 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
- [简介](introduction.md) | ||
- [智能合约介绍](introduction-smart-contracts.md) | ||
- [安装Solidity](installing-solidity.md) | ||
- [Solidity 编程实例](solidity-example.md) | ||
- [深入理解 Solidity](solidity-depth.md) | ||
- [源文件的布局](layout-state-variables-storage.md) | ||
- [合约的结构](structure-contract.md) | ||
- [类型](types.md) | ||
- [单位和全局可用变量](units-globally-available-variables.md) | ||
- [表达式和控制结构](expressions-control-structures.md) | ||
- [合约](contracts.md) | ||
- [杂项](miscellaneous.md) | ||
- [编程规范](style-guide.md) | ||
- [通用模式](common-patterns.md) | ||
- [常见问题](frequently-asked-questions.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
# 通用模式 | ||
|
||
## 访问限制 | ||
|
||
访问限制是合约的一种通用模式,但你不能限制任何人获取你的合约和交易的状态。当然,你可以通过加密来增加读取难度,但是如果你的合约需要读取该数据(指加密的数据),其他人也可以读取。 | ||
|
||
你可以通过将合约状态设置为私有来限制其他合约来读取你的合约状态。 | ||
|
||
此外,你可以限制其他人修改你的合约状态或者调用你的合约函数,这也是本章将要讨论的。 | ||
|
||
函数修饰符的使用可以让这些限制(访问限制)具有较好的可读性。 | ||
|
||
``` | ||
contract AccessRestriction { | ||
// These will be assigned at the construction | ||
// phase, where `msg.sender` is the account | ||
// creating this contract. | ||
//以下变量将在构造函数中赋值 | ||
//msg.sender是你的账户 | ||
//创建本合约 | ||
address public owner = msg.sender; | ||
uint public creationTime = now; | ||
// Modifiers can be used to change | ||
// the body of a function. | ||
// If this modifier is used, it will | ||
// prepend a check that only passes | ||
// if the function is called from | ||
// a certain address. | ||
``` | ||
|
||
//修饰符可以用来修饰函数体,如果使用该修饰符,当该函数被其他地址调用时将会先检查是否允许调用(译注:就是说外部要调用本合约有修饰符的函数时会检查是否允许调用,比如该函数是私有的则外部不能调用。) | ||
|
||
``` | ||
modifier onlyBy(address _account) | ||
{ | ||
if (msg.sender != _account) | ||
throw; | ||
// Do not forget the "_"! It will | ||
// be replaced by the actual function | ||
// body when the modifier is invoked. | ||
//account变量不要忘了“_” | ||
_ | ||
} | ||
/// Make `_newOwner` the new owner of this | ||
/// contract. | ||
//修改当前合约的宿主 | ||
function changeOwner(address _newOwner) | ||
onlyBy(owner) | ||
{ | ||
owner = _newOwner; | ||
} | ||
modifier onlyAfter(uint _time) { | ||
if (now < _time) throw; | ||
_ | ||
} | ||
/// Erase ownership information. | ||
/// May only be called 6 weeks after | ||
/// the contract has been created. | ||
//清除宿主信息。只能在合约创建6周后调用 | ||
function disown() | ||
onlyBy(owner) | ||
onlyAfter(creationTime + 6 weeks) | ||
{ | ||
delete owner; | ||
} | ||
// This modifier requires a certain | ||
// fee being associated with a function call. | ||
// If the caller sent too much, he or she is | ||
// refunded, but only after the function body. | ||
// This is dangerous, because if the function | ||
// uses `return` explicitly, this will not be | ||
// done! | ||
//该修饰符和函数调用关联时需要消耗一部分费用。调用者发送的多余费用会在函数执行完成后返还,但这个是相当危险的,因为如果函数 | ||
modifier costs(uint _amount) { | ||
if (msg.value < _amount) | ||
throw; | ||
_ | ||
if (msg.value > _amount) | ||
msg.sender.send(_amount - msg.value); | ||
} | ||
function forceOwnerChange(address _newOwner) | ||
costs(200 ether) | ||
{ | ||
owner = _newOwner; | ||
// just some example condition | ||
if (uint(owner) & 0 == 1) | ||
// in this case, overpaid fees will not | ||
// be refunded | ||
return; | ||
// otherwise, refund overpaid fees | ||
}} | ||
``` | ||
|
||
A more specialised way in which access to function calls can be restricted will be discussed in the next example. | ||
|
||
State Machine | ||
Contracts often act as a state machine, which means that they have certain stages in which they behave differently or in which different functions can be called. A function call often ends a stage and transitions the contract into the next stage (especially if the contract models interaction). It is also common that some stages are automatically reached at a certain point in time. | ||
|
||
An example for this is a blind auction contract which starts in the stage “accepting blinded bids”, then transitions to “revealing bids” which is ended by “determine auction autcome”. | ||
|
||
Function modifiers can be used in this situation to model the states and guard against incorrect usage of the contract. | ||
|
||
Example | ||
|
||
In the following example, the modifier atStage ensures that the function can only be called at a certain stage. | ||
|
||
Automatic timed transitions are handled by the modifier timeTransitions, which should be used for all functions. | ||
|
||
Note | ||
|
||
Modifier Order Matters. If atStage is combined with timedTransitions, make sure that you mention it after the latter, so that the new stage is taken into account. | ||
|
||
Finally, the modifier transitionNext can be used to automatically go to the next stage when the function finishes. | ||
|
||
Note | ||
|
||
Modifier May be Skipped. Since modifiers are applied by simply replacing code and not by using a function call, the code in the transitionNext modifier can be skipped if the function itself uses return. If you want to do that, make sure to call nextStage manually from those functions. | ||
|
||
``` | ||
contract StateMachine { | ||
enum Stages { | ||
AcceptingBlindedBids, | ||
RevealBids, | ||
AnotherStage, | ||
AreWeDoneYet, | ||
Finished | ||
} | ||
// This is the current stage. | ||
Stages public stage = Stages.AcceptingBlindedBids; | ||
uint public creationTime = now; | ||
modifier atStage(Stages _stage) { | ||
if (stage != _stage) throw; | ||
_ | ||
} | ||
function nextStage() internal { | ||
stage = Stages(uint(stage) + 1); | ||
} | ||
// Perform timed transitions. Be sure to mention | ||
// this modifier first, otherwise the guards | ||
// will not take the new stage into account. | ||
modifier timedTransitions() { | ||
if (stage == Stages.AcceptingBlindedBids && | ||
now >= creationTime + 10 days) | ||
nextStage(); | ||
if (stage == Stages.RevealBids && | ||
now >= creationTime + 12 days) | ||
nextStage(); | ||
// The other stages transition by transaction | ||
} | ||
// Order of the modifiers matters here! | ||
function bid() | ||
timedTransitions | ||
atStage(Stages.AcceptingBlindedBids) | ||
{ | ||
// We will not implement that here | ||
} | ||
function reveal() | ||
timedTransitions | ||
atStage(Stages.RevealBids) | ||
{ | ||
} | ||
// This modifier goes to the next stage | ||
// after the function is done. | ||
// If you use `return` in the function, | ||
// `nextStage` will not be called | ||
// automatically. | ||
modifier transitionNext() | ||
{ | ||
_ | ||
nextStage(); | ||
} | ||
function g() | ||
timedTransitions | ||
atStage(Stages.AnotherStage) | ||
transitionNext | ||
{ | ||
// If you want to use `return` here, | ||
// you have to call `nextStage()` manually. | ||
} | ||
function h() | ||
timedTransitions | ||
atStage(Stages.AreWeDoneYet) | ||
transitionNext | ||
{ | ||
} | ||
function i() | ||
timedTransitions | ||
atStage(Stages.Finished) | ||
{ | ||
}} | ||
``` | ||
|
||
Next Previous |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "Solidity 官方文档中文版", | ||
"introduction": "Solidity是一种语法类似JavaScript的高级语言。它被设计成以编译的方式生成以太坊虚拟机代码。在后续内容中你将会发现,使用它很容易创建用于投票、众筹、封闭拍卖、多重签名钱包等等的合约。" | ||
} |
Oops, something went wrong.