这篇文章上次修改于 565 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

1 type id

blak2b(
    first_input_cell {
        since,
        previous_outpoint,
    },
    first_output_cell_using_the_current_type_script = 0,
)

2 使用 type id 部署一个合约

inputs
    ckb cell
outputs
    contract cell
        - data: contract bin
        - lock: deployer
        - type: 
            - code_hash: TYPE_ID_CODE_HASH
            - hash_type: type
            - args: blak2b(
                first_input_cell {
                    since,
                    previous_outpoint,
                },
                first_output_cell_using_the_current_type_script = 0,
              )
    ckb cell

3 升级合约

inputs
    old contract cell
    ckb cell
outputs
    new contract cell
        - data: new contract bin
        - lock: deployer
        - type: same with old contract cell
    ckb cell

4 使用升级后的合约

合约升级后,old contract cell 会被销毁,所以 tx deps 中应该放 new contract cell 的索引。

inputs
    some cells
        - type
            - code_hash: hash(new_contract_cell.type)
            - hash_type: type
            - args
outputs
    some cells
deps
    new contract cell