diff --git a/lib/ckb/api.rb b/lib/ckb/api.rb index 5e773132..31df7804 100644 --- a/lib/ckb/api.rb +++ b/lib/ckb/api.rb @@ -16,7 +16,7 @@ def initialize(host: CKB::RPC::DEFAULT_URL, mode: MODE::TESTNET) @rpc = CKB::RPC.new(host: host) if mode == MODE::TESTNET # Testnet system script code_hash - expected_code_hash = "0x94334bdda40b69bae067d84937aa6bbccf8acd0df6626d4b9ac70d4612a11933" + expected_code_hash = "0x54811ce986d5c3e57eaafab22cdd080e32209e39590e204a99b32935f835a13c" # For testnet chain, we can assume the second cell of the first transaction # in the genesis block contains default lock script we can use here. system_cell_transaction = genesis_block.transactions.first diff --git a/lib/ckb/types/script.rb b/lib/ckb/types/script.rb index 82fe4d32..75fb2204 100644 --- a/lib/ckb/types/script.rb +++ b/lib/ckb/types/script.rb @@ -3,13 +3,14 @@ module CKB module Types class Script - attr_reader :code_hash, :args + attr_reader :code_hash, :args, :hash_type # @param code_hash [String] # @param args [String[]] - def initialize(code_hash:, args:) + def initialize(code_hash:, args:, hash_type: "Data") @code_hash = code_hash @args = args + @hash_type = hash_type end # @return [Integer] Byte @@ -22,7 +23,8 @@ def calculate_bytesize def to_h { code_hash: @code_hash, - args: @args + args: @args, + hash_type: @hash_type } end @@ -31,13 +33,22 @@ def self.from_h(hash) new( code_hash: hash[:code_hash], - args: hash[:args] + args: hash[:args], + hash_type: hash[:hash_type] ) end def to_hash blake2b = CKB::Blake2b.new blake2b << Utils.hex_to_bin(@code_hash) if @code_hash + blake2b << case @hash_type + when "Data" + "\x0" + when "Type" + "\x1" + else + raise "Invalid hash type!" + end args = @args || [] args.each do |arg| blake2b << Utils.hex_to_bin(arg) diff --git a/spec/ckb/types/script_spec.rb b/spec/ckb/types/script_spec.rb index 4bfbe42b..a0050feb 100644 --- a/spec/ckb/types/script_spec.rb +++ b/spec/ckb/types/script_spec.rb @@ -11,7 +11,7 @@ ) end - let(:code_hash) { "0x86f4f705a8e85905b1c73b84b1f3a3cf6dbfdd7eb8e47bfd1c489681ee2762cb" } + let(:code_hash) { "0xc00073200d2b2f4ad816a8d04bb2431ce0d3ebd49141b086eda4ab4e06bc3a21" } it "to_hash" do expect(