Skip to content

Commit

Permalink
Update translation based on latest version.
Browse files Browse the repository at this point in the history
Version up to 20180626, commit: 503eb8caa53c1f6ef00cec1fee099b2457c304f4
  • Loading branch information
riversyang committed Jun 27, 2018
1 parent ea558a1 commit 5ca74e0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion miscellaneous.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ AST 内的源代码映射使用以下表示法:
- ``this`` (类型为当前合约的变量):当前合约实例,可以准确地转换为 ``address``
- ``super``:当前合约的上一级继承关系的合约
- ``selfdestruct(address recipient)``:销毁当前合约,把余额发送到给定地址
- ``suicide(address recipient)``:一个不推荐使用的 ``selfdestruct`` 的同义词
- ``suicide(address recipient)``: ``selfdestruct`` 等价,但已不推荐使用
- ``<address>.balance`` (``uint256``): :ref:`address` 的余额,以 Wei 为单位
- ``<address>.send(uint256 amount) returns (bool)``:向 :ref:`address` 发送给定数量的 Wei,失败时返回 ``false``
- ``<address>.transfer(uint256 amount)``:向 :ref:`address` 发送给定数量的 Wei,失败时会把错误抛出(throw)
Expand Down
53 changes: 40 additions & 13 deletions units-and-global-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

由于闰秒造成的每年不都是 365 天、每天不都是 24 小时 `leap seconds <https://en.wikipedia.org/wiki/Leap_second>`_,所以如果你要使用这些单位计算日期和时间,请注意这个问题。因为闰秒是无法预测的,所以需要借助外部的预言机(oracle,是一种链外数据服务,译者注)来对一个确定的日期代码库进行时间矫正。

.. note::
``years`` 后缀已经不推荐使用了,因为从 0.5.0 版本开始将不再支持。

这些后缀不能直接用在变量后边。如果想用时间单位(例如 days)来将输入变量换算为时间,你可以用如下方式来完成:

::
Expand All @@ -40,22 +43,23 @@
特殊变量和函数
===============================

在全局命名空间中已经存在了(预设了)一些特殊的变量和函数,他们主要用来提供关于区块链的信息
在全局命名空间中已经存在了(预设了)一些特殊的变量和函数,他们主要用来提供关于区块链的信息或一些通用的工具函数

.. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin
.. index:: abi, block, coinbase, difficulty, encode, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin


区块和交易属性
--------------------------------

- ``block.blockhash(uint blockNumber) returns (bytes32)``: 给定区块的哈希—仅对最近的 256 个区块有效而不包括当前区块
- ``block.blockhash(uint blockNumber) returns (bytes32)``:指定区块的区块哈希——仅可用于最新的 256 个区块且不包括当前区块;而 blocks 从 0.4.22 版本开始已经不推荐使用,由 ``blockhash(uint blockNumber)`` 代替
- ``block.coinbase`` (``address``): 挖出当前区块的矿工地址
- ``block.difficulty`` (``uint``): 当前区块难度
- ``block.gaslimit`` (``uint``): 当前区块 gas 限额
- ``block.number`` (``uint``): 当前区块号
- ``block.timestamp`` (``uint``): 自 unix epoch 起始当前区块以秒计的时间戳
- ``gasleft() returns (uint256)``:剩余的 gas
- ``msg.data`` (``bytes``): 完整的 calldata
- ``msg.gas`` (``uint``): 剩余 gas
- ``msg.gas`` (``uint``): 剩余 gas - 自 0.4.21 版本开始已经不推荐使用,由 ``gesleft()`` 代替
- ``msg.sender`` (``address``): 消息发送者(当前调用)
- ``msg.sig`` (``bytes4``): calldata 的前 4 字节(也就是函数标识符)
- ``msg.value`` (``uint``): 随消息发送的 wei 的数量
Expand All @@ -67,7 +71,7 @@
  对于每一个**外部函数**调用,包括 ``msg.sender`` 和 ``msg.value`` 在内所有 ``msg`` 成员的值都会变化。这里包括对库函数的调用。

.. note::
不要依赖 ``block.timestamp``、 ``now`` 和 ``block.blockhash`` 产生随机数,除非你知道自己在做什么。
不要依赖 ``block.timestamp``、 ``now`` 和 ``blockhash`` 产生随机数,除非你知道自己在做什么。

  时间戳和区块哈希在一定程度上都可能受到挖矿矿工影响。例如,挖矿社区中的恶意矿工可以用某个给定的哈希来运行赌场合约的 payout 函数,而如果他们没收到钱,还可以用一个不同的哈希重新尝试。

Expand All @@ -76,17 +80,36 @@
.. note::
基于可扩展因素,区块哈希不是对所有区块都有效。你仅仅可以访问最近 256 个区块的哈希,其余的哈希均为零。

.. index:: abi, encoding, packed

ABI 编码函数
----------------------

- ``abi.encode(...) returns (bytes)``: :ref:`ABI <ABI>` - 对给定参数进行编码
- ``abi.encodePacked(...) returns (bytes)``:对给定参数执行 :ref:`紧打包编码 <abi_packed_mode>`
- ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: :ref:`ABI <ABI>` - 对给定参数进行编码,并以给定的函数选择器作为起始的 4 字节数据一起返回
- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``:等价于 ``abi.encodeWithSelector(bytes4(keccak256(signature), ...)``

.. note::
这些编码函数可以用来构造函数调用数据,而不用实际进行调用。此外,``keccak256(abi.encodePacked(a, b))`` 是更准确的方法来计算在未来版本不推荐使用的 ``keccak256(a, b)``。

更多详情请参考 :ref:`ABI <ABI>` 和 :ref:`紧打包编码 <abi_packed_mode>`。

.. index:: assert, revert, require

错误处理
--------------

``assert(bool condition)``:
  如果条件不满足就抛出—用于内部错误
  如果条件不满足,则使当前交易没有效果 — 用于检查内部错误
``require(bool condition)``:
如果条件不满足就抛掉—用于输入或者外部组件引起的错误。
如果条件不满足则撤销状态更改 - 用于检查由输入或者外部组件引起的错误。
``require(bool condition, string message)``:
如果条件不满足则撤销状态更改 - 用于检查由输入或者外部组件引起的错误,可以同时提供一个错误消息。
``revert()``:
终止运行并恢复状态变动。
终止运行并撤销状态更改。
``revert(string reason)``:
终止运行并撤销状态更改,可以同时提供一个解释性的字符串。

.. index:: keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography,

Expand Down Expand Up @@ -136,11 +159,11 @@
``<address>.send(uint256 amount) returns (bool)``:
  向 :ref:`address` 发送数量为 amount 的 Wei,失败时返回 ``false``,发送 2300 gas 的矿工费用,不可调节。
``<address>.call(...) returns (bool)``:
  发出底层 ``CALL``,失败时返回 ``false``,发送所有可用 gas,不可调节
  发出低级函数 ``CALL``,失败时返回 ``false``,发送所有可用 gas,可调节
``<address>.callcode(...) returns (bool)``:
  发出底层 ``CALLCODE``,失败时返回 ``false``,发送所有可用 gas,不可调节
  发出低级函数 ``CALLCODE``,失败时返回 ``false``,发送所有可用 gas,可调节
``<address>.delegatecall(...) returns (bool)``:
  发出底层 ``DELEGATECALL``,失败时返回 ``false``,发送所有可用 gas,不可调节
  发出低级函数 ``DELEGATECALL``,失败时返回 ``false``,发送所有可用 gas,可调节

更多信息,参考 :ref:`address` 部分:

Expand All @@ -149,7 +172,11 @@
用这种接收者取回钱的模式。

.. note::
    不鼓励使用 ``callcode``,并且将来它会被移除。
如果在通过低级函数 delegatecall 发起调用时需要访问存储中的变量,那么这两个合约的存储中的变量定义顺序需要一致,以便被调用的合约代码可以正确地通过变量名访问合约的存储变量。
这当然不是指像在高级的库函数调用时所传递的存储变量指针那样的情况。

.. note::
   不鼓励使用 ``callcode``,并且将来它会被移除。

.. index:: this, selfdestruct

Expand All @@ -163,6 +190,6 @@
销毁合约,并把余额发送到指定 :ref:`address`。

``suicide(address recipient)``:
等价于 selfdestruct。
selfdestruct 等价,但已不推荐使用

此外,当前合约内的所有函数都可以被直接调用,包括当前函数。

0 comments on commit 5ca74e0

Please sign in to comment.