Skip to content

Commit

Permalink
Merge pull request #1650 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
Deploy to testnet
  • Loading branch information
zmcNotafraid authored Feb 27, 2024
2 parents a8f949e + 6d3bf24 commit c08451c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
6 changes: 4 additions & 2 deletions app/models/ckb_sync/new_node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ def build_udts!(local_block, outputs, outputs_data)
if parsed_spore_cell[:cluster_id].present?
binary_hashes = CkbUtils.hexes_to_bins_sql(CkbSync::Api.instance.spore_cluster_code_hashes)
spore_cluster_type_ids = TypeScript.where("code_hash IN (#{binary_hashes})").where(hash_type: "data1",
args: parsed_spore_cell[:cluster_id]).pluck(:id)
args: parsed_spore_cell[:cluster_id]).pluck(:id)

spore_cluster_cell = CellOutput.live.where(type_script_id: spore_cluster_type_ids).last
parsed_cluster_data = CkbUtils.parse_spore_cluster_data(spore_cluster_cell.data)
Expand Down Expand Up @@ -712,7 +712,9 @@ def build_udts!(local_block, outputs, outputs_data)
nft_token_attr[:full_name] = info[:name]
nft_token_attr[:symbol] = info[:symbol]
nft_token_attr[:decimal] = info[:decimal]
nft_token_attr[:published] = true
unless Udt.where(symbol: info[:symbol].strip, udt_type: :omiga_inscription).exists?
nft_token_attr[:published] = true
end
end
# fill issuer_address after publish the token
udts_attributes << {
Expand Down
39 changes: 22 additions & 17 deletions app/models/token_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TokenCollection < ApplicationRecord
validates :sn, uniqueness: true, presence: true

def self.find_by_sn(sn)
c = find_by sn: sn
c = find_by(sn:)
return c if c

c = find_by_type_hash(sn)
Expand All @@ -24,18 +24,19 @@ def self.find_by_type_hash(type_hash)
TokenCollection.find_by! type_script_id: ts.id
end

def as_json(options = {})
def as_json(_options = {})
{
id: id,
standard: standard,
name: name,
description: description,
icon_url: icon_url,
id:,
standard:,
name:,
description:,
icon_url:,
creator: creator&.address_hash || "",
items_count: items_count,
holders_count: holders_count,
h24_ckb_transactions_count: h24_ckb_transactions_count,
type_script: type_script&.as_json
items_count:,
holders_count:,
h24_ckb_transactions_count:,
type_script: type_script&.as_json,
sn:,
}
end

Expand Down Expand Up @@ -75,12 +76,12 @@ def update_udt_info
Udt.where(
code_hash: ts.code_hash,
hash_type: ts.hash_type,
args: ts.args
args: ts.args,
).update_all(
symbol: symbol,
symbol:,
full_name: name,
description: description,
icon_file: icon_url
description:,
icon_file: icon_url,
)
end
end
Expand All @@ -94,7 +95,11 @@ def self.update_cell
# removed the wrong token collections
def self.remove_corrupted
where(standard: "nrc721").where(type_script_id: nil).or(where(creator_id: nil)).find_each do |tc|
tc.update_info rescue nil
begin
tc.update_info
rescue StandardError
nil
end

if tc.cell.blank?
tc.destroy
Expand All @@ -113,7 +118,7 @@ def self.fix_sn

begin
tc2.items.update_all collection_id: tc.id
rescue
rescue StandardError
puts "destroy all items"
end
tc2.destroy!
Expand Down
1 change: 1 addition & 0 deletions app/workers/token_transfer_detect_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def find_or_create_spore_collection(_cell, type_script)
args: parsed_spore_cell[:cluster_id])
TokenCollection.find_or_create_by(
standard: "spore",
type_script_id: spore_cluster_type.id,
sn: spore_cluster_type.script_hash,
description: "Only for no cluster spore cell",
)
Expand Down
22 changes: 12 additions & 10 deletions test/models/ckb_sync/node_data_processor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1034,15 +1034,15 @@ class NodeDataProcessorTest < ActiveSupport::TestCase
Address.find_or_create_address(lock1, node_block.header.timestamp)
Address.find_or_create_address(lock2, node_block.header.timestamp)
300.times do |i|
if i % 2 == 0
node_block.transactions.first.outputs << CKB::Types::Output.new(
capacity: 30000 * 10**8, lock: lock1,
)
else
node_block.transactions.first.outputs << CKB::Types::Output.new(
capacity: 40000 * 10**8, lock: lock2,
)
end
node_block.transactions.first.outputs << if i % 2 == 0
CKB::Types::Output.new(
capacity: 30000 * 10**8, lock: lock1,
)
else
CKB::Types::Output.new(
capacity: 40000 * 10**8, lock: lock2,
)
end
node_block.transactions.first.outputs_data << "0x"
end
new_local_block = node_data_processor.process_block(node_block)
Expand Down Expand Up @@ -4043,8 +4043,10 @@ class NodeDataProcessorTest < ActiveSupport::TestCase
assert_equal info.mint_limit, 0.1e12
assert_equal info.mint_status, "minting"
assert_equal info.udt_id, Udt.first.id
udt = Udt.first
assert_equal "0x5fa66c8d5f43914f85d3083e0529931883a5b0a14282f891201069f1b5067908",
Udt.first.type_hash
udt.type_hash
assert_equal true, udt.published
end
end

Expand Down

0 comments on commit c08451c

Please sign in to comment.