关于 btc-terminology
btc-terminology 是一项开发技能,说明 Bitcoin 地址术语在配置、Go 代码和 Bitcoin Core RPC 中的用法,重点区分 Taproot 地址类型与 Bech32m 编码。
主要功能
- 01区分 Taproot 与 Bech32m
- 02说明配置和 RPC 中的术语
- 03记录 Go 类型转换
- 04提供核对清单
适用场景
- 01编辑 Taproot 地址配置
- 02编写 Bitcoin Core RPC 调用
- 03审查地址相关 Go 代码
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ hiromaily/ go-crypto-wallet --skill btc-terminology安装后在 Claude Code 中输入/btc-terminology确认已加载。
详细介绍
BTC 术语规则
🚨 严重:Bech32m 与 Taproot
这是常见的 Bug 来源。 切勿混淆这些术语:
| 术语 | 含义 | 使用场景 |
|---|---|---|
| bech32m | 编码格式(地址的序列化方式) | Bitcoin Core RPC、Shell 脚本 |
| taproot | 地址类型(地址所代表的内容) | 配置文件、领域模型 |
关键规则: bech32m ≠ taproot —— 两者相关,但不可互换。
快速参考表
| 场景 | 正确术语 | 示例 |
|---|---|---|
| 配置 YAML/TOML 文件 | taproot | address_type: "taproot" |
| 环境变量 | taproot | WALLET_ADDRESS_TYPE="taproot" |
| Bitcoin Core CLI/RPC | bech32m | bitcoin-cli getnewaddress "" bech32m |
| Shell 脚本(接收方地址) | bech32m | getnewaddress "" bech32m |
Go 领域代码(internal/domain/address/) | taproot | AddrTypeTaproot |
Go Bitcoin Core 接口(internal/domain/bitcoin/) | bech32m | AddressTypeTaproot = "bech32m" |
常见错误
❌ 错误
# Config file - DON'T use bech32m
address_type: "bech32m" # WRONG!
# Shell script - DON'T use taproot for Bitcoin Core RPC
bitcoin-cli getnewaddress "" taproot # WRONG!
✅ 正确
# Config file - Use taproot
address_type: "taproot" # CORRECT!
# Shell script - Use bech32m for Bitcoin Core RPC
bitcoin-cli getnewaddress "" bech32m # CORRECT!
技术背景
为什么有两个不同的术语?
- Taproot(BIP341)= SegWit 版本 1 地址类型(P2TR - Pay-to-Taproot)
- Bech32m(BIP350)= 用于修复原始 Bech32 校验和问题的编码格式
所有 Taproot 地址都使用 bech32m 编码,但:
- 面向用户的配置使用“taproot”(你想要的地址类型)
- Bitcoin Core RPC 使用“bech32m”(地址的编码方式)
地址格式对比
| 编码 | SegWit 版本 | 地址类型 | 前缀 | 配置值 |
|---|---|---|---|---|
| Base58 | N/A | P2PKH | 1... | legacy |
| Base58 | N/A | P2SH | 3... | p2sh-segwit |
| Bech32 | v0 | P2WPKH | bc1q... | bech32 |
| Bech32m | v1 | P2TR | bc1p... | taproot |
代码库映射
项目中有两种不同的类型定义:
// internal/domain/bitcoin/address_type.go
// For Bitcoin Core RPC communication
AddressTypeTaproot AddressType = "bech32m" // Bitcoin Core uses "bech32m"
// internal/domain/address/types.go
// For user-facing configuration
AddrTypeTaproot AddrType = "taproot" // User sees "taproot"
这两种类型之间的转换由映射函数处理:
// internal/infrastructure/api/btc/btc/mapper.go
// FromAddressType: "bech32m" (Bitcoin Core) → "taproot" (user-facing)
// ToAddressType: "taproot" (user-facing) → "bech32m" (Bitcoin Core)
验证清单
处理 Taproot/Bech32m 代码时:
- 配置文件(YAML/TOML)使用
address_type: "taproot" - 环境变量使用
WALLET_ADDRESS_TYPE="taproot" - Shell 脚本中的 Bitcoin Core RPC 调用使用
bech32m - 生成接收方地址的 Shell 脚本使用
bech32m - Go 代码根据所在层级使用正确的类型:
- 领域/配置层:
AddrTypeTaproot(值:"taproot") - Bitcoin Core 接口:
AddressTypeTaproot(值:"bech32m")
- 领域/配置层:
相关文件
| 文件 | 用途 |
|---|---|
internal/domain/address/types.go | 面向用户的 AddrType 定义 |
internal/domain/bitcoin/address_type.go | Bitcoin Core AddressType 定义 |
internal/infrastructure/api/btc/btc/mapper.go | 类型转换函数 |
docs/chains/btc/taproot/user-guide.md | Taproot 用户指南 |
Related Documentation
评论
支持 Markdown