-
Notifications
You must be signed in to change notification settings - Fork 2
type id 合约
Chen Yu edited this page Feb 23, 2022
·
4 revisions
CKB 交易在执行合约的时候, 支持 script 以
hash type: type # 意味着去找 type script 的 hash
code hash: hash(contract cell's type script) # 指定要找的 type script 的 hash
args: 任意数据的形式, 通过 contract cell 的 type script 的 hash 去定位合约所在 cell
type id 合约是内置于 CKB 节点的系统级别的合约, 他的运行结果是在部署合约的时候保证新产生的合约所在的 cell 的 type script 会是独一无二的, 假设一个合约部署的时候依赖了 type id 合约, 那么这个合约 cell 会是下面这个结构
type script:
# type script of deployed contract
hash type: type
code hash: type id 合约的 code hash
args: 一段基于部署合约时算出来的 hash
data: 合约源码这个 type script 是独一无二的, 因为 hash type 和 code hash 指向 type id 合约, 是既定的. args 是部署合约的时候计算出来的, 不会存在冲突.
因为这个 type script 是独一无二的(虽然区别只有 args), 所以可以考虑以 hash(type script) 为索引来定位合约所在的 cell, 后续业务合约升级时, 只要新部署的合约继续带上这个同一个 type script(主要是那个 args 不变), 就可以认为是同一业务的合约, 所以上面这个 type script 的 hash 被是为合约的 id
type script:
# type script of deployed contract
hash type: type
code hash: type id 合约的 code hash
args: 来自上一版合约所在 cell 的 type script 的 args
data: 新的合约源码