Skip to content

Commit

Permalink
feat: identify stablepp_pool cell (#2298)
Browse files Browse the repository at this point in the history
* feat: identify stablepp_pool cell

Signed-off-by: Miles Zhang <[email protected]>

* fix: block rollback test

Signed-off-by: Miles Zhang <[email protected]>

---------

Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid authored Nov 28, 2024
1 parent 681b2da commit 1faf918
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 13 deletions.
11 changes: 9 additions & 2 deletions app/models/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/cell_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/models/cell_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CellOutput < ApplicationRecord
unique_cell: 16,
xudt_compatible: 17,
did_cell: 18,
stablepp_pool: 19,
}

belongs_to :ckb_transaction
Expand Down
4 changes: 4 additions & 0 deletions app/models/ckb_sync/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:)
Expand Down
16 changes: 8 additions & 8 deletions app/models/ckb_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ 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"
has_many :dao_events # , dependent: :delete_all
# 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

Expand Down
2 changes: 2 additions & 0 deletions app/serializers/cell_output_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion app/utils/ckb_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions config/settings.mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion test/models/ckb_transaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1faf918

Please sign in to comment.