From b31de70ac2a8f3b0bcd381614dca810507a44580 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:31:35 +0800 Subject: [PATCH 1/9] chore(deps): bump actionpack from 7.0.8.1 to 7.0.8.4 (#1912) Bumps [actionpack](https://github.com/rails/rails) from 7.0.8.1 to 7.0.8.4. - [Release notes](https://github.com/rails/rails/releases) - [Changelog](https://github.com/rails/rails/blob/v7.1.3.4/actionpack/CHANGELOG.md) - [Commits](https://github.com/rails/rails/compare/v7.0.8.1...v7.0.8.4) --- updated-dependencies: - dependency-name: actionpack dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile.lock | 116 +++++++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index af3aa5e38..a4d79ce5f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,47 +10,47 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (7.0.8.1) - actionpack (= 7.0.8.1) - activesupport (= 7.0.8.1) + actioncable (7.0.8.4) + actionpack (= 7.0.8.4) + activesupport (= 7.0.8.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.8.1) - actionpack (= 7.0.8.1) - activejob (= 7.0.8.1) - activerecord (= 7.0.8.1) - activestorage (= 7.0.8.1) - activesupport (= 7.0.8.1) + actionmailbox (7.0.8.4) + actionpack (= 7.0.8.4) + activejob (= 7.0.8.4) + activerecord (= 7.0.8.4) + activestorage (= 7.0.8.4) + activesupport (= 7.0.8.4) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.8.1) - actionpack (= 7.0.8.1) - actionview (= 7.0.8.1) - activejob (= 7.0.8.1) - activesupport (= 7.0.8.1) + actionmailer (7.0.8.4) + actionpack (= 7.0.8.4) + actionview (= 7.0.8.4) + activejob (= 7.0.8.4) + activesupport (= 7.0.8.4) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.8.1) - actionview (= 7.0.8.1) - activesupport (= 7.0.8.1) + actionpack (7.0.8.4) + actionview (= 7.0.8.4) + activesupport (= 7.0.8.4) rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.8.1) - actionpack (= 7.0.8.1) - activerecord (= 7.0.8.1) - activestorage (= 7.0.8.1) - activesupport (= 7.0.8.1) + actiontext (7.0.8.4) + actionpack (= 7.0.8.4) + activerecord (= 7.0.8.4) + activestorage (= 7.0.8.4) + activesupport (= 7.0.8.4) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.8.1) - activesupport (= 7.0.8.1) + actionview (7.0.8.4) + activesupport (= 7.0.8.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -58,24 +58,24 @@ GEM active_interaction (5.3.0) activemodel (>= 5.2, < 8) activesupport (>= 5.2, < 8) - activejob (7.0.8.1) - activesupport (= 7.0.8.1) + activejob (7.0.8.4) + activesupport (= 7.0.8.4) globalid (>= 0.3.6) - activemodel (7.0.8.1) - activesupport (= 7.0.8.1) - activerecord (7.0.8.1) - activemodel (= 7.0.8.1) - activesupport (= 7.0.8.1) + activemodel (7.0.8.4) + activesupport (= 7.0.8.4) + activerecord (7.0.8.4) + activemodel (= 7.0.8.4) + activesupport (= 7.0.8.4) activerecord-import (1.4.1) activerecord (>= 4.2) - activestorage (7.0.8.1) - actionpack (= 7.0.8.1) - activejob (= 7.0.8.1) - activerecord (= 7.0.8.1) - activesupport (= 7.0.8.1) + activestorage (7.0.8.4) + actionpack (= 7.0.8.4) + activejob (= 7.0.8.4) + activerecord (= 7.0.8.4) + activesupport (= 7.0.8.4) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.8.1) + activesupport (7.0.8.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -138,7 +138,7 @@ GEM builder (3.2.4) byebug (11.1.3) coderay (1.1.3) - concurrent-ruby (1.2.3) + concurrent-ruby (1.3.1) config (4.1.0) deep_merge (~> 1.2, >= 1.2.1) dry-validation (~> 1.0, >= 1.0.0) @@ -241,7 +241,7 @@ GEM http-cookie (1.0.5) domain_name (~> 0.5) http-form_data (2.3.0) - i18n (1.14.4) + i18n (1.14.5) concurrent-ruby (~> 1.0) iniparse (1.5.0) io-event (1.1.6) @@ -284,8 +284,8 @@ GEM marcel (1.0.4) method_source (1.1.0) mini_mime (1.1.5) - mini_portile2 (2.8.6) - minitest (5.22.3) + mini_portile2 (2.8.7) + minitest (5.23.1) minitest-reporters (1.6.1) ansi builder @@ -347,7 +347,7 @@ GEM puma (6.4.2) nio4r (~> 2.0) raabro (1.4.0) - racc (1.7.3) + racc (1.8.0) rack (2.2.9) rack-attack (6.6.1) rack (>= 1.0, < 3) @@ -357,20 +357,20 @@ GEM rack (>= 2.0.0) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.8.1) - actioncable (= 7.0.8.1) - actionmailbox (= 7.0.8.1) - actionmailer (= 7.0.8.1) - actionpack (= 7.0.8.1) - actiontext (= 7.0.8.1) - actionview (= 7.0.8.1) - activejob (= 7.0.8.1) - activemodel (= 7.0.8.1) - activerecord (= 7.0.8.1) - activestorage (= 7.0.8.1) - activesupport (= 7.0.8.1) + rails (7.0.8.4) + actioncable (= 7.0.8.4) + actionmailbox (= 7.0.8.4) + actionmailer (= 7.0.8.4) + actionpack (= 7.0.8.4) + actiontext (= 7.0.8.4) + actionview (= 7.0.8.4) + activejob (= 7.0.8.4) + activemodel (= 7.0.8.4) + activerecord (= 7.0.8.4) + activestorage (= 7.0.8.4) + activesupport (= 7.0.8.4) bundler (>= 1.15.0) - railties (= 7.0.8.1) + railties (= 7.0.8.4) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -378,9 +378,9 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.8.1) - actionpack (= 7.0.8.1) - activesupport (= 7.0.8.1) + railties (7.0.8.4) + actionpack (= 7.0.8.4) + activesupport (= 7.0.8.4) method_source rake (>= 12.2) thor (~> 1.0) From c5f10cbb142863566af98dea0cc888eea96cc242 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 6 Jun 2024 14:02:38 +0800 Subject: [PATCH 2/9] feat: support xudt compatible contract (#1926) * feat: support xudt compatible contract Signed-off-by: Miles Zhang * fix: typo Signed-off-by: Miles Zhang --------- Signed-off-by: Miles Zhang --- app/jobs/revert_block_job.rb | 2 +- app/models/cell_input.rb | 2 +- app/models/cell_output.rb | 1 + app/models/ckb_sync/api.rb | 4 ++ .../ckb_sync/new_node_data_processor.rb | 37 ++++++++++--------- app/models/udt.rb | 2 +- app/models/udt_account.rb | 2 +- app/utils/ckb_utils.rb | 4 +- config/settings.mainnet.yml | 3 ++ 9 files changed, 35 insertions(+), 22 deletions(-) diff --git a/app/jobs/revert_block_job.rb b/app/jobs/revert_block_job.rb index 20ade0a4a..e21f3af1e 100644 --- a/app/jobs/revert_block_job.rb +++ b/app/jobs/revert_block_job.rb @@ -108,7 +108,7 @@ def recalculate_udt_accounts(udt_type_hashes, local_tip_block) when "sudt" amount = address.cell_outputs.live.udt.where(type_hash:).sum(:udt_amount) udt_account.update!(amount:) - when "xudt", "omiga_inscription" + when "xudt", "omiga_inscription", "xudt_compatible" amount = address.cell_outputs.live.where(cell_type: udt_account.udt_type).where(type_hash:).sum(:udt_amount) udt_account.update!(amount:) when "m_nft_token" diff --git a/app/models/cell_input.rb b/app/models/cell_input.rb index 02beb4cdb..24fe917b4 100644 --- a/app/models/cell_input.rb +++ b/app/models/cell_input.rb @@ -13,7 +13,7 @@ class CellInput < ApplicationRecord normal: 0, nervos_dao_deposit: 1, nervos_dao_withdrawing: 2, udt: 3, m_nft_issuer: 4, m_nft_class: 5, m_nft_token: 6, nrc_721_token: 7, nrc_721_factory: 8, cota_registry: 9, cota_regular: 10, spore_cluster: 11, spore_cell: 12, omiga_inscription_info: 13, omiga_inscription: 14, - xudt: 15, unique_cell: 16 + xudt: 15, unique_cell: 16, xudt_compatible: 17 } def output diff --git a/app/models/cell_output.rb b/app/models/cell_output.rb index 6c782b3b3..7654c185f 100644 --- a/app/models/cell_output.rb +++ b/app/models/cell_output.rb @@ -28,6 +28,7 @@ class CellOutput < ApplicationRecord omiga_inscription: 14, xudt: 15, unique_cell: 16, + xudt_compatible: 17, } belongs_to :ckb_transaction diff --git a/app/models/ckb_sync/api.rb b/app/models/ckb_sync/api.rb index 168c65002..9dd401b18 100644 --- a/app/models/ckb_sync/api.rb +++ b/app/models/ckb_sync/api.rb @@ -99,6 +99,10 @@ def xudt_code_hash Settings.xudt_code_hash end + def xudt_compatible_code_hash + Settings.xudt_compatible_code_hash + end + def unique_cell_code_hash Settings.unique_cell_code_hash end diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index c6b46c6f7..5ae92027a 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -419,7 +419,7 @@ def update_or_create_udt_accounts!(local_block) local_block.cell_outputs.select(:id, :address_id, :type_hash, :cell_type, :type_script_id).each do |udt_output| next unless udt_output.cell_type.in?(%w(udt m_nft_token nrc_721_token - spore_cell omiga_inscription xudt)) + spore_cell omiga_inscription xudt xudt_compatible)) address = Address.find(udt_output.address_id) udt_type = udt_type(udt_output.cell_type) @@ -450,7 +450,7 @@ def update_or_create_udt_accounts!(local_block) CellOutput.where(consumed_by_id: tx_id).select(:id, :address_id, :type_hash, :cell_type).each do |udt_output| next unless udt_output.cell_type.in?(%w(udt m_nft_token nrc_721_token - spore_cell omiga_inscription xudt)) + spore_cell omiga_inscription xudt xudt_compatible)) address = Address.find(udt_output.address_id) udt_type = udt_type(udt_output.cell_type) @@ -461,7 +461,7 @@ def update_or_create_udt_accounts!(local_block) :symbol, :decimal, :published, :code_hash, :type_hash, :created_at).take! if udt_account.present? case udt_type - when "sudt", "omiga_inscription", "xudt" + when "sudt", "omiga_inscription", "xudt", "xudt_compatible" udt_accounts_attributes << { id: udt_account.id, amount:, created_at: udt.created_at } when "m_nft_token" @@ -496,14 +496,8 @@ def udt_account_amount(udt_type, type_hash, address) case udt_type when "sudt" address.cell_outputs.live.udt.where(type_hash:).sum(:udt_amount) - when "xudt" - address.cell_outputs.live.xudt.where(type_hash:).sum(:udt_amount) - when "omiga_inscription" - address.cell_outputs.live.omiga_inscription.where(type_hash:).sum(:udt_amount) - when "m_nft_token" - address.cell_outputs.live.m_nft_token.where(type_hash:).sum(:udt_amount) - when "spore_cell" - address.cell_outputs.live.spore_cell.where(type_hash:).sum(:udt_amount) + when "xudt", "xudt_compatible", "omiga_inscription", "m_nft_token", "spore_cell" + address.cell_outputs.live.where(cell_type: udt_type).where(type_hash:).sum(:udt_amount) else 0 end @@ -598,7 +592,7 @@ def build_udts!(local_block, outputs, outputs_data) items.each_with_index do |output, index| cell_type = cell_type(output.type, outputs_data[tx_index][index]) next unless cell_type.in?(%w(udt m_nft_token nrc_721_token spore_cell - omiga_inscription_info omiga_inscription xudt)) + omiga_inscription_info omiga_inscription xudt xudt_compatible)) type_hash, parsed_udt_type = if cell_type == "omiga_inscription_info" @@ -679,7 +673,7 @@ def build_udts!(local_block, outputs, outputs_data) nft_token_attr[:symbol] = info[:symbol] nft_token_attr[:decimal] = info[:decimal] nft_token_attr[:published] = true - when "xudt" + when "xudt", "xudt_compatible" issuer_address = Address.find_by(lock_hash: output.type.args[0..65])&.address_hash items.each_with_index do |output, index| if output.type&.code_hash == CkbSync::Api.instance.unique_cell_code_hash @@ -1035,6 +1029,12 @@ def build_cell_inputs( contained_udt_ids[tx_index] << Udt.where(type_hash:, udt_type: "xudt").pick(:id) + when "xudt_compatible" + tags[tx_index] << "xudt_compatible" + udt_address_ids[tx_index] << address_id + contained_udt_ids[tx_index] << Udt.where(type_hash:, + udt_type: "xudt_compatible").pick(:id) + when "nrc_721_token" tags[tx_index] << "nrc_721_token" udt_address_ids[tx_index] << address_id @@ -1107,7 +1107,12 @@ def build_cell_outputs!( contained_udt_ids[tx_index] << Udt.where( type_hash: item.type.compute_hash, udt_type: "xudt", ).pick(:id) - + elsif attr[:cell_type] == "xudt_compatible" + tags[tx_index] << "xudt_compatible" + udt_address_ids[tx_index] << address_id + contained_udt_ids[tx_index] << Udt.where( + type_hash: item.type.compute_hash, udt_type: "xudt_compatible", + ).pick(:id) elsif attr[:cell_type].in?(%w(m_nft_token nrc_721_token spore_cell)) token_transfer_ckb_tx_ids << ckb_txs[tx_index]["id"] end @@ -1170,9 +1175,7 @@ def cell_output_attributes(output, address, ckb_transaction, local_block, cell_i def udt_amount(cell_type, output_data, type_script_args) case cell_type - when "udt" - CkbUtils.parse_udt_cell_data(output_data) - when "xudt" + when "udt", "xudt", "xudt_compatible" CkbUtils.parse_udt_cell_data(output_data) when "omiga_inscription" CkbUtils.parse_omiga_inscription_data(output_data)[:mint_limit] diff --git a/app/models/udt.rb b/app/models/udt.rb index 2d573cb31..3e4f86e59 100644 --- a/app/models/udt.rb +++ b/app/models/udt.rb @@ -7,7 +7,7 @@ class Udt < ApplicationRecord has_one :xudt_tag enum udt_type: { sudt: 0, m_nft_token: 1, nrc_721_token: 2, spore_cell: 3, - omiga_inscription: 4, xudt: 5 } + omiga_inscription: 4, xudt: 5, xudt_compatible: 6 } validates_presence_of :total_amount validates :decimal, diff --git a/app/models/udt_account.rb b/app/models/udt_account.rb index e0063676c..3fe6f0fbf 100644 --- a/app/models/udt_account.rb +++ b/app/models/udt_account.rb @@ -1,6 +1,6 @@ class UdtAccount < ApplicationRecord enum udt_type: { sudt: 0, m_nft_token: 1, nrc_721_token: 2, spore_cell: 3, - omiga_inscription: 4, xudt: 5 } + omiga_inscription: 4, xudt: 5, xudt_compatible: 6 } belongs_to :address belongs_to :udt diff --git a/app/utils/ckb_utils.rb b/app/utils/ckb_utils.rb index 25058e25f..84f52f984 100644 --- a/app/utils/ckb_utils.rb +++ b/app/utils/ckb_utils.rb @@ -447,6 +447,8 @@ def self.cell_type(type_script, output_data) "spore_cell" when CkbSync::Api.instance.omiga_inscription_info_code_hash "omiga_inscription_info" + when CkbSync::Api.instance.xudt_compatible_code_hash + "xudt_compatible" when CkbSync::Api.instance.xudt_code_hash Rails.cache.fetch(type_script.compute_hash) do if OmigaInscriptionInfo.exists?(udt_hash: type_script.compute_hash) @@ -455,7 +457,7 @@ def self.cell_type(type_script, output_data) "xudt" end end - when Settings.unique_cell_code_hash + when CkbSync::Api.instance.unique_cell_code_hash "unique_cell" else if is_nrc_721_token_cell?(output_data) diff --git a/config/settings.mainnet.yml b/config/settings.mainnet.yml index 1130bfd3f..27576bacd 100644 --- a/config/settings.mainnet.yml +++ b/config/settings.mainnet.yml @@ -31,6 +31,9 @@ omiga_inscription_code_hash: "0x7490970e6af9b9fe63fc19fc523a12b2ec69027e6ae484ed # xudt xudt_code_hash: "0x50bd8d6680b8b9cf98b73f3c08faf8b2a21914311954118ad6609be6e78a1b95" +# xudt compatible +xudt_compatible_code_hash: "0x74f8fd146cca83d5fa2acd8a2b0bc7f0408a38b79a173c1e8ca1fbdfc95122ff" + unique_cell_code_hash: "0x2c8c11c985da60b0a330c61a85507416d6382c130ba67f0c47ab071e00aec628" # hash length of an attribute(especially which comes from bytea column), From c12c47494caaa6ded16ae4471150f11f5ebfd601 Mon Sep 17 00:00:00 2001 From: Rabbit Date: Thu, 6 Jun 2024 17:03:57 +0800 Subject: [PATCH 3/9] fix: update bitcoin transction created_at (#1928) * fix: update bitcoin transction created_at * fix: bitcoin annotations --- app/jobs/import_btc_time_cell_job.rb | 6 ++++-- app/jobs/import_rgbpp_cell_job.rb | 10 +++++++--- app/workers/bitcoin_transaction_detect_worker.rb | 7 ++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/jobs/import_btc_time_cell_job.rb b/app/jobs/import_btc_time_cell_job.rb index 5025b8875..ffbc49533 100644 --- a/app/jobs/import_btc_time_cell_job.rb +++ b/app/jobs/import_btc_time_cell_job.rb @@ -17,7 +17,7 @@ def perform(cell_id) raw_tx = fetch_raw_transaction(txid) return unless raw_tx - tx = build_transaction!(raw_tx) + tx = build_transaction!(raw_tx, cell_output.ckb_transaction) # build transfer BitcoinTransfer.create_with( bitcoin_transaction_id: tx.id, @@ -29,16 +29,18 @@ def perform(cell_id) end end - def build_transaction!(raw_tx) + def build_transaction!(raw_tx, ckb_tx) tx = BitcoinTransaction.find_by(txid: raw_tx["txid"]) return tx if tx + created_at = Time.at((ckb_tx.block_timestamp / 1000).to_i).in_time_zone BitcoinTransaction.create!( txid: raw_tx["txid"], tx_hash: raw_tx["hash"], time: raw_tx["time"], block_hash: raw_tx["blockhash"], block_height: 0, + created_at:, ) end diff --git a/app/jobs/import_rgbpp_cell_job.rb b/app/jobs/import_rgbpp_cell_job.rb index 386ce29d6..9cfcb99c5 100644 --- a/app/jobs/import_rgbpp_cell_job.rb +++ b/app/jobs/import_rgbpp_cell_job.rb @@ -19,7 +19,7 @@ def perform(cell_id) raw_tx = fetch_raw_transaction(txid) return unless raw_tx - tx = build_transaction!(raw_tx) + tx = build_transaction!(raw_tx, cell_output.ckb_transaction) # build op_returns vout_attributes = [] op_returns = build_op_returns!(raw_tx, tx, cell_output.ckb_transaction) @@ -47,7 +47,7 @@ def perform(cell_id) Rails.logger.error(e.message) end - def build_transaction!(raw_tx) + def build_transaction!(raw_tx, ckb_tx) tx = BitcoinTransaction.find_by(txid: raw_tx["txid"]) return tx if tx @@ -55,12 +55,15 @@ def build_transaction!(raw_tx) if raw_tx["blockhash"].present? block_header = rpc.getblockheader(raw_tx["blockhash"]) end + + created_at = Time.at((ckb_tx.block_timestamp / 1000).to_i).in_time_zone BitcoinTransaction.create!( txid: raw_tx["txid"], tx_hash: raw_tx["hash"], time: raw_tx["time"], block_hash: raw_tx["blockhash"], block_height: block_header&.dig("result", "height") || 0, + created_at:, ) end @@ -136,7 +139,8 @@ def build_vin!(cell_id, tx) end def build_address!(address_hash, cell_output) - bitcoin_address = BitcoinAddress.find_or_create_by!(address_hash:) + created_at = Time.at((cell_output.block_timestamp / 1000).to_i).in_time_zone + bitcoin_address = BitcoinAddress.create_with(created_at:).find_or_create_by!(address_hash:) BitcoinAddressMapping. create_with(bitcoin_address_id: bitcoin_address.id). find_or_create_by!(ckb_address_id: cell_output.address_id) diff --git a/app/workers/bitcoin_transaction_detect_worker.rb b/app/workers/bitcoin_transaction_detect_worker.rb index 768f7a952..b4f861a9c 100644 --- a/app/workers/bitcoin_transaction_detect_worker.rb +++ b/app/workers/bitcoin_transaction_detect_worker.rb @@ -92,11 +92,12 @@ def build_bitcoin_annotations! annotations = [] @block.ckb_transactions.each do |transaction| - next unless BitcoinTransfer.exists?(ckb_transaction_id: transaction.id) - leap_direction, transfer_step = annotation_workflow_attributes(transaction) tags = annotation_tags(transaction) - annotations << { ckb_transaction_id: transaction.id, leap_direction:, transfer_step:, tags: } + + if tags.present? + annotations << { ckb_transaction_id: transaction.id, leap_direction:, transfer_step:, tags: } + end end BitcoinAnnotation.upsert_all(annotations, unique_by: [:ckb_transaction_id]) if annotations.present? From 5aadf7b496fc5bd2d97438bdc3c82caec1945d98 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 6 Jun 2024 18:43:40 +0800 Subject: [PATCH 4/9] chore: add testnet xudt compatible contract (#1931) * chore: add testnet xudt compatible contract Signed-off-by: Miles Zhang * feat: support xudt_compatible api Signed-off-by: Miles Zhang --------- Signed-off-by: Miles Zhang --- app/controllers/api/v1/xudts_controller.rb | 6 +++++- config/settings.mainnet.yml | 2 +- config/settings.testnet.yml | 4 +++- test/controllers/api/v1/xudts_controller_test.rb | 10 ++++++++++ test/factories/udt.rb | 9 +++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/xudts_controller.rb b/app/controllers/api/v1/xudts_controller.rb index 707a1e02c..7b0e7c601 100644 --- a/app/controllers/api/v1/xudts_controller.rb +++ b/app/controllers/api/v1/xudts_controller.rb @@ -7,7 +7,7 @@ class XudtsController < ApplicationController before_action :validate_pagination_params, :pagination_params, only: :index def index - scope = Udt.xudt.includes(:xudt_tag) + scope = Udt.includes(:xudt_tag).where(udt_type: xudt_type_params) if params[:symbol].present? scope = scope.where("LOWER(symbol) = ?", params[:symbol].downcase) @@ -104,6 +104,10 @@ def parse_tags tags = params[:tags].split(",") tags & XudtTag::VALID_TAGS end + + def xudt_type_params + params[:type].blank? ? "xudt" : "xudt_compatible" + end end end end diff --git a/config/settings.mainnet.yml b/config/settings.mainnet.yml index 27576bacd..596b2c769 100644 --- a/config/settings.mainnet.yml +++ b/config/settings.mainnet.yml @@ -32,7 +32,7 @@ omiga_inscription_code_hash: "0x7490970e6af9b9fe63fc19fc523a12b2ec69027e6ae484ed xudt_code_hash: "0x50bd8d6680b8b9cf98b73f3c08faf8b2a21914311954118ad6609be6e78a1b95" # xudt compatible -xudt_compatible_code_hash: "0x74f8fd146cca83d5fa2acd8a2b0bc7f0408a38b79a173c1e8ca1fbdfc95122ff" +xudt_compatible_code_hash: "0x092c2c4a26ea475a8e860c29cf00502103add677705e2ccd8d6fe5af3caa5ae3" unique_cell_code_hash: "0x2c8c11c985da60b0a330c61a85507416d6382c130ba67f0c47ab071e00aec628" diff --git a/config/settings.testnet.yml b/config/settings.testnet.yml index 251898c99..8ea7fe3d8 100644 --- a/config/settings.testnet.yml +++ b/config/settings.testnet.yml @@ -35,6 +35,9 @@ omiga_inscription_code_hash: "0x3a241ceceede72a5f55c8fb985652690f09a517d6c9070f0 xudt_code_hash: "0x25c29dc317811a6f6f3985a7a9ebc4838bd388d19d0feeecf0bcd60f6c0975bb" unique_cell_code_hash: "0x8e341bcfec6393dcd41e635733ff2dca00a6af546949f70c57a706c0f344df8b" +# xudt compatible +xudt_compatible_code_hash: "0x98701eaf939113606a8a70013fd2e8f27b8f1e234acdc329f3d71f9e9d3d3233" + # hash length of an attribute(especially which comes from bytea column), # e.g. Block.uncle_block_hashes: "0x587f354162afd133b4a4f7a4b621d11e043c3c08b0af2801f1686b5403b14953", which has a length of 66 ( 2 + 64) default_hash_length: "64" @@ -82,4 +85,3 @@ proposal_window: 10 rgbpp_code_hash: "0x61ca7a4796a4eb19ca4f0d065cb9b10ddcf002f10f7cbb810c706cb6bb5c3248" # btc time code hash btc_time_code_hash: "0x00cdf8fab0f8ac638758ebf5ea5e4052b1d71e8a77b9f43139718621f6849326" - diff --git a/test/controllers/api/v1/xudts_controller_test.rb b/test/controllers/api/v1/xudts_controller_test.rb index 7aea9c8fe..9563208eb 100644 --- a/test/controllers/api/v1/xudts_controller_test.rb +++ b/test/controllers/api/v1/xudts_controller_test.rb @@ -19,6 +19,16 @@ class XudtsControllerTest < ActionDispatch::IntegrationTest assert_response :success end + test "should get success code when call xudt_compatible index " do + create(:udt, :xudt_compatible, published: true) + + valid_get api_v1_xudts_url, params: {type: "xudt_compatible"} + + assert_response :success + assert_equal 1, json["data"].length + end + + test "filter xudt by symbol and tags" do udt = create(:udt, :xudt, symbol: "CKBB") create(:xudt_tag, udt:, tags: ["duplicate", "layer-1-asset", "supply-limited"]) diff --git a/test/factories/udt.rb b/test/factories/udt.rb index 350a65486..094165fdc 100644 --- a/test/factories/udt.rb +++ b/test/factories/udt.rb @@ -63,5 +63,14 @@ symbol { "BBQ" } decimal { 8 } end + + trait :xudt_compatible do + udt_type { "xudt_compatible" } + published { true } + full_name { "XUDTCompatible" } + symbol { "XC" } + decimal { 8 } + end + end end From 4531ac92c00d8190fd5f20b0fd49266195f94513 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 6 Jun 2024 19:50:49 +0800 Subject: [PATCH 5/9] feat: address udt_accounts match xudt_compatible (#1934) * feat: address udt_accounts match xudt_compatible Signed-off-by: Miles Zhang * feat: extra_info add xudt_compatible info Signed-off-by: Miles Zhang * feat: cell_output extra_info add xudt_compatible type Signed-off-by: Miles Zhang --------- Signed-off-by: Miles Zhang --- app/models/concerns/cell_outputs/extra_info.rb | 2 +- app/serializers/address_serializer.rb | 2 +- app/serializers/cell_output_serializer.rb | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/cell_outputs/extra_info.rb b/app/models/concerns/cell_outputs/extra_info.rb index 064129bf5..e2e5b544b 100644 --- a/app/models/concerns/cell_outputs/extra_info.rb +++ b/app/models/concerns/cell_outputs/extra_info.rb @@ -5,7 +5,7 @@ module ExtraInfo extend ActiveSupport::Concern included do def udt_info - return unless cell_type.in?(%w(udt xudt)) + return unless cell_type.in?(%w(udt xudt xudt_compatible)) udt_info = Udt.find_by(type_hash:, published: true) CkbUtils.hash_value_to_s( diff --git a/app/serializers/address_serializer.rb b/app/serializers/address_serializer.rb index 7c848e719..2c573932d 100644 --- a/app/serializers/address_serializer.rb +++ b/app/serializers/address_serializer.rb @@ -50,7 +50,7 @@ class AddressSerializer uan: udt_account.uan, udt_type_script: udt_account.udt&.type_script, } - elsif udt_account.udt_type == "xudt" + elsif udt_account.udt_type.in?(["xudt", "xudt_compatible"]) { symbol: udt_account.symbol, decimal: udt_account.decimal.to_s, diff --git a/app/serializers/cell_output_serializer.rb b/app/serializers/cell_output_serializer.rb index 483c82fdb..70c0e2238 100644 --- a/app/serializers/cell_output_serializer.rb +++ b/app/serializers/cell_output_serializer.rb @@ -35,6 +35,8 @@ class CellOutputSerializer object.udt_info.merge!(type: "udt") when "xudt" object.udt_info.merge!(type: "xudt") + when "xudt_compatible" + object.udt_info.merge!(type: "xudt_compatible") when "cota_registry" object.cota_registry_info.merge!(type: "cota") when "cota_regular" From 8fef5b1155b06ef8728359f68839119537ac7015 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Fri, 7 Jun 2024 13:49:09 +0800 Subject: [PATCH 6/9] fix: tag for xudt with no symbol (#1937) * fix: tag for xudt with no symbol Signed-off-by: Miles Zhang * fix: not to upsert_all empty array Signed-off-by: Miles Zhang --------- Signed-off-by: Miles Zhang --- app/workers/xudt_tag_worker.rb | 20 ++++++++++++-------- test/workers/xudt_tag_worker_test.rb | 8 ++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/workers/xudt_tag_worker.rb b/app/workers/xudt_tag_worker.rb index 0a08aa256..200848ecf 100644 --- a/app/workers/xudt_tag_worker.rb +++ b/app/workers/xudt_tag_worker.rb @@ -3,17 +3,21 @@ class XudtTagWorker def perform udts = Udt.published_xudt.left_joins(:xudt_tag).where(xudt_tag: { id: nil }).limit(100) - attrs = - udts.map do |udt| - tags = mark_tags(udt) - { udt_id: udt.id, udt_type_hash: udt.type_hash, tags: } - end - - XudtTag.upsert_all(attrs, unique_by: :udt_id, on_duplicate: :update, update_only: :tags) + if !udts.empty? + attrs = + udts.map do |udt| + tags = mark_tags(udt) + { udt_id: udt.id, udt_type_hash: udt.type_hash, tags: } + end + + XudtTag.upsert_all(attrs, unique_by: :udt_id, on_duplicate: :update, update_only: :tags) + end end def mark_tags(udt) - if invalid_char?(udt.symbol) + if udt.symbol.blank? + ["unnamed"] + elsif invalid_char?(udt.symbol) ["invalid"] elsif invisible_char?(udt.symbol) ["suspicious"] diff --git a/test/workers/xudt_tag_worker_test.rb b/test/workers/xudt_tag_worker_test.rb index a0705e9f0..6b2384b58 100644 --- a/test/workers/xudt_tag_worker_test.rb +++ b/test/workers/xudt_tag_worker_test.rb @@ -5,6 +5,14 @@ class XudtTagWorkerTest < ActiveJob::TestCase @address = create(:address, address_hash: "ckb1qz7xc452rgxs5z0ks3xun46dmdp58sepg0ljtae8ck0d7nah945nvqgqqqqqqx3l3v4") end + test "when xudt with no symbol" do + create(:udt, :xudt, symbol: nil) + assert_changes -> { XudtTag.count }, from: 0, to: 1 do + XudtTagWorker.new.perform + end + assert_equal ["unnamed"], XudtTag.last.tags + end + test "insert to xudt_tags successfully" do udt = create(:udt, :xudt) create(:xudt_tag, udt_id: udt.id, udt_type_hash: udt.type_hash, tags: ["out-of-length-range"]) From 5246ca113f8d2ff96891694cafe64268c9258508 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Fri, 7 Jun 2024 13:49:16 +0800 Subject: [PATCH 7/9] fix: display cells support xudt compatible cell (#1938) Signed-off-by: Miles Zhang --- app/models/concerns/ckb_transactions/display_cells.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/concerns/ckb_transactions/display_cells.rb b/app/models/concerns/ckb_transactions/display_cells.rb index a12b0cc4e..5f154c2ee 100644 --- a/app/models/concerns/ckb_transactions/display_cells.rb +++ b/app/models/concerns/ckb_transactions/display_cells.rb @@ -108,6 +108,9 @@ def normal_tx_display_inputs(cell_inputs_for_display) if previous_cell_output.xudt? display_input.merge!(attributes_for_xudt_cell(previous_cell_output)) end + if previous_cell_output.xudt_compatible? + display_input.merge!(attributes_for_xudt_compatible_cell(previous_cell_output)) + end if previous_cell_output.cell_type.in?(%w(m_nft_issuer m_nft_class m_nft_token)) display_input.merge!(attributes_for_m_nft_cell(previous_cell_output)) end @@ -142,6 +145,7 @@ def normal_tx_display_outputs(cell_outputs_for_display) display_output.merge!(attributes_for_udt_cell(output)) if output.udt? display_output.merge!(attributes_for_xudt_cell(output)) if output.xudt? + display_output.merge!(attributes_for_xudt_compatible_cell(output)) if output.xudt_compatible? display_output.merge!(attributes_for_cota_registry_cell(output)) if output.cota_registry? display_output.merge!(attributes_for_cota_regular_cell(output)) if output.cota_regular? if output.cell_type.in?(%w(m_nft_issuer m_nft_class m_nft_token)) @@ -228,6 +232,11 @@ def attributes_for_xudt_cell(xudt_cell) { xudt_info: info, extra_info: info } end + def attributes_for_xudt_compatible_cell(xudt_compatible_cell) + info = CkbUtils.hash_value_to_s(xudt_compatible_cell.udt_info) + { xudt_compatible_info: info, extra_info: info } + end + def hex_since(int_since_value) "0x#{int_since_value.to_s(16).rjust(16, '0')}" end From 3651865915567f61ec7ecb982e616d74be61416f Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Fri, 7 Jun 2024 16:42:02 +0800 Subject: [PATCH 8/9] feat: xudt_compatible needs to tag (#1940) * feat: xudt_compatible needs to tag Signed-off-by: Miles Zhang * test: add test to xudt tags worker Signed-off-by: Miles Zhang * feat: first_xudt tag's logic combine xudt and xudt_compatible Signed-off-by: Miles Zhang * feat: deatail api support xudt_compatible Signed-off-by: Miles Zhang * feat: xudt api returns xudt_compatible either Signed-off-by: Miles Zhang --------- Signed-off-by: Miles Zhang --- app/controllers/api/v1/xudts_controller.rb | 2 +- app/controllers/concerns/cell_data_comparator.rb | 2 +- app/models/udt.rb | 2 +- app/models/xudt_tag.rb | 2 +- app/serializers/udt_serializer.rb | 2 +- app/utils/ckb_utils.rb | 2 +- app/workers/xudt_tag_worker.rb | 2 +- test/controllers/api/v1/xudts_controller_test.rb | 4 ++-- test/workers/xudt_tag_worker_test.rb | 8 ++++++++ 9 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/v1/xudts_controller.rb b/app/controllers/api/v1/xudts_controller.rb index 7b0e7c601..ef8b7d643 100644 --- a/app/controllers/api/v1/xudts_controller.rb +++ b/app/controllers/api/v1/xudts_controller.rb @@ -106,7 +106,7 @@ def parse_tags end def xudt_type_params - params[:type].blank? ? "xudt" : "xudt_compatible" + params[:type].blank? ? ["xudt", "xudt_compatible"] : "xudt_compatible" end end end diff --git a/app/controllers/concerns/cell_data_comparator.rb b/app/controllers/concerns/cell_data_comparator.rb index 3551de378..43512e885 100644 --- a/app/controllers/concerns/cell_data_comparator.rb +++ b/app/controllers/concerns/cell_data_comparator.rb @@ -59,7 +59,7 @@ def diff_udt_cells(inputs, outputs) h[k][:amount] += c.udt_amount.to_f } - cell_types = %w(udt omiga_inscription xudt) + cell_types = %w(udt omiga_inscription xudt xudt_compatible) inputs = inputs.where(cell_type: cell_types).each_with_object({}) { |c, h| process_udt.call(c, h) } outputs = outputs.where(cell_type: cell_types).each_with_object({}) { |c, h| process_udt.call(c, h) } diff --git a/app/models/udt.rb b/app/models/udt.rb index 3e4f86e59..e1361882e 100644 --- a/app/models/udt.rb +++ b/app/models/udt.rb @@ -19,7 +19,7 @@ class Udt < ApplicationRecord scope :query_by_name_or_symbl, ->(search) { where("lower(full_name) LIKE ? or lower(symbol) LIKE ?", "%#{search}%", "%#{search}%") } - scope :published_xudt, -> { where(udt_type: :xudt, published: true) } + scope :published_xudt, -> { where(udt_type: %i[xudt xudt_compatible], published: true) } attribute :code_hash, :ckb_hash diff --git a/app/models/xudt_tag.rb b/app/models/xudt_tag.rb index df13fd6d3..3ec66726e 100644 --- a/app/models/xudt_tag.rb +++ b/app/models/xudt_tag.rb @@ -1,7 +1,7 @@ class XudtTag < ApplicationRecord belongs_to :udt - VALID_TAGS = ["invalid", "suspicious", "out-of-length-range", "rgbpp-compatible", "layer-1-asset", "supply-limited", "duplicate", "layer-2-asset", "supply-unlimited"] + VALID_TAGS = ["unnamed", "invalid", "suspicious", "out-of-length-range", "rgbpp-compatible", "layer-1-asset", "supply-limited", "duplicate", "layer-2-asset", "supply-unlimited"] end # == Schema Information diff --git a/app/serializers/udt_serializer.rb b/app/serializers/udt_serializer.rb index 1b80662ea..f3cdfea82 100644 --- a/app/serializers/udt_serializer.rb +++ b/app/serializers/udt_serializer.rb @@ -69,7 +69,7 @@ class UdtSerializer end attribute :xudt_tags, if: Proc.new { |record, _params| - record.udt_type == "xudt" && record.published + record.udt_type.in?(["xudt", "xudt_compatible"]) && record.published } do |object| object.xudt_tag&.tags end diff --git a/app/utils/ckb_utils.rb b/app/utils/ckb_utils.rb index 84f52f984..3445eda37 100644 --- a/app/utils/ckb_utils.rb +++ b/app/utils/ckb_utils.rb @@ -407,7 +407,7 @@ def self.cell_type(type_script, output_data) CkbSync::Api.instance.issuer_script_code_hash, CkbSync::Api.instance.token_class_script_code_hash, CkbSync::Api.instance.token_script_code_hash, CkbSync::Api.instance.cota_registry_code_hash, CkbSync::Api.instance.cota_regular_code_hash, CkbSync::Api.instance.omiga_inscription_info_code_hash, - CkbSync::Api.instance.xudt_code_hash, CkbSync::Api.instance.unique_cell_code_hash + CkbSync::Api.instance.xudt_code_hash, CkbSync::Api.instance.unique_cell_code_hash, CkbSync::Api.instance.xudt_compatible_code_hash ].include?(type_script&.code_hash) && type_script&.hash_type == "type") || is_nrc_721_token_cell?(output_data) || is_nrc_721_factory_cell?(output_data) || diff --git a/app/workers/xudt_tag_worker.rb b/app/workers/xudt_tag_worker.rb index 200848ecf..ea40d46d2 100644 --- a/app/workers/xudt_tag_worker.rb +++ b/app/workers/xudt_tag_worker.rb @@ -49,7 +49,7 @@ def out_of_length?(symbol) end def first_xudt?(symbol, block_timestamp) - !Udt.xudt.where("LOWER(symbol) = ?", symbol.downcase).where("block_timestamp < ?", block_timestamp).exists? + !Udt.published_xudt.where("LOWER(symbol) = ?", symbol.downcase).where("block_timestamp < ?", block_timestamp).exists? end def rgbpp_lock?(issuer_address) diff --git a/test/controllers/api/v1/xudts_controller_test.rb b/test/controllers/api/v1/xudts_controller_test.rb index 9563208eb..1e25bd7eb 100644 --- a/test/controllers/api/v1/xudts_controller_test.rb +++ b/test/controllers/api/v1/xudts_controller_test.rb @@ -21,14 +21,14 @@ class XudtsControllerTest < ActionDispatch::IntegrationTest test "should get success code when call xudt_compatible index " do create(:udt, :xudt_compatible, published: true) + create(:udt, :xudt, published: true) - valid_get api_v1_xudts_url, params: {type: "xudt_compatible"} + valid_get api_v1_xudts_url, params: { type: "xudt_compatible" } assert_response :success assert_equal 1, json["data"].length end - test "filter xudt by symbol and tags" do udt = create(:udt, :xudt, symbol: "CKBB") create(:xudt_tag, udt:, tags: ["duplicate", "layer-1-asset", "supply-limited"]) diff --git a/test/workers/xudt_tag_worker_test.rb b/test/workers/xudt_tag_worker_test.rb index 6b2384b58..f06bb5488 100644 --- a/test/workers/xudt_tag_worker_test.rb +++ b/test/workers/xudt_tag_worker_test.rb @@ -5,6 +5,14 @@ class XudtTagWorkerTest < ActiveJob::TestCase @address = create(:address, address_hash: "ckb1qz7xc452rgxs5z0ks3xun46dmdp58sepg0ljtae8ck0d7nah945nvqgqqqqqqx3l3v4") end + test "add tag to xudt compatible" do + create(:udt, :xudt_compatible, symbol: nil) + assert_changes -> { XudtTag.count }, from: 0, to: 1 do + XudtTagWorker.new.perform + end + assert_equal ["unnamed"], XudtTag.last.tags + end + test "when xudt with no symbol" do create(:udt, :xudt, symbol: nil) assert_changes -> { XudtTag.count }, from: 0, to: 1 do From ab327396c26bd772ae8d8b3d85e5a13fe7dd5dac Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Fri, 7 Jun 2024 17:25:44 +0800 Subject: [PATCH 9/9] feat: issuer address may not exist for xudt compatible test data (#1944) Signed-off-by: Miles Zhang --- app/workers/xudt_tag_worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/workers/xudt_tag_worker.rb b/app/workers/xudt_tag_worker.rb index ea40d46d2..55851b990 100644 --- a/app/workers/xudt_tag_worker.rb +++ b/app/workers/xudt_tag_worker.rb @@ -53,7 +53,7 @@ def first_xudt?(symbol, block_timestamp) end def rgbpp_lock?(issuer_address) - CkbUtils.parse_address(issuer_address).script.code_hash == Settings.rgbpp_code_hash + issuer_address.present? && CkbUtils.parse_address(issuer_address).script.code_hash == Settings.rgbpp_code_hash end ## TODO: current no this condition