https://github.com/webankblockchain/liquid
Liquid 由微众银行区块链团队开发并完全开源,是一种嵌入式领域特定语言( embedded Domain Specific Language,eDSL),能够用来编写运行于区块链底层平台FISCO BCOS的智能合约。
https://github.com/webankblockchain/liquid
contract rust
Last synced: 11 months ago
JSON representation
Liquid 由微众银行区块链团队开发并完全开源,是一种嵌入式领域特定语言( embedded Domain Specific Language,eDSL),能够用来编写运行于区块链底层平台FISCO BCOS的智能合约。
- Host: GitHub
- URL: https://github.com/webankblockchain/liquid
- Owner: WeBankBlockchain
- License: apache-2.0
- Created: 2021-03-17T13:01:09.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-05-10T08:42:39.000Z (about 3 years ago)
- Last Synced: 2024-04-24T03:16:28.749Z (about 2 years ago)
- Topics: contract, rust
- Language: Rust
- Homepage: https://liquid-doc.readthedocs.io/zh_CN/latest/
- Size: 799 KB
- Stars: 44
- Watchers: 4
- Forks: 15
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Liquid - Makes Smart Contract Smarter
[](https://github.com/WeBankBlockchain/liquid/blob/main/LICENSE)
[](https://github.com/WeBankBlockchain/liquid)
[](https://github.com/WebankBlockchain/liquid/releases/latest)
[](https://www.rust-lang.org/)
Liquid 由微众银行区块链团队开发并完全开源,是一种[嵌入式领域特定语言](http://wiki.haskell.org/Embedded_domain_specific_language)( embedded Domain Specific Language,eDSL),能够用来编写运行于区块链底层平台[FISCO BCOS](https://github.com/FISCO-BCOS/FISCO-BCOS)的智能合约。
## 关键特性
### 安全(Security)
- 支持在智能合约内部便捷地编写单元测试用例,可通过内嵌的区块链模拟环境直接在本地执行;
- 算数溢出及内存越界安全检查;
- 能够结合模糊测试等工具进行深度测试;
- 未来将进一步集成形式化验证及数据隐私保护技术。
### 性能(Performance)
- 配合 LLVM 优化器,支持将智能合约代码编译为可移植、体积小、加载快 Wasm 格式字节码;
- 对 Wasm 执行引擎进行了深度优化,并支持交易并行化等技术;
- 结合 Tree-Shaking 等技术,进一步压缩智能合约体积。
### 体验(Experience)
- 支持使用大部分现代语言特性(如移动语义及自动类型推导等);
- 提供专有开发工具及编辑器插件辅助开发;
- 丰富的标准库及第三方组件。
### 可定制(Customization)
- 能够根据业务需求对编程模型、语言文法的进行深度定制。
- 未来还将进一步探索如何与隐私保护、跨链协同等功能相结合。
## 合约示例
使用 Liquid 编写的 HelloWorld 合约如下所示:
```rust
#![cfg_attr(not(feature = "std"), no_std)]
use liquid::storage;
use liquid_lang as liquid;
#[liquid::contract]
mod hello_world {
use super::*;
#[liquid(storage)]
struct HelloWorld {
name: storage::Value,
}
#[liquid(methods)]
impl HelloWorld {
pub fn new(&mut self) {
self.name.initialize(String::from("Alice"));
}
pub fn get(&self) -> String {
self.name.clone()
}
pub fn set(&mut self, name: String) {
self.name.set(name)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn get_works() {
let contract = HelloWorld::new();
assert_eq!(contract.get(), "Alice");
}
#[test]
fn set_works() {
let mut contract = HelloWorld::new();
let new_name = String::from("Bob");
contract.set(new_name.clone());
assert_eq!(contract.get(), "Bob");
}
}
}
```
## 技术文档
阅读[Liquid 在线技术文档](https://liquid-doc.readthedocs.io/zh_CN/latest/index.html),详细了解如何使用 Liquid。
- [快速开始](https://liquid-doc.readthedocs.io/zh_CN/latest/docs/quickstart/prerequisite.html)
- [基础语法](https://liquid-doc.readthedocs.io/zh_CN/latest/docs/contract/contract_mod.html)
- [开发与测试](https://liquid-doc.readthedocs.io/zh_CN/latest/docs/dev_testing/development.html)
- [参考](https://liquid-doc.readthedocs.io/zh_CN/latest/docs/advance/metaprogramming.html)
## 架构设计

## 社区
- [智能合约编译技术专项兴趣小组](https://mp.weixin.qq.com/s/NfBZtPWxXdnP0XLLGrQKow)
## 最小支持 Rust 版本(Minimum Supported Rust Version,MSRV)
Rust Nightly 1.52 或更高。
## License
Liquid 的开源协议为 Apache License 2.0,详情请参考[LICENSE](./LICENSE)。