Skip to content

Commit

Permalink
Rename "external" to "public"
Browse files Browse the repository at this point in the history
  • Loading branch information
xhliu committed Jul 3, 2019
1 parent 1e0bd26 commit 03f967b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/ackermann.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ nCrypt has devised to way to cauculate the value of the Ackermann function using
}
// y = 5
function unlock(int y) external {
public function unlock(int y) {
require(y == ackermann(a, b));
}
}
Expand Down
22 changes: 11 additions & 11 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A contract consists of two parts: locking script and unlocking script.
x = 10;
}
function equal(int y) external {
public function equal(int y) {
require(y == x);
}
}
Expand All @@ -28,18 +28,18 @@ require
The ``require`` function specifies terms/conditions of the contract. It consumes a boolean condition and will abort the execution of a contract if the condition is not met.
Otherwise, it will continue the execution.

External Function
Public Function
=================
Each contract has at least one external function. It is denoted with the ``external`` keyword and does not return any value. The function body corresponds to unlocking script (commonly referred to as ``scriptPubKey``) and its arguments locking script (aka, ``scriptSig``).
External function can be regarded as the entry point into the contract from the outside (like ``main`` in ``C`` and ``Java``). A contract can only be fulfilled and successfully complete when its external function succeeds.
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 unlocking script (commonly referred to as ``scriptPubKey``) and its arguments locking script (aka, ``scriptSig``).
It is visible outside the contract, similar to ``public`` function in Solidity. It acts as the entry point into the contract from the outside (like ``main`` in ``C`` and ``Java``). A contract can only be fulfilled and successfully complete when its public function succeeds.

An external function must end with a ``require`` call. ``require`` can also appear in other parts of an external function. An external function only succeeds if it runs to completion without violating any condition in ``require``.
A public function must end with a ``require`` call. ``require`` can also appear in other parts of a public function. A public function only succeeds if it runs to completion without violating any condition in ``require``.
In the above example, ``scriptSig`` of ``10`` can fulfill the contract.

Multiple External Functions
Multiple Public Functions
---------------------------
A contract can have multiple external functions, representing different ways to fulfill a contract. Only one of the external functions can be chosen at a time. In this case, the last operator of ``scriptSig`` has to be the index of the external function chosen, starting from 1.
For example, if ``larger`` external function path is chosen, the ``scriptSig`` of ``10 3`` can fulfill the contract below, in which ``3`` is the external function index.
A contract can have multiple public functions, representing different ways to fulfill a contract. Only one of the public functions can be chosen at a time. In this case, the last operator of ``scriptSig`` has to be the index of the public function chosen, starting from 1.
For example, if ``larger`` public function path is chosen, the ``scriptSig`` of ``10 3`` can fulfill the contract below, in which ``3`` is the public function index.

.. code-block:: solidity
Expand All @@ -50,15 +50,15 @@ For example, if ``larger`` external function path is chosen, the ``scriptSig`` o
x = 10;
}
function equal(int y) external {
public function equal(int y) {
require(y == x);
}
function smaller(int y) external {
public function smaller(int y) {
require(y < x);
}
function larger(int y) external {
public function larger(int y) {
require(y > x);
}
}
2 changes: 1 addition & 1 deletion docs/p2pkh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Pay to Public Key Hash
pubKeyHash = Ripemd160(0x16475707a0c893698c82eb8d177a8164c0aa1e72);
}
function unlock(Sig sig, PubKey pubKey) external {
public function unlock(Sig sig, PubKey pubKey) {
require(hash160(pubKey) == pubKeyHash);
require(checkSig(sig, pubKey));
}
Expand Down
2 changes: 1 addition & 1 deletion docs/rpuzzle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ One crucial in R-Puzzle is to extract ``r`` from `DER`_ encoded signature. The f
}
// r = 00948c67a95f856ae875a48a2d104df9d232189897a811178a715617d4b090a7e9
function unlock(bytes r) external {
public function unlock(bytes r) {
require(r == getSigR(s));
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/syntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Formal Specification
.. math::
\begin{align*}
contract &::= \mathrm{contract}\ \mathrm{ID}\ \{\ [var]^*\ constructor\ [function]^*\ [external]^+\ \}\\
contract &::= \mathrm{contract}\ \mathrm{ID}\ \{\ [var]^*\ constructor\ [function]^*\ [public]^+\ \}\\
var &::= formal;\\
formal &::= \mathrm{TYPE}\ \mathrm{ID}\\
function &::= \mathrm{function}\ \mathrm{ID}(formal[,\ formal]^*)\ \mathrm{returns}\ (\mathrm{TYPE})\ \{\ [stmt]^*\ \mathrm{return}\ expr;\ \}\\
constructor &::= \mathrm{constructor}([formal[,\ formal]^*])\ \{\ [stmt]^*\ \}\\
external &::= \mathrm{function}\ \mathrm{ID}(formal[,\ formal]^*)\ \mathrm{external}\ \{\ [stmt]^*\ \mathrm{require}(expr);\}\\
public &::= \mathrm{public}\ \mathrm{function}\ \mathrm{ID}(formal[,\ formal]^*)\ \{\ [stmt]^*\ \mathrm{require}(expr);\}\\
stmt &::= \mathrm{TYPE}\ \mathrm{ID} = expr;\\
&\ \ \ |\ \ \mathrm{ID} = expr;\\
&\ \ \ |\ \ \mathrm{require}(expr);\\
Expand Down

0 comments on commit 03f967b

Please sign in to comment.