Skip to content

安装


本页说明如何确认你拿到的 utxo_compiler 是否能运行。utxo_compiler 是命令行程序:你在终端里输入命令,它读取 .ct 合约文件,再输出编译结果。

支持的平台

  • Linux
  • Windows 64 位
  • Windows 32 位
  • macOS:计划支持

发布产物结构

Linux 包结构

下载并解压 Linux 包后,目录通常长这样:

utxo_compiler-v1.0.0-linux/
├── utxo_compiler        # 可执行文件
├── doc/                 # 文档目录
├── install.sh           # 安装脚本
└── VERSION              # 版本信息

Windows 包结构

Windows 包会额外带上运行所需的动态链接库(DLL)。DLL 可以理解为程序运行时要加载的依赖文件。

utxo_compiler-v1.0.0-windows-64/32/
├── utxo_compiler.exe    # Windows可执行文件
├── libstdc++-6.dll      # C++标准库
├── libgcc_s_seh-1.dll   # GCC运行时库
├── libwinpthread-1.dll  # 多线程支持库
├── doc/                 # 文档目录
├── install.bat          # Windows安装脚本
├── DEPENDENCIES.txt     # 依赖库说明
└── VERSION              # 版本信息

测试和验证

第一步:确认程序能启动

在终端中进入解压后的目录,然后运行版本检查命令。

Linux:

bash
./builds/linux/bin/utxo_compiler --version

Windows 可执行文件也可以在 Linux 上用 Wine 做基础验证:

bash
# 如果没有 Wine,需要先安装
sudo apt install wine

wine ./builds/windows-64/bin/utxo_compiler.exe --version
wine ./builds/windows-32/bin/utxo_compiler.exe --version

第二步:编译一个最小合约

准备一个文件 p2pkh.ct

python
Contract P2PKH:
    def verify(sig: hex, pubKey: hex):
        pubKeyHash = Hash160(pubKey.Clone())
        EqualVerify(pubKeyHash, self.pubKeyHash)
        result = CheckSig(sig, pubKey)

这段代码的作用是验证“签名是否来自指定公钥哈希对应的私钥”。几个关键点:

  • sig:交易签名,花费 UTXO 时由调用方提供。
  • pubKey:公钥,合约会计算它的 Hash160
  • self.pubKeyHash:部署合约时写入锁定脚本的目标公钥哈希。
  • Clone():复制 pubKey,因为 Hash160 会消耗传入的值,后面 CheckSig 还要再用一次。

编译:

bash
./builds/linux/bin/utxo_compiler p2pkh.ct

如果编译成功,说明命令行程序、基本语法解析和字节码生成都可以工作。后续可以进入 教程一:P2PKH 合约入门,学习如何调试和调用它。

验证 Windows 包依赖库

如果 Windows 用户反馈程序无法启动,可以检查包里是否包含所需 DLL:

bash
# 检查 Windows 可执行文件依赖哪些 DLL
x86_64-w64-mingw32-objdump -p builds/windows-64/bin/utxo_compiler.exe | grep "DLL Name"

# 检查 zip 包中是否包含 DLL
unzip -l dist/utxo_compiler-v*-windows-64.zip | grep "\.dll"

初级开发者易踩坑

  • 把包内路径写错:示例中的 ./builds/linux/bin/utxo_compiler 是开发目录路径。如果你使用的是发布包,可能是 ./utxo_compiler
  • Windows 缺 DLLutxo_compiler.exe 旁边需要放着依赖 DLL,不能只复制一个 .exe
  • .ct 文件名写错:编译命令最后一个参数必须指向真实存在的合约文件。
  • 第一次就上链测试:建议先本地编译和调试,通过后再构造真实交易。

快速回顾

  • utxo_compiler 是命令行编译器,用来把 .ct 合约编译成锁定脚本字节码。
  • 安装后先运行 --version,再编译一个最小合约确认环境可用。
  • Windows 包需要 .exe 和 DLL 放在一起。
  • 如果代码里同一个变量要用两次,通常需要先 .Clone()

下一步


🇬🇧 English version