sBTC 注册表
概述
该 sBTC 注册表合约 (sbtc-registry.clar)作为 sBTC 系统的中央注册表。它管理提款请求、已完成的存款以及当前的签名者集合。该合约对于维护状态和协调 sBTC 生态系统内的操作至关重要。
错误常量
ERR_UNAUTHORIZED(u400):表示未授权访问。ERR_INVALID_REQUEST_ID(u401):表示无效的提款请求 ID。ERR_AGG_PUBKEY_REPLAY(u402):表示尝试重放聚合公钥。ERR_MULTI_SIG_REPLAY(u403):表示尝试重放多重签名地址。
状态变量
last-withdrawal-request-id:跟踪最新的提款请求 ID。current-signature-threshold:存储当前所需签名的阈值。current-signer-set:维护当前签名者公钥的列表。current-aggregate-pubkey:保存当前的聚合公钥。current-signer-principal:存储当前签名者的主体地址。
数据映射
withdrawal-requests
按请求 ID 存储提款请求详情。
字段:
amount:被提取的 sBTC 数量(以聪为单位)max-fee:提款的最大费用sender:发送者的主体(principal)recipient:BTC 接收地址(版本和哈希字节)block-height:创建请求时的燃烧区块高度
withdrawal-status
按请求 ID 跟踪提款请求的状态。
值:
bool(接受为 true,拒绝为 false,挂起为 none)
completed-deposits
记录已完成的存款交易以防止重放攻击。
键:
{txid: (buff 32), vout-index: uint}值:
{amount: uint, recipient: principal}
aggregate-pubkeys
跟踪已使用的聚合公钥以防止重放攻击。
键:
(buff 33)(聚合公钥)值:
bool
multi-sig-address
跟踪已使用的多重签名地址以防止重放攻击。
键:
principal(多重签名地址)值:
bool
protocol-contracts
存储授权的协议合约地址。
键:
principal(合约地址)值:
bool
只读函数
get-withdrawal-request
按 ID 检索提款请求。
参数:
id:uint
返回:
(optional {amount: uint, max-fee: uint, sender: principal, recipient: {version: (buff 1), hashbytes: (buff 32)}, block-height: uint, status: (optional bool)})
get-completed-deposit
按交易 ID 和输出索引获取已完成的存款。
参数:
txid:(buff 32)vout-index:uint
返回:
(optional {amount: uint, recipient: principal})
get-current-signer-data
返回当前签名者集合信息。
返回:
{current-signer-set: (list 128 (buff 33)), current-aggregate-pubkey: (buff 33), current-signer-principal: principal, current-signature-threshold: uint}
get-current-aggregate-pubkey
返回当前的聚合公钥。
返回:
(buff 33)
get-current-signer-principal
返回当前签名者的主体。
返回:
principal
get-current-signer-set
返回当前的签名者公钥集合。
返回:
(list 128 (buff 33))
公共函数
create-withdrawal-request
创建新的提款请求。仅可由协议合约调用。
参数:
amount:uintmax-fee:uintsender:principalrecipient:{version: (buff 1), hashbytes: (buff 32)}height:uint
返回:
(response uint uint)
complete-withdrawal-accept
将提款请求标记为已接受。
参数:
request-id:uintbitcoin-txid:(buff 32)output-index:uintsigner-bitmap:uintfee:uint
返回:
(response bool uint)
complete-withdrawal-reject
将提款请求标记为已拒绝。
参数:
request-id:uintsigner-bitmap:uint
返回:
(response bool uint)
complete-deposit
记录已完成的存款交易。
参数:
txid:(buff 32)vout-index:uintamount:uintrecipient:principal
返回:
(response bool uint)
rotate-keys
更新签名者集合、多重签名主体和聚合公钥。
参数:
new-keys:(list 128 (buff 33))new-address:principalnew-aggregate-pubkey:(buff 33)new-signature-threshold:uint
返回:
(response (buff 33) uint)
私有函数
increment-last-withdrawal-request-id
递增并返回下一个提款请求 ID。
返回:
uint
is-protocol-caller
检查调用者是否为授权的协议合约。
返回:
(response bool uint)
validate-protocol-caller
验证给定主体是否为授权的协议合约。
参数:
caller:principal
返回:
(response bool uint)
事件
合约通过(使用 print)为重要操作发出事件:
提款请求创建:“withdrawal-create”
提款接受:“withdrawal-accept”
提款拒绝:“withdrawal-reject”
存款完成:“completed-deposit”
安全注意事项
访问控制
只有授权的协议合约可以调用某些函数。
重放防护
该合约防止对存款、聚合公钥和多重签名地址的重放攻击。
状态管理
该合约仔细管理提款的状态和当前签名者集合。
这有帮助吗?