Skip to content

Commit

Permalink
feat: fill contract info task
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid committed Dec 4, 2024
1 parent d451f8e commit a2a9384
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 63 deletions.
4 changes: 2 additions & 2 deletions app/models/ckb_sync/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ def spore_cluster_code_hashes
if mode == CKB::MODE::MAINNET
[Settings.spore_cluster1_code_hash]
else
[Settings.spore_cluster1_code_hash, Settings.spore_cluster2_code_hash, Settings.spore_cluster3_code_hash]
[Settings.spore_cluster1_code_hash, Settings.spore_cluster2_code_hash]
end
end

def spore_cell_code_hashes
if mode == CKB::MODE::MAINNET
[Settings.spore_cell1_code_hash]
else
[Settings.spore_cell1_code_hash, Settings.spore_cell2_code_hash, Settings.spore_cell3_code_hash]
[Settings.spore_cell1_code_hash, Settings.spore_cell2_code_hash]
end
end

Expand Down
5 changes: 3 additions & 2 deletions app/workers/analyze_contract_from_cell_dependency_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class AnalyzeContractFromCellDependencyWorker
def perform
cell_deps_out_points_attrs = Set.new
contract_attrs = Set.new
cell_deps_attrs = []
cell_deps_attrs = Set.new

Check warning on line 7 in app/workers/analyze_contract_from_cell_dependency_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/analyze_contract_from_cell_dependency_worker.rb#L4-L7

Added lines #L4 - L7 were not covered by tests

CellDependency.where(contract_analyzed: false).where.not(block_number: nil).order("block_number desc").limit(1000).each do |cell_dep|
cell_deps_attrs << { contract_analyzed: true, ckb_transaction_id: cell_dep.ckb_transaction_id, contract_cell_id: cell_dep.contract_cell_id, dep_type: cell_dep.dep_type }

Check warning on line 10 in app/workers/analyze_contract_from_cell_dependency_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/analyze_contract_from_cell_dependency_worker.rb#L9-L10

Added lines #L9 - L10 were not covered by tests
Expand All @@ -16,14 +16,15 @@ def perform
type_script_hashes = Set.new
lock_script_hashes = Set.new

Check warning on line 17 in app/workers/analyze_contract_from_cell_dependency_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/analyze_contract_from_cell_dependency_worker.rb#L16-L17

Added lines #L16 - L17 were not covered by tests

cell_outputs = ckb_transaction.cell_outputs.includes(:type_script).to_a
cell_outputs = ckb_transaction.cell_outputs.includes(:type_script, :lock_script).to_a
cell_inputs = ckb_transaction.cell_inputs.includes(:previous_cell_output).map(&:previous_cell_output)
cell_inputs.each do |input|
lock_script_hashes << input.lock_script.code_hash
type_script_hashes << input.type_script.code_hash if input.type_script
end

Check warning on line 24 in app/workers/analyze_contract_from_cell_dependency_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/analyze_contract_from_cell_dependency_worker.rb#L19-L24

Added lines #L19 - L24 were not covered by tests

cell_outputs.each do |output|
lock_script_hashes << output.lock_script.code_hash
type_script_hashes << output.type_script.code_hash if output.type_script
end

Check warning on line 29 in app/workers/analyze_contract_from_cell_dependency_worker.rb

View check run for this annotation

Codecov / codecov/patch

app/workers/analyze_contract_from_cell_dependency_worker.rb#L26-L29

Added lines #L26 - L29 were not covered by tests

Expand Down
2 changes: 1 addition & 1 deletion app/workers/contract_statistic_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ContractStatisticWorker
def perform
h24_tx_ids = CkbTransaction.h24.pluck(:id)
ActiveRecord::Base.connection.execute("SET statement_timeout = 0")
Contract.find_each do |contract|
Contract.where(verified: true).find_each do |contract|
contract_cell_ids = CellDepsOutPoint.list_contract_cell_ids_by_contract([contract.id])
ckb_transactions_count = CellDependency.where(contract_cell_id: contract_cell_ids).select(:ckb_transaction_id).distinct.count
h24_ckb_transactions_count = CellDependency.where(contract_cell_id: contract_cell_ids, ckb_transaction_id: h24_tx_ids).select(:ckb_transaction_id).distinct.count
Expand Down
6 changes: 2 additions & 4 deletions config/settings.testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ nrc_721_factory_output_data_header: "0x24ff5a9ab8c38d195ce2b4ea75ca8987"
nrc_721_token_output_data_header: "0x0ddeff3e8ee03cbf6a2c6920d05c381e"

# spore nft code hash
spore_cluster1_code_hash: "0x7366a61534fa7c7e6225ecc0d828ea3b5366adec2b58206f2ee84995fe030075" # tag: v2 preview
spore_cluster1_code_hash: "0x0bbe768b519d8ea7b96d58f1182eb7e6ef96c541fbd9526975077ee09f049058" # tag: v2 preview
spore_cluster2_code_hash: "0x598d793defef36e2eeba54a9b45130e4ca92822e1d193671f490950c3b856080" # tag: v1 latest
spore_cluster3_code_hash: "0x0bbe768b519d8ea7b96d58f1182eb7e6ef96c541fbd9526975077ee09f049058" # tag: 0.2.2-beta.2
spore_cell1_code_hash: "0x5e063b4c0e7abeaa6a428df3b693521a3050934cf3b0ae97a800d1bc31449398" # tag: v2 preview
spore_cell1_code_hash: "0x685a60219309029d01310311dba953d67029170ca4848a4ff638e57002130a0d" # tag: v2 preview
spore_cell2_code_hash: "0xbbad126377d45f90a8ee120da988a2d7332c78ba8fd679aab478a19d6c133494" # tag: v1 latest
spore_cell3_code_hash: "0x685a60219309029d01310311dba953d67029170ca4848a4ff638e57002130a0d" # tag: 0.2.2-beta.2

#did cell
did_cell_code_hash: "0x0b1f412fbae26853ff7d082d422c2bdd9e2ff94ee8aaec11240a5b34cc6e890f"
Expand Down
Loading

0 comments on commit a2a9384

Please sign in to comment.