From 1faf918f24fc904983635cf71af857acf956616a Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 28 Nov 2024 19:08:43 +0900 Subject: [PATCH] feat: identify stablepp_pool cell (#2298) * feat: identify stablepp_pool cell Signed-off-by: Miles Zhang * fix: block rollback test Signed-off-by: Miles Zhang --------- Signed-off-by: Miles Zhang --- app/models/block.rb | 11 +++++++++-- app/models/cell_input.rb | 2 +- app/models/cell_output.rb | 1 + app/models/ckb_sync/api.rb | 4 ++++ app/models/ckb_transaction.rb | 16 ++++++++-------- app/serializers/cell_output_serializer.rb | 2 ++ app/utils/ckb_utils.rb | 5 ++++- config/settings.mainnet.yml | 3 +++ test/models/ckb_transaction_test.rb | 1 - 9 files changed, 32 insertions(+), 13 deletions(-) diff --git a/app/models/block.rb b/app/models/block.rb index 2cfddbebc..7f22d905a 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -284,8 +284,15 @@ def cache_keys def invalid! uncle_blocks.delete_all # delete_address_txs_cache - ckb_transactions.delete_all - CellOutput.where(block_id: id).delete_all + ckb_transaction_ids = ckb_transactions.pluck(:id) + CellOutput.where(ckb_transaction_id: ckb_transaction_ids).delete_all + CellInput.where(ckb_transaction_id: ckb_transaction_ids).delete_all + AccountBook.where(ckb_transaction_id: ckb_transaction_ids).delete_all + CellDependency.where(ckb_transaction_id: ckb_transaction_ids).delete_all + HeaderDependency.where(ckb_transaction_id: ckb_transaction_ids).delete_all + TokenTransfer.where(transaction_id: ckb_transaction_ids).delete_all + Witness.where(ckb_transaction_id: ckb_transaction_ids).delete_all + ckb_transactions.destroy_all ForkedBlock.create(attributes) destroy end diff --git a/app/models/cell_input.rb b/app/models/cell_input.rb index cbc35c668..098ab9751 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_compatible: 17, did_cell: 18 + xudt: 15, unique_cell: 16, xudt_compatible: 17, did_cell: 18, stablepp_pool: 19 } def output diff --git a/app/models/cell_output.rb b/app/models/cell_output.rb index aa71bc73d..228d00722 100644 --- a/app/models/cell_output.rb +++ b/app/models/cell_output.rb @@ -32,6 +32,7 @@ class CellOutput < ApplicationRecord unique_cell: 16, xudt_compatible: 17, did_cell: 18, + stablepp_pool: 19, } belongs_to :ckb_transaction diff --git a/app/models/ckb_sync/api.rb b/app/models/ckb_sync/api.rb index 424484a9c..168bafe65 100644 --- a/app/models/ckb_sync/api.rb +++ b/app/models/ckb_sync/api.rb @@ -127,6 +127,10 @@ def single_use_lock_code_hash Settings.single_use_lock_code_hash end + def stablepp_pool_code_hash + Settings.stablepp_pool_code_hash + end + METHOD_NAMES.each do |name| define_method name do |*params| call_rpc(name, params:) diff --git a/app/models/ckb_transaction.rb b/app/models/ckb_transaction.rb index 5434b8bf9..aecd211ea 100644 --- a/app/models/ckb_transaction.rb +++ b/app/models/ckb_transaction.rb @@ -16,11 +16,11 @@ class CkbTransaction < ApplicationRecord has_many :included_blocks, class_name: "Block", through: :block_transactions, inverse_of: :contained_transactions - has_many :account_books, dependent: :delete_all + has_many :account_books has_many :addresses, through: :account_books - has_many :cell_inputs, dependent: :delete_all + has_many :cell_inputs has_many :input_cells, through: :cell_inputs, source: :previous_cell_output - has_many :cell_outputs, dependent: :delete_all + has_many :cell_outputs accepts_nested_attributes_for :cell_outputs has_many :inputs, class_name: "CellOutput", inverse_of: "consumed_by", foreign_key: "consumed_by_id" has_many :outputs, class_name: "CellOutput" @@ -28,11 +28,11 @@ class CkbTransaction < ApplicationRecord # has_many :script_transactions, dependent: :delete_all # has_many :scripts, through: :script_transactions - has_many :referring_cells, dependent: :delete_all - has_many :token_transfers, foreign_key: :transaction_id, dependent: :delete_all, inverse_of: :ckb_transaction - has_many :cell_dependencies, dependent: :delete_all - has_many :header_dependencies, dependent: :delete_all - has_many :witnesses, dependent: :delete_all + has_many :referring_cells + has_many :token_transfers, foreign_key: :transaction_id, inverse_of: :ckb_transaction + has_many :cell_dependencies + has_many :header_dependencies + has_many :witnesses has_one :reject_reason diff --git a/app/serializers/cell_output_serializer.rb b/app/serializers/cell_output_serializer.rb index a7f1a626b..835659f85 100644 --- a/app/serializers/cell_output_serializer.rb +++ b/app/serializers/cell_output_serializer.rb @@ -49,6 +49,8 @@ class CellOutputSerializer object.dob_info.merge!(type: "dob") when "omiga_inscription_info", "omiga_inscription" object.omiga_inscription_info.merge!(type: "omiga_inscription") + when "stablepp_pool" + { type: "stablepp_pool", capacity: object.capacity.to_s } end end end diff --git a/app/utils/ckb_utils.rb b/app/utils/ckb_utils.rb index e5cc46d2b..e99c67917 100644 --- a/app/utils/ckb_utils.rb +++ b/app/utils/ckb_utils.rb @@ -412,7 +412,8 @@ 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_compatible_code_hashes, CkbSync::Api.instance.did_cell_code_hash + CkbSync::Api.instance.xudt_code_hash, CkbSync::Api.instance.unique_cell_code_hash, *CkbSync::Api.instance.xudt_compatible_code_hashes, + CkbSync::Api.instance.did_cell_code_hash, CkbSync::Api.instance.stablepp_pool_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) || @@ -469,6 +470,8 @@ def self.cell_type(type_script, output_data) "xudt" when CkbSync::Api.instance.unique_cell_code_hash "unique_cell" + when CkbSync::Api.instance.stablepp_pool_code_hash + "stablepp_pool" else if is_nrc_721_token_cell?(output_data) "nrc_721_token" diff --git a/config/settings.mainnet.yml b/config/settings.mainnet.yml index 9fb0266a3..d48ef34e4 100644 --- a/config/settings.mainnet.yml +++ b/config/settings.mainnet.yml @@ -40,6 +40,9 @@ xudt_compatible_code_hash: "0x092c2c4a26ea475a8e860c29cf00502103add677705e2ccd8d xudt_compatible2_code_hash: "0x26a33e0815888a4a0614a0b7d09fa951e0993ff21e55905510104a0b1312032b" xudt_compatible3_code_hash: "0x42a0b2aacc836c0fc2bbd421a9020de42b8411584190f30be547fdf54214acc3" +# stablepp_pool +stablepp_pool_code_hash: "0x26622198b66240e437e323e0fecf1c26ba3c8c28a45f03ed3ebb9f7f2bdc0055" + # 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" diff --git a/test/models/ckb_transaction_test.rb b/test/models/ckb_transaction_test.rb index dd8333a99..e886069a5 100644 --- a/test/models/ckb_transaction_test.rb +++ b/test/models/ckb_transaction_test.rb @@ -19,7 +19,6 @@ class CkbTransactionTest < ActiveSupport::TestCase should have_many(:addresses).through(:account_books) should have_many(:cell_inputs) should have_many(:cell_outputs) - should have_many(:script_transactions) should have_many(:cell_dependencies) should have_and_belong_to_many(:contained_udt_addresses)