Sway编程语言-更新中(The Sway Programming Language-Updatin
  • Sway编程语言(The Sway Programming Language)
  • 1. 导言(Introduction)
    • 1.1 安装(Installation)
    • 1.2 Sway快速入门 (Sway Quickstart)
    • 1.3 Fuel工具链 (The Fuel Toolchain)
    • 1.4 一个Forc项目 (A Forc Project)
    • 1.5 标准库 (Standard Library)
  • 2. 示例(Example)
    • 2.1计数器(Counter)
    • 2.2子货币(Subcurrency)
    • 2.3 FizzBuzz
    • 2.4 钱包智能合约(Wallet Smart Contract)
  • 3.Sway编程类型(Sway Program Types)
    • 3.1 合约(Contracts)
    • 3.2 库 (Libraries)
    • 3.3 脚本(Scripts)
    • 3.4 谓词 (Predicates)
  • 4. Sway语言基础 (Sway Language basics)
    • 4.1 变量 (Variables)
    • 4.2 内置类型(Built-in Types)
    • 4.3 常用库类型(Commonly Used Library Types)
    • 4.4 区块链类 (Blockchain Types)
    • 4.5 函数 (Functions)
    • 4.6 结构、元祖和穷举 (Structs, Tuples, and Enums)
    • 4.7 方法和关联函数 (Methods and Associated Functions)
    • 4.8 注释和日志 (Comments and Logging)
    • 4.9 控制流 (Control Flow)
  • 5. 用Sway部署区块链 (Blockchain Development with Sway)
    • 5.1 哈希和加密学 (Hashing and Cryptography)
    • 5.2 合约存储(Contract Storage)
    • 5.3 函数纯度 (Function Purity)
    • 5.4 标识符(Identifiers)
    • 5.5 原生资产(Native Assets)
    • 5.6 访问控制 (Access Control)
    • 5.7 调用合约(Calling Contracts)
  • 6. 高级概念 (Advanced Concepts)
    • 6.1 高级类型 (Advanced Types)
    • 6.2 通用类型 (Generic Types)
    • 6.3 特征 (Traits)
    • 6.4 集 (Assembly)
  • 7. 一般集聚 (Common Collections)
    • 7.1 堆上的向量(Vectors on the Heap)
    • 7.2 存储向量 (Storage Vectors)
    • 7.3 存储映射 (Storage Maps)
  • 8.测试(Testing)
    • 8.1 单元测试(Unit Testing)
    • 8.2 用Rust来测试 (Testing with Rust)
  • 9.应用前端开发 (Application Frontend Development)
    • 9.1 TypeScript SDK
  • 10.Sway应用(Sway Reference)
    • 10.1 编译器内部函数(Compiler Intrinsics)
    • 10.2 属性(Attributes)
    • 10.3 风格向导(Style Guide)
    • 10.4 已知各类问题(Known Issues and Workarounds)
    • 10.5 与Solidity的不同之处 (Differences From Solidity)
    • 10.6 与Rust的不同之处 (Differences From Rust)
    • 10.7 向Sway贡献 (Contributing To Sway)
  • 11. Forc引用 (Forc Reference)
    • 11.1清单参考 (Manifest Reference)
    • 11.2 工作区(Workspaces)
    • 11.3 依赖(Dependencies)
    • 11.4 命令(Commands)
      • 11.4.1 forc-addr2line
      • 11.4.2 forc-build
      • 11.4.3 forc-check
Powered by GitBook
On this page
  • [项目]部分 (The [project] section)
  • [依赖]部分 (The [dependencies] section)
  • [网络]部分 (The [network] section)
  • [build-profiles-*] 部分 (The [build-profiles-*] section)
  • [补丁]部分 (The [patch] section)
  • [合约依赖] 部分 (The [contract-dependencies] section)
  1. 11. Forc引用 (Forc Reference)

11.1清单参考 (Manifest Reference)

Previous11. Forc引用 (Forc Reference)Next11.2 工作区(Workspaces)

Last updated 1 year ago

The Forc.toml (the manifest file) is a compulsory file for each package and it is written in [TOML] format. Forc.toml consists of the following fields:

Forc.toml(manifest 文件)是每个包的强制文件,它以 [TOML] 格式编写。 Forc.toml 由以下字段组成:

  • [project] - Defines a sway project. [项目] - 定义一个 sway 项目。

    • name - The name of the project. 名称 - 项目的名称

    • authors - The authors of the project. 作者-项目的作者

    • organization - The organization of the project. 组织-项目的组织

    • license- The project license. 许可证- 项目许可

    • entry - The entry point for the compiler to start parsing from. 入口 - 编译器开始解析的入口点

      • For the recomended way of selecting an entry point of large libraries please take a look at: 有关推荐的选择大型库入口点方法,请查看:

    • implicit-std - Controls whether provided std version (with the current forc version) will get added as a dependency implicitly. Unless you know what you are doing, leave this as default. implicit-std - 控制是否将提供的 std 版本(使用当前的 forc 版本)添加为隐藏依赖。 除非您知道自己在做什么,否则请将其保留为默认值。

    • forc-version - The minimum forc version required for this project to work properly. forc-version - 该项目正常运行所需的最低 forc 版本

  • dependencies- Defines the dependencies. 依赖 - 定义依赖项

  • network - Defines a network for forc to interact with. 网络 - 定义 forc 交互的网络。

  • url -URL of the network. url - 网络的 URL

  • build-profiles - Defines the build profiles. build-profiles - 定义构建配置文件

  • patch - Defines the patches. 补丁 - 定义补丁

  • contract-dependencies- Defines the contract dependencies. 合约依赖- 定义合约依赖。

[项目]部分 (The [project] section)

An example Forc.toml is shown below. Under [project] the following fields are optional:

下面显示了一个示例Forc.toml。在[项目]下,以下字段是可选的:

  • 作者 authors

  • 组织 organization

Also for the following fields, a default value is provided so omitting them is allowed:

此外,还为以下字段提供了默认值,因此允许省略它们:

  • entry - (default : main.sw) 入口 - (默认:main.sw)

  • implicit-std - (default : true) 隐含标准 - (默认值:true)

[project]
authors = ["user"]
entry = "main.sw"
organization = "Fuel_Labs"
license = "Apache-2.0"
name = "wallet_contract"

[依赖]部分 (The [dependencies] section)

The following fields can be provided with a dependency:

可以为以下字段提供依赖:

  • version - Desired version of the dependency 版本 - 所需的依赖版本

  • path - The path of the dependency (if it is local) 路径 - 依赖项的路径(如果是本地的)

  • git - The URL of the git repo hosting the dependency git - 托管依赖的 git 存储库的 URL

  • branch - The desired branch to fetch from the git repo 分支 - 从 git 存储库获取所需的分支

  • tag - The desired tag to fetch from the git repo tag - 从 git 存储库获取所需的标签

  • rev - The desired rev (i.e. commit hash) reference rev - 所需的 rev(即提交哈希)参考

[网络]部分 (The [network] section)

For the following fields, a default value is provided so omitting them is allowed:

对于以下字段,提供了默认值,因此允许省略它们:

[build-profiles-*] 部分 (The [build-profiles-*] section)

The [build-profiles] tables provide a way to customize compiler settings such as debug options.

[build-profiles]表提供了一种自定义编译器设置(例如调试选项)的方法。

The following fields needs to be provided for a build-profile:

构建配置文件需要提供以下字段:

  • print-ast - Whether to print out the generated AST (true) or not (false). print-ast - 是否打印生成的 AST (true) 或不打印 (false)

  • print-dca-graph - Whether to print out the computed DCA graph (in GraphViz DOT format). print-dca-graph - 是否打印计算出的 DCA 图表(以 GraphViz DOT 格式)

  • print-finalized-asm - Whether to compile to bytecode (false) or to print out the generated ASM (true). print-finalized-asm - 是否编译为字节码 (false) 或打印生成的 ASM (true)

  • print-intermediate-asm - Whether to compile to bytecode (false) or to print out the generated ASM (true). print-intermediate-asm - 是否编译为字节码 (false) 或打印生成的 ASM (true)。

  • print-ir - Whether to compile to bytecode (false) or to print out the generated IR (true). print-ir - 是否编译为字节码 (false) 或打印生成的 IR (true)

  • terse-mode - Terse mode. Limited warning and error output. terse-mode - 简洁模式。有限的警告和错误输出。

There are two default [build-profile] available with every manifest file. These are debug and release profiles. If you want to override these profiles, you can provide them explicitly in the manifest file like the following example:

每个清单文件都有两个默认的[build-profile]。这些是调试和发布配置文件。如果您想覆盖这些配置文件,您可以在清单文件中明确提供它们,如下例所示:

[project]
authors = ["user"]
entry = "main.sw"
organization = "Fuel_Labs"
license = "Apache-2.0"
name = "wallet_contract"

[build-profiles.debug]
print-finalized-asm = false
print-intermediate-asm = false
print-ir = false
terse = false

[build-profiles.release]
print-finalized-asm = false 
print-intermediate-asm = false
print-ir = false
terse = true

Note that providing the corresponding cli options (like --print-finalized-asm) will override the selected build profile. For example if you pass both --release and --print-finalized-asm, release build profile is omitted and resulting build profile would have a structure like the following:

请注意,提供相应的 cli 选项(如--print-finalized-asm)将覆盖所选的构建配置文件。例如,如果您同时传递--release和--print-finalized-asm,则发布构建配置文件将被省略,生成的构建配置文件将具有如下结构:

  • print-finalized-asm - true 打印最终确定的asm - true

  • print-intermediate-asm - false 打印中间asm - false

  • print-ir - false 打印IR - false

  • terse - false terse - 错误

[补丁]部分 (The [patch] section)

[project]
authors = ["user"]
entry = "main.sw"
organization = "Fuel_Labs"
license = "Apache-2.0"
name = "wallet_contract"

[dependencies]

[patch.'https://github.com/fuellabs/sway']
std = { git = "https://github.com/fuellabs/sway", branch = "test" }

In the example above, std is patched with the test branch from std repo. You can also patch git dependencies with dependencies defined with a path.

在上面的示例中,std是用std存储库中的test分支修补的。您还可以使用路径定义的依赖项来修补 git 依赖项。

[patch.'https://github.com/fuellabs/sway']
std = { path = "/path/to/local_std_version" }

Just like std or core you can also patch dependencies you declared with a git repo.

就像std 或 core 一样,您也可以修补使用 git 存储库声明的依赖项。

[project]
authors = ["user"]
entry = "main.sw"
organization = "Fuel_Labs"
license = "Apache-2.0"
name = "wallet_contract"

[dependencies]
foo = { git = "https://github.com/foo/foo", branch = "master" }

[patch.'https://github.com/foo']
foo = { git = "https://github.com/foo/foo", branch = "test" }

Note that each key after the [patch] is a URL of the source that is being patched.

请注意,[patch]后面的每个键都是正在修补的源的 URL。

[合约依赖] 部分 (The [contract-dependencies] section)

The [contract-dependenices] table can be used to declare contract dependencies for a Sway contract or script. Contract dependencies are the set of contracts that our contract or script may interact with. Declaring [contract-dependencies] makes it easier to refer to contracts in your Sway source code without having to manually update IDs each time a new version is deployed. Instead, we can use forc to pin and update contract dependencies just like we do for regular library dependencies.

[合约依赖 contract-dependenices]表可用于声明 Sway 合约或脚本的合约依赖。合约依赖是合约或脚本可能与之交互的一组合约。声明[合约依赖 contract-dependenices]可以更轻松地引用 Sway 源代码中的合约,而无需在每次部署新版本时手动更新 ID。相反,我们可以使用 forc 来固定和更新合约依赖,就像处理常规库依赖一样。

Contracts declared under [contract-dependencies] are built and pinned just like regular [dependencies] however rather than importing each contract dependency's entire public namespace we instead import their respective contract IDs as CONTRACT_ID constants available via each contract dependency's namespace root. This means you can use a contract dependency's ID as if it were declared as a pub const in the root of the contract dependency package as demonstrated in the example below.

在[合约依赖 contract-dependencies]下,声明合约的构建和固定就像常规的[依赖项 dependencies]一样,但是我们并不导入每个合约依赖的整个公共命名空间,而是将其各自合约 ID 导入,为可通过每个合约依赖的命名空间使用的CONTRACT_ID常量根。这意味着您可以使用合约依赖的 ID,就好像它在合约依赖包的根目录中声明为pub const一样,如下例所示。

Entries under [contract-dependencies] can be declared in the same way that [dependencies] can be declared. That is, they can refer to the path or git source of another contract. Note that entries under [contract-dependencies] must refer to contracts and will otherwise produce an error.

[合约依赖 contract-dependencies]下的条目可以以与[dependencies]相同的方式声明。也就是说,他们可以引用另一个合约的path或git源。请注意,[dependencies]下的条目必须引用合约,否则会产生错误。

Example Forc.toml: 示例 Forc.toml:

[project]
authors = ["user"]
entry = "main.sw"
organization = "Fuel_Labs"
license = "Apache-2.0"
name = "wallet_contract"

[contract-dependencies]
foo = { path = "../foo" }

Example usage: 示例用法:

script;

fn main() {
  let foo_id = foo::CONTRACT_ID;
}

Because the ID of a contract is computed deterministically, rebuilding the same contract would always result in the same contract ID. Since two contracts with same contract ID cannot be deployed on the blockchain, a "salt" factor is needed to modify the contract ID. For each contract dependency declared under [contract-dependencies], salt can be specified. An example is shown below:

由于合约的 ID 是确定性计算的,因此重建相同的合约将始终产生相同的合约 ID。由于两个具有相同合约ID的合约无法部署在区块链上,因此需要一个“盐”因子来修改合约ID。对于在[合约依赖 contract-dependencies]下声明的每个合约依赖,可以指定“盐”。一个例子如下所示:

[contract-dependencies]
foo = { path = "../foo", salt = "0x1000000000000000000000000000000000000000000000000000000000000000" }

For contract dependencies that do not specify any value for salt, a default of all zeros for salt is implicitly applied.

对于未指定盐 salt任何值的合约依赖,将默认把salt的值设置为0。

Please see for details

有关详细信息,请参阅

URL - (default: ) URL - (默认值:)

Since release and debug implicitly included in every manifest file, you can use them by just passing --release or by not passing anything (debug is default). For using a user defined build profile there is --build-profile <profile name> option available to the relevant commands. (For an example see )

由于release和debug 隐式包含在每个清单文件中,因此您可以通过仅传递--release或不传递任何内容(默认为debug)来使用。要使用用户定义的构建配置文件,相关命令可以使用--build-profile <profile name>选项。 (有关示例,请参阅)

The [patch] section of Forc.toml can be used to override dependencies with other copies. The example provided below patches source with master branch of the same repo.

Forc.toml 的 [patch] 部分可用于覆盖与其他副本的依赖。下面提供的示例,使用同一存储库 为源的主分支 。

Libraries
Libraries
dependencies
依赖
http://127.0.0.1:4000
http://127.0.0.1:4000
forc-build
forc-build
https://github.com/fuellabs/sway
https://github.com/fuellabs/sway