Skip to content

Commit

Permalink
f(x) analogy
Browse files Browse the repository at this point in the history
  • Loading branch information
xhliu committed Feb 27, 2021
1 parent cdfb820 commit 60321f5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
Binary file added docs/_static/images/fx.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ It quickly becomes intractable when the contract size and complexity grow.

sCrypt is designed to facilitate writing smart contract running on chain.

* It is easy to learn. Syntactically, sCrypt is similar to Solidity, making it easier to be adopted by existing smart contract developers. However, the resemblance is only superficial, since sCrypt is compiled into Bitcoin Script by the underlying compiler, instead of EVM bytecode.
* It is easy to learn. Syntactically, sCrypt is similar to Javascript and Solidity, making it easier to be adopted by existing web and smart contract developers.
* It is statically typed. Type checking can help detect many errors at compile time.


Expand Down
16 changes: 12 additions & 4 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,24 @@ If the condition is not met, the contract will abort execution and fail. Otherwi

Public Function
=================
Each contract has at least one public function. It is denoted with the ``public`` keyword and does not return any value. The function body corresponds to locking script (commonly referred to as ``scriptPubKey``) and its arguments unlocking script (aka, ``scriptSig``).
Each contract has at least one public function. It is denoted with the ``public`` keyword and does not return any value. The function body corresponds to locking script and its arguments unlocking script.
It is visible outside the contract and acts as the entry point into the contract (like ``main`` in ``C`` and ``Java``).

A public function must end with a ``require()`` call. ``require()`` can also appear in other parts of a public function. A contract can only be fulfilled and succeed when its called public function runs to completion without violating any conditions in ``require()``.
In the above example, only ``scriptSig`` (i.e., ``y``) equal to ``this.x`` can fulfill the contract.
In the above example, only ``unlockingScript`` (i.e., ``y``) equal to ``this.x`` can fulfill the contract.

A public function can be regarded as a mathematical boolean function. ``f`` is the function body and ``x`` the function arguments.
A contract call succeeds if and only if ``f(x)`` returns true.

.. image:: _static/images/fx.png
:width: 120px
:alt: sCrypt logo
:align: center

Multiple Public Functions
-------------------------
A contract can have multiple public functions, representing different ways to fulfill a contract. Only one of the public functions can be called at a time. In this case, the last operator of ``scriptSig`` has to be the index of the public function called, starting from ``0``.
For example, if public function ``larger`` is called, ``scriptSig`` of ``y 2`` can fulfill the contract below, in which ``2`` is the public function index.
A contract can have multiple public functions, representing different ways to fulfill a contract. Only one of the public functions can be called at a time. In this case, the last operator of ``unlockingScript`` has to be the index of the public function called, starting from ``0``.
For example, if public function ``larger`` is called, ``unlockingScript`` of ``y 2`` can fulfill the contract below, in which ``2`` is the public function index.

.. code-block:: solidity
Expand Down
19 changes: 9 additions & 10 deletions docs/locale/zh_CN/LC_MESSAGES/intro.po
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,12 @@ msgstr "公有函数"
msgid ""
"Each contract has at least one public function. It is denoted with the "
"``public`` keyword and does not return any value. The function body "
"corresponds to locking script (commonly referred to as ``scriptPubKey``) and"
" its arguments unlocking script (aka, ``scriptSig``). It is visible outside "
"corresponds to locking script and"
" its arguments unlocking script. It is visible outside "
"the contract and acts as the entry point into the contract (like ``main`` in"
" ``C`` and ``Java``)."
msgstr ""
"每个合约至少要有一个公有函数。用 ``public`` 关键字修饰,并且不返回任何值。函数体对应锁定脚本(通常被称为 "
"``scriptPubKey``),函数参数为解锁脚本(也被称为 ``scriptSig``)。公有函数在合约外部是可见的,是合约的入口(就像 "
"每个合约至少要有一个公有函数。用 ``public`` 关键字修饰,并且不返回任何值。函数体对应锁定脚本,函数参数为解锁脚本。公有函数在合约外部是可见的,是合约的入口(就像 "
"``C`` 和 ``Java`` 的 ``main`` 函数)。"

# 3d91fd25596646abb5d0047e50ac813e
Expand All @@ -109,12 +108,12 @@ msgid ""
" appear in other parts of a public function. A contract can only be "
"fulfilled and succeed when its called public function runs to completion "
"without violating any conditions in ``require()``. In the above example, "
"only ``scriptSig`` (i.e., ``y``) equal to ``this.x`` can fulfill the "
"only ``unlockingScript`` (i.e., ``y``) equal to ``this.x`` can fulfill the "
"contract."
msgstr ""
"公有函数的最后一个语句必须是 ``require()`` 。 ``require()`` "
"也可以出现在公有函数的其他地方。只有在被调用的公有函数执行完毕,并且所有 ``require()`` "
"中的条件全部被满足时,合约才算执行成功。在上面的例子中,只有 ``scriptSig`` (即 ``y`` )等于 ``this.x`` "
"中的条件全部被满足时,合约才算执行成功。在上面的例子中,只有 ``unlockingScript`` (即 ``y`` )等于 ``this.x`` "
"时合约才能执行成功。"

# 2d7fe4f73f39469da0cc6b132acb4d29
Expand All @@ -127,11 +126,11 @@ msgstr "多个公有函数"
msgid ""
"A contract can have multiple public functions, representing different ways "
"to fulfill a contract. Only one of the public functions can be called at a "
"time. In this case, the last operator of ``scriptSig`` has to be the index "
"time. In this case, the last operator of ``unlockingScript`` has to be the index "
"of the public function called, starting from ``0``. For example, if public "
"function ``larger`` is called, ``scriptSig`` of ``y 2`` can fulfill the "
"function ``larger`` is called, ``unlockingScript`` of ``y 2`` can fulfill the "
"contract below, in which ``2`` is the public function index."
msgstr ""
"一个合约可以有多个公有函数,表示有多种方式可以满足合约。但一次只能调用其中一个。在这种情况下, ``scriptSig`` "
"一个合约可以有多个公有函数,表示有多种方式可以满足合约。但一次只能调用其中一个。在这种情况下, ``unlockingScript`` "
"的最后一个操作符必须是被调用的公有函数的索引,公有函数索引按照定义顺序从 ``0`` 开始。举例如下,要调用公有函数 ``larger`` , "
"``scriptSig`` 要用 ``y 2`` ,其中 ``2`` 是被调用的公有函数的索引。"
"``unlockingScript`` 要用 ``y 2`` ,其中 ``2`` 是被调用的公有函数的索引。"

0 comments on commit 60321f5

Please sign in to comment.