What information is contained in the witness of a cellbase cell

We are reviewing a piece of code(feat: support message on cellbase witnesses · nervosnetwork/ckb-explorer@468357e · GitHub) and have discovered that the context of the commit has been lost, so we are unclear about the specific meaning of the code.

def self.generate_lock_script_from_cellbase(cellbase)
    cellbase_witness = cellbase.witnesses.first.delete_prefix("0x")
    cellbase_witness_serialization = [cellbase_witness].pack("H*")
    script_offset = [cellbase_witness_serialization[4..7].unpack1("H*")].pack("H*").unpack1("V")
    message_offset = [cellbase_witness_serialization[8..11].unpack1("H*")].pack("H*").unpack1("V")
    script_serialization = cellbase_witness_serialization[script_offset...message_offset]
    code_hash_offset = [script_serialization[4..7].unpack1("H*")].pack("H*").unpack1("V")
    hash_type_offset = [script_serialization[8..11].unpack1("H*")].pack("H*").unpack1("V")
    args_offset = [script_serialization[12..15].unpack1("H*")].pack("H*").unpack1("V")
    code_hash_serialization = script_serialization[code_hash_offset...hash_type_offset]
    hash_type_serialization = script_serialization[hash_type_offset...args_offset]
    args_serialization = script_serialization[hash_type_offset + 1..-1]
    args_serialization = args_serialization[4..-1]

    code_hash = "0x#{code_hash_serialization.unpack1("H*")}"
    hash_type_hex = "0x#{hash_type_serialization.unpack1("H*")}"
    args = "0x#{args_serialization.unpack1("H*")}"

    hash_type = hash_type_hex == "0x00" ? "data" : "type"
    CKB::Types::Script.new(code_hash: code_hash, args: args, hash_type: hash_type)
  end

Is there any documentation available regarding the decoding of the cellbase witness?

1 Like

Here is a simulation of using Molecule to deserialize CellbaseWitness data.

you can use explorer Tool for an online experience. CKB Explorer

2 Likes