Skip to content

Commit

Permalink
fix: remove spore cluster and cell contract code_hash mapping (#1648)
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid authored Feb 23, 2024
1 parent e176fe4 commit e7127d9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
11 changes: 0 additions & 11 deletions app/models/ckb_sync/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,6 @@ def spore_cell_code_hashes
end
end

def spore_code_hash_mapping
if mode == CKB::MODE::MAINNET
{ Settings.spore_cell1_code_hash => Settings.spore_cluster1_code_hash }
else
{
Settings.spore_cell1_code_hash => Settings.spore_cluster1_code_hash,
Settings.spore_cell2_code_hash => Settings.spore_cluster2_code_hash,
}
end
end

def omiga_inscription_info_code_hash
Settings.omiga_inscription_info_code_hash
end
Expand Down
7 changes: 4 additions & 3 deletions app/models/ckb_sync/new_node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,10 @@ def build_udts!(local_block, outputs, outputs_data)
if cell_type == "spore_cell"
parsed_spore_cell = CkbUtils.parse_spore_cell_data(outputs_data[tx_index][index])
if parsed_spore_cell[:cluster_id].present?
cluster_code_hash = CkbSync::Api.instance.spore_code_hash_mapping[output.type.code_hash]
spore_cluster_type_ids = TypeScript.where(code_hash: cluster_code_hash, hash_type: "data1",
args: parsed_spore_cell[:cluster_id]).pluck(:id)
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)

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)
nft_token_attr[:full_name] = parsed_cluster_data[:name]
Expand Down
8 changes: 4 additions & 4 deletions app/workers/token_transfer_detect_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,18 @@ def find_or_create_m_nft_collection(_cell, type_script)
def find_or_create_spore_collection(_cell, type_script)
spore_cell = type_script.cell_outputs.order("id desc").first
parsed_spore_cell = CkbUtils.parse_spore_cell_data(spore_cell.data)
cluster_code_hash = CkbSync::Api.instance.spore_code_hash_mapping[type_script.code_hash]
if parsed_spore_cell[:cluster_id].nil?
spore_cluster_type = TypeScript.find_or_create_by(code_hash: cluster_code_hash, hash_type: "data1",
spore_cluster_type = TypeScript.find_or_create_by(code_hash: CkbSync::Api.instance.spore_cluster_code_hashes.first, hash_type: "data1",
args: parsed_spore_cell[:cluster_id])
TokenCollection.find_or_create_by(
standard: "spore",
sn: spore_cluster_type.script_hash,
description: "Only for no cluster spore cell",
)
else
spore_cluster_type_ids = TypeScript.where(code_hash: cluster_code_hash, hash_type: "data1",
args: parsed_spore_cell[:cluster_id]).pluck(:id)
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)
spore_cluster_cell = CellOutput.live.where(type_script_id: spore_cluster_type_ids).last
coll = TokenCollection.find_or_create_by(
standard: "spore",
Expand Down

0 comments on commit e7127d9

Please sign in to comment.