Skip to content

Commit

Permalink
feat: generate full payload address
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Sep 19, 2019
1 parent 17b42dc commit 2e49198
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/utils/ckb_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ def self.generate_lock_script_from_cellbase(cellbase)
end

def self.generate_address(lock_script)
return unless use_default_lock_script?(lock_script)
if use_default_lock_script?(lock_script)
short_payload_blake160_address(lock_script)
else
code_hash = lock_script.code_hash
args = lock_script.args
format_type = lock_script.hash_type == "data" ? "0x02" : "0x04"
first_arg = args.first

return if args.blank? || !args.all? { |arg| CKB::Utils.valid_hex_string?(arg) }

type1_address(lock_script)
CKB::Address.new(first_arg).generate_full_payload_address(format_type, code_hash, args)
end
end

def self.type1_address(lock_script)
def self.short_payload_blake160_address(lock_script)
blake160 = lock_script.args.first
return if blake160.blank? || !CKB::Utils.valid_hex_string?(blake160)

Expand Down

0 comments on commit 2e49198

Please sign in to comment.