@acc-toppings/api-acc-compiler 中文文档教程

发布于 5年前 浏览 16 项目主页 更新于 3年前

api-acc-compiler NPM Version

可以执行以下功能的独立 Node.JS 服务器:

  • Compile a smart contract to generate an .abi file
  • Compile and deploy a smart contract to the blockchain in a single step
  • Import a ready-made .abi file to go with the deployment of a smart contract

在引擎盖下,这些功能创建一个运行 acc.cdt 的 Docker 容器。 可以在此处查看有关此的更多信息。

Installation

如果与其他工具分开运行,请导航到此包的根目录并运行 yarn install。 安装所有依赖项后,导航到 ./docker-acc-cdt 文件夹并运行 ./build_acc_cdt_docker.sh 以构建 Docker 映像。 这是必要的,因为该服务将执行 shell 脚本代码,该代码会暂时启动 Docker 容器(在完成任务后处置)。

之后,导航回根目录并执行 yarn start 以启动本地服务。

Endpoints

/api/acc/compile - POST method

一种 POST 方法,它根据提供的 source 输入为智能合约编译一组源文件。 它接受以下参数:

  1. source - <String> - An absolute file path to the entry file of the smart contract. The filename with file extension will be passed to acc-cpp as the primary argument for compilation.

它将返回以下内容:

{
    wasmLocation: - <String> - full path of the compiled WASM file
    abi: - <String> - full path of the ABI file
    abiContents: - <String> - Stringified contents of the ABI file
    errors: - <Array[String]> - List of possible errors
    stdout: - <Array[String]> - Line by line contents of the standard output of the compiler
    stderr: - <Array[String]> - Line by line contents of the standard error of the compiler
    compiled: - <Boolean> - Helper field to determine if file has been compiled or not
}

请注意,它将使用包含 source 中指示的条目文件的文件夹作为文件所有依赖项的容器。

/api/acc/import - POST method

一种 POST 方法,它将文件名和该文件的内容作为输入,将文件写入 API 服务器中的预定位置,以便用于智能合约部署。 当编译 ABI 不起作用时,使用此 API 方法作为备份。 它接受以下参数:

  1. abiName - <String> - A file name with file extension such as abi_file.abi
  2. content - <String> - The raw stringified content of the .abi file to import

它将返回以下内容:

{
    abiPath: - <String> - The full path of the imported ABI file
    errors: - <Array[String]> - List of possible errors
    imported: - <Boolean> - Helper field to determine if the file has been compiled or not
}

/api/acc/deploy - POST method

一个 POST 方法,它根据提供的 source 输入为智能合约编译一组源代码文件。 之后,它会将编译好的智能合约部署到区块链的endpoint,并使用account_name 权限和private_key 签名。 或者,如果提供了 abiSource,该服务将使用 abiSource 中的 .abi 文件,而不是生成 .abi 文件本身。 它接受以下参数:

  1. source - <String> - An absolute file path to the entry file of the smart contract. The filename with file extension will be passed to acc-cpp as the primary argument for compilation.
  2. endpoint - <String> - The full endpoint of the nodeacc instance the user wishes to deploy the contract to
  3. account_name - <String> - The name of the account that will sign and deploy this contract
  4. private_key - <String> - The private key of the account's permission. Be aware to use the correct private key. Otherwise, you may receive an error.
  5. [abiSource] - <String> - An absolute file path to the imported .abi file to use instead of the default behavior. Optional field.

它将返回以下内容:

{
    wasmLocation: - <String> - full path of the compiled WASM file
    abi: - <String> - full path of the ABI file
    abiContents: - <String> - Stringified contents of the ABI file
    output: - <Object> - Trimmed result of the deployment action, in cases of deployment success
    errors: - <Array[String]> - List of possible errors
    stdout: - <Array[String]> - Line by line contents of the standard output of the compiler
    stderr: - <Array[String]> - Line by line contents of the standard error of the compiler
    compiled: - <Boolean> - Helper field to determine if file has been compiled or not
    deployed: - <Boolean> - Helper field to determine if file has been deployed or not
}

请注意,它将使用包含 source 中指示的条目文件的文件夹作为文件所有依赖项的容器。

api-acc-compiler NPM Version

Self-contained Node.JS server that can perform the following functions:

  • Compile a smart contract to generate an .abi file
  • Compile and deploy a smart contract to the blockchain in a single step
  • Import a ready-made .abi file to go with the deployment of a smart contract

Under the hood, these functions create a Docker container running acc.cdt. More information about this can be viewed here.

Installation

Navigate to the root of this package and run yarn install if running separately from the rest of the tools. Once all dependencies have been installed, navigate to the ./docker-acc-cdt folder and run ./build_acc_cdt_docker.sh to build the Docker image. This is necessary as the service will execute shell script code which spins up the Docker container transiently (disposed after it has finished the task).

Afterwards, navigate back to the root and do yarn start to spin up the local service.

Endpoints

/api/acc/compile - POST method

A POST method that compiles a group of source files for the smart contract based on a provided source input. It accepts the following as parameters:

  1. source - <String> - An absolute file path to the entry file of the smart contract. The filename with file extension will be passed to acc-cpp as the primary argument for compilation.

It will return the following:

{
    wasmLocation: - <String> - full path of the compiled WASM file
    abi: - <String> - full path of the ABI file
    abiContents: - <String> - Stringified contents of the ABI file
    errors: - <Array[String]> - List of possible errors
    stdout: - <Array[String]> - Line by line contents of the standard output of the compiler
    stderr: - <Array[String]> - Line by line contents of the standard error of the compiler
    compiled: - <Boolean> - Helper field to determine if file has been compiled or not
}

Note, that it will use the folder containing the entry file indicated in source as the container for all dependencies of the file.

/api/acc/import - POST method

A POST method which takes a file name and the contents of that file as an input, writing the file to a pre-determined location in the API server so it can be used for smart contract deployment. Use this API method as a back up for cases when compiling the ABI did not work. It accepts the following as parameters:

  1. abiName - <String> - A file name with file extension such as abi_file.abi
  2. content - <String> - The raw stringified content of the .abi file to import

It will return the following:

{
    abiPath: - <String> - The full path of the imported ABI file
    errors: - <Array[String]> - List of possible errors
    imported: - <Boolean> - Helper field to determine if the file has been compiled or not
}

/api/acc/deploy - POST method

A POST method that compiles a group of source code files for the smart contract based on a provided source input. Afterwards, it will deploy the compiled smart contract to the blockchain at endpoint with the account_name permission signed with private_key. Optionally, if abiSource is provided, the service will use the .abi file at abiSource instead of generating the .abi file itself. It accepts the following as parameters:

  1. source - <String> - An absolute file path to the entry file of the smart contract. The filename with file extension will be passed to acc-cpp as the primary argument for compilation.
  2. endpoint - <String> - The full endpoint of the nodeacc instance the user wishes to deploy the contract to
  3. account_name - <String> - The name of the account that will sign and deploy this contract
  4. private_key - <String> - The private key of the account's permission. Be aware to use the correct private key. Otherwise, you may receive an error.
  5. [abiSource] - <String> - An absolute file path to the imported .abi file to use instead of the default behavior. Optional field.

It will return the following:

{
    wasmLocation: - <String> - full path of the compiled WASM file
    abi: - <String> - full path of the ABI file
    abiContents: - <String> - Stringified contents of the ABI file
    output: - <Object> - Trimmed result of the deployment action, in cases of deployment success
    errors: - <Array[String]> - List of possible errors
    stdout: - <Array[String]> - Line by line contents of the standard output of the compiler
    stderr: - <Array[String]> - Line by line contents of the standard error of the compiler
    compiled: - <Boolean> - Helper field to determine if file has been compiled or not
    deployed: - <Boolean> - Helper field to determine if file has been deployed or not
}

Note, that it will use the folder containing the entry file indicated in source as the container for all dependencies of the file.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文