Skip to content

Commit

Permalink
Merge pull request #2106 from nervosnetwork/testnet
Browse files Browse the repository at this point in the history
Deploy to mainnet
  • Loading branch information
rabbitz authored Aug 1, 2024
2 parents e161ec2 + 9e06a1b commit 4eba470
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
23 changes: 11 additions & 12 deletions app/controllers/api/v2/bitcoin_vouts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ def verify
bitcoin_vouts = BitcoinVout.includes(:bitcoin_transaction).
where(bitcoin_transactions: { txid: previous_vout["txid"] },
bitcoin_vouts: { index: previous_vout["index"], op_return: false })
bitcoin_vouts.each do |vout|
next if vout.unbound? || vout.normal?
next unless vout.cell_output

status =
if vout.cell_output.dead?
"normal"
elsif vout.cell_output == cell_output
"binding"
else
"unbound"
end
vout.update(consumed_by:, status:)
related_cell_outputs = bitcoin_vouts.map(&:cell_output).compact
if related_cell_outputs.all?(&:live?)
bitcoin_vouts.update_all(status: "binding")
else
bitcoin_vouts.each do |vout|
next unless vout.cell_output
next if vout.normal? || vout.unbound?

status = vout.cell_output.dead? ? "normal" : "unbound"
vout.update(consumed_by:, status:)
end
end

head :no_content
Expand Down
30 changes: 21 additions & 9 deletions app/utils/ckb_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -614,15 +614,27 @@ def self.hexes_to_bins_sql(hex_strings)
end

def self.parse_spore_cluster_data(hex_data)
data = hex_data.slice(2..-1)
name_offset = [data.slice(8, 8)].pack("H*").unpack1("l") * 2
description_offset = [data.slice(16, 8)].pack("H*").unpack1("l") * 2
name = [data.slice(name_offset + 8..description_offset - 1)].pack("H*")
description = [data.slice(description_offset + 8..-1)].pack("H*")
name = "#{name[0, 97]}..." if name.length > 100
{ name:, description: }
rescue StandardError => _e
{ name: nil, description: nil }
safe_encode = Proc.new do |str|
str.force_encoding("UTF-8").encode("UTF-8", invalid: :replace, undef: :replace, replace: "")
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
""
end

begin
data = hex_data.slice(2..-1)
name_offset = [data.slice(8, 8)].pack("H*").unpack1("l") * 2
description_offset = [data.slice(16, 8)].pack("H*").unpack1("l") * 2
name = [data.slice(name_offset + 8..description_offset - 1)].pack("H*")
description = [data.slice(description_offset + 8..-1)].pack("H*")
name = "#{name[0, 97]}..." if name.length > 100
name = safe_encode.call(name)
description = safe_encode.call(description)

{ name:, description: }
rescue StandardError => e
puts "Error parsing spore cluster data: #{e.message}"
{ name: nil, description: nil }
end
end

def self.parse_spore_cell_data(hex_data)
Expand Down

0 comments on commit 4eba470

Please sign in to comment.