Bivrost 构建状态

🔥 🌈 Solidity 合约和 Swift 之间的桥梁

Bivrost 处于非常早期的开发阶段。不要将其用于任何重要的用途。

描述

bivrost 为 Solidity 合约生成 Swift 类,这些类知道如何编码和解码其函数调用。 使用此工具生成可发送到区块链的交易。

您可以将其用作 Swift 项目的预编译脚本阶段。 生成所需的文件,然后将其添加到您的项目中。

bivrost 创建一个输出文件夹,其中包含用于编码和解码的辅助代码以及生成的合约类。

用法

Mint 🌱

$ mint run gnosis/bivrost-swift "bivrost --input './contracts/*.json' --output '../Sources/Solidity'"

SPM

$ git clone https://github.com/gnosis/bivrost-swift
$ cd bivrost-swift
$ swift run bivrost --input './contracts/*.json' --output '../Sources/Solidity'

目前不支持从代码中使用 BivrostKit,但已列入路线图。

选项

运行 $ mint run gnosis/bivrost-swift "bivrost --help" 以获取当前帮助。

输入文件

bivrost 解析由 truffle 编译器 生成的 Solidity 合约 JSON 文件以进行代码生成。 它们应具有以下格式

{
    "contract_name": "TestContract",
    "abi": [
      {
        "constant": false,
        "inputs": [
          {
            "name": "inputVariable",
            "type": "uint16"
          },
          {
            "name": "anotherInputVariable",
            "type": "uint128"
          }
        ],
        "name": "aTestFunction",
        "outputs": [
          {
            "name": "outputVariable",
            "type": "bool"
          }
        ],
        "payable": false,
        "type": "function"
      },
      [ more function definitions... ]
    ]
}

输出

bivrost 在输出文件夹中生成以下文件夹结构

<output folder>
  - BivrostError.swift
  - Coding
    - BaseEncoder.swift
    - BaseDecoder.swift
  - Extensions
    - BigIntExtension.swift
    - DataExtension.swift
    - StringExtension.swift
  - Generated Contracts
    - ContractName1.swift
    - ContractName2.swift
  - Generated Types
    - ArrayX-Generated.swift
    - BytesX-Generated.swift
    - IntX-Generated.swift
    - UIntX-Generated.swift
  - Protocols
    - DynamicType.swift
    - SolidityCodable.swift
    - SolidityFunction.swift
    - StaticType.swift
  - Types
    - Address.swift
    - ArrayX.swift
    - Bool.swift
    - Bytes.swift
    - BytesX.swift
    - Function.swift
    - IntX.swift
    - Solidity.swift
    - String.swift
    - UIntX.swift
    - VariableArray.swift

生成的代码依赖于 BigInt (import BigInt),因此请确保生成的代码可以使用它。

许可证

Bivrost 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。

问题

当前,通过 swift package generate-xcodeproj 生成 Xcode 项目时,测试不起作用。 此问题在 Quick/Quick#751 中进行了描述。

解决方法