Skip to content

Commit

Permalink
更新对应于FISCO-BCOS 3.0的第一、二章内容 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuo-young committed Dec 2, 2021
1 parent 22b8543 commit 4ab393a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
16 changes: 8 additions & 8 deletions docs/contract/call_external.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#[liquid::interface(name = auto)]
mod entry {
extern "solidity" {
extern "liquid" {
fn getInt(&self, key: String) -> i256;
...
}
Expand All @@ -70,9 +70,9 @@

在用于外部合约声明的模块中,必须有且只能有一个`extern`代码块,且该代码块中需要有至少一个合约方法的声明。`extern`代码块中,只能包含外部合约公开方法的签名,而不能包含其实现。每个外部合约公开方法的签名中,第一个参数必须为接收器,可以为`&self``&mut self`,用于表示该方法是否为只读方法。所声明的的只读性必须要和目标方法的只读性一致,否则可能会导致调用失败。外部合约公开方法的声明中无需包含构造函数的声明。

由于 Solidity 语言支持重载语法,即 Solidity 合约中可能会出现名称相同但参数不同的合约方法。为支持调用这些方法,Liquid 允许在`extern`代码块中声明名称相同但参数类型不同的外部合约公开方法。由于 Rust 语言本身不支持重载语法,因此 Liquid 将会使用特殊手段对这些重载方法提供支持,例如:
<!-- 由于 Solidity 语言支持重载语法,即 Solidity 合约中可能会出现名称相同但参数不同的合约方法。为支持调用这些方法,Liquid 允许在`extern`代码块中声明名称相同但参数类型不同的外部合约公开方法。由于 Rust 语言本身不支持重载语法,因此 Liquid 将会使用特殊手段对这些重载方法提供支持,例如: -->

```eval_rst
<!-- ```eval_rst
.. code-block:: rust
:linenos:
:emphasize-lines: 4-7
Expand All @@ -88,15 +88,15 @@
...
}
}
```
``` -->

```eval_rst
<!-- ```eval_rst
.. admonition:: 注意
只能在用于外部合约声明的模块中使用这种语法,合约代码中仍然无法使用重载语法。
```
``` -->

`extern`关键字后的字符串`"solidity"`用于表示所声明的外部合约使用[ABI 编解码](https://solidity.readthedocs.io/en/v0.7.1/abi-spec.html#formal-specification-of-the-encoding)方案对参数即返回值进行编解码,当前 Liquid 中仅支持调用这类外部合约。
<!-- `extern`关键字后的字符串`"solidity"`用于表示所声明的外部合约使用[ABI 编解码](https://solidity.readthedocs.io/en/v0.7.1/abi-spec.html#formal-specification-of-the-encoding)方案对参数即返回值进行编解码,当前 Liquid 中仅支持调用这类外部合约。 -->

外部合约声明的描述对象与合约模块相同,两者均是对智能合约行为的描述,只是外部合约声明中并不包含其行为的具体实现,因此两者在语义上属于同等地位。当需要声明外部合约时,较好的代码组织方式是将外部合约声明与合约模块放置于同级的命名空间中,而不是在合约模块内部放置外部合约声明:

Expand Down Expand Up @@ -165,7 +165,7 @@
#[liquid::interface(name = auto)]
mod kv_table_factory {
extern "solidity" {
extern "liquid" {
fn openTable(&self, name: String) -> KvTable;
...
}
Expand Down
2 changes: 1 addition & 1 deletion docs/contract/intrinsic.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn now(self) -> timestamp
<li>

```rust
pub fn get_Address(self) -> Address
pub fn get_address(self) -> Address
```

</li>
Expand Down
32 changes: 28 additions & 4 deletions docs/quickstart/prerequisite.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ rustup component add rustc-dev
```eval_rst
.. admonition:: 注意
由于Liquid使用了少量目前尚不稳定的Rust语言特性,因此在构建时需要依赖nightly版本的 ``rustc`` 。但是这些特性目前已经被广泛应用在Rust项目中,因此其可靠性值得信赖。随着Rust语言迭代演进,这些特性终将变为稳定特性。
由于Liquid使用了少量目前尚不稳定的Rust语言特性,因此在构建时需要依赖 ``nightly`` 版本的 ``rustc`` 。但是这些特性目前已经被广泛应用在Rust项目中,因此其可靠性值得信赖。随着Rust语言迭代演进,这些特性终将变为稳定特性。
```

查看当前rustup已安装的版本并切换为nightly:

```shell
rustup toolchain list
rustup default nightly-2021-06-23
```

```eval_rst
Expand Down Expand Up @@ -78,20 +85,37 @@ replace-with = 'ustc'
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
```

## 安装其他依赖

请确保配置 ``cmake`` 环境,Linux可以通过以下命令安装:

```shell
sudo apt install cmak
sudo yum install cmake3
```
Mac下可以直接通过 ``homebrew`` 安装:

```shell
brew install cmake
```

## 安装 cargo-liquid

`cargo-liquid` 是用于辅助开发 Liquid 智能合约的命令行工具,在终端中执行以下命令安装:

```shell
cargo install --git https://github.com/WeBankBlockchain/cargo-liquid --tag v1.0.0-rc1 --force
cargo install --git https://github.com/WeBankBlockchain/cargo-liquid --branch dev --force
```

```eval_rst
.. admonition:: 注意
若无法正常访问GitHub,则请执行 ``cargo install --git https://gitee.com/WeBankBlockchain/cargo-liquid --tag v1.0.0-rc1 --force`` 命令进行安装。
若无法正常访问GitHub,则请执行 ``cargo install --git https://gitee.com/WeBankBlockchain/cargo-liquid --branch dev --force`` 命令进行安装。
```


## 安装 Binaryen(可选)

Binaryen 项目中包含了一系列 Wasm 字节码分析及优化工具,其中如 `wasm-opt` 等工具会在 Liquid 智能合约的构建过程中使用。目前 Binaryen 仅提供了编译安装的方式,请参考其[官方文档](https://github.com/WebAssembly/binaryen#building),根据所使用的操作系统选择对应的编译安装方式。
Binaryen 项目中包含了一系列 Wasm 字节码分析及优化工具,其中如 `wasm-opt` 等工具会在 Liquid 智能合约的构建过程中使用。请参考其[官方文档](https://github.com/WebAssembly/binaryen#building)

除根据官方文档的编译安装方式外, Linux下可通过 ``apt install binaryen`` 下载安装(如使用Ubuntu,则系统版本不低于20.04, 其他操作系统可参照[此处](https://pkgs.org/download/binaryen)查看是否可直接通过包管理工具安装), Mac下可直接通过 ``brew install binaryen`` 下载安装binaryen。

0 comments on commit 4ab393a

Please sign in to comment.