Skip to content

Commit c3d595e

Browse files
authored
Merge pull request #2535 from nervosnetwork/testnet
Deploy to mainnet
2 parents e613d1c + fb37a8d commit c3d595e

21 files changed

+555
-115
lines changed

.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,6 @@ BITCOIN_SIGNET_PASS=""
129129
PARTNER_DOMAINS="/localhost:\d*/"
130130

131131
# -------------------------------- Fiber segment --------------------------------
132-
FIBER_NODE_URL=""
132+
FIBER_NODE_URL=""
133+
134+
SSRI_URL="http://localhost:9090"

.env.test.local.travis

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ ASSET_URL=""
4848

4949
# -------------------------------- portfolio segment --------------------------------
5050
AUTH_ACCESS_EXPIRE=1296000
51-
SECRET_KEY_BASE=
51+
SECRET_KEY_BASE=
52+
53+
SSRI_URL="http://0.0.0.0:9090"

app/controllers/api/v1/xudts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def parse_tags
110110
end
111111

112112
def xudt_type_params
113-
params[:type].blank? ? ["xudt", "xudt_compatible"] : "xudt_compatible"
113+
params[:type].blank? ? ["xudt", "xudt_compatible", "ssri"] : "xudt_compatible"
114114
end
115115
end
116116
end

app/controllers/api/v2/blocks_controller.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ def ckb_node_versions
44
result = Block.last_7_days_ckb_node_version
55

66
render json: {
7-
data: result.map { |k, v|
7+
data: result.map do |k, v|
88
{
9-
version: (k || 'others'),
10-
blocks_count: v
9+
version: k || "others",
10+
blocks_count: v,
1111
}
12-
}
12+
end,
1313
}
1414
end
15+
16+
def by_epoch
17+
block = Block.where(epoch: params[:epoch_number]).order("number asc").limit(1).offset(params[:epoch_index].to_i).first
18+
render json: BlockSerializer.new(block)
19+
end
1520
end
1621
end
17-

app/models/cell_input.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CellInput < ApplicationRecord
1313
normal: 0, nervos_dao_deposit: 1, nervos_dao_withdrawing: 2, udt: 3, m_nft_issuer: 4,
1414
m_nft_class: 5, m_nft_token: 6, nrc_721_token: 7, nrc_721_factory: 8, cota_registry: 9,
1515
cota_regular: 10, spore_cluster: 11, spore_cell: 12, omiga_inscription_info: 13, omiga_inscription: 14,
16-
xudt: 15, unique_cell: 16, xudt_compatible: 17, did_cell: 18, stablepp_pool: 19
16+
xudt: 15, unique_cell: 16, xudt_compatible: 17, did_cell: 18, stablepp_pool: 19, ssri: 20
1717
}
1818

1919
def output

app/models/cell_output.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CellOutput < ApplicationRecord
3333
xudt_compatible: 17,
3434
did_cell: 18,
3535
stablepp_pool: 19,
36+
ssri: 20,
3637
}
3738

3839
belongs_to :ckb_transaction
@@ -147,7 +148,7 @@ def occupied?
147148

148149
# @return [Boolean]
149150
def free?
150-
type_hash.blank? && (data.present? && data == "0x")
151+
type_hash.blank? && data.present? && data == "0x"
151152
end
152153

153154
def address_hash

app/models/ckb_sync/new_node_data_processor.rb

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ def call
2828
return if target_block_number > tip_block_number - @offset.to_i
2929

3030
target_block = CkbSync::Api.instance.get_block_by_number(target_block_number)
31-
if !forked?(target_block, local_tip_block)
31+
if forked?(target_block, local_tip_block)
32+
self.reorg_started_at = Time.now
33+
res = RevertBlockJob.perform_now(local_tip_block)
34+
reorg_started_at.delete
35+
res
36+
else
3237
Rails.logger.error "process_block: #{target_block_number}"
3338
res =
3439
ApplicationRecord.cache do
3540
process_block(target_block)
3641
end
3742
reorg_started_at.delete
3843
res
39-
else
40-
self.reorg_started_at = Time.now
41-
res = RevertBlockJob.perform_now(local_tip_block)
42-
reorg_started_at.delete
43-
res
4444
end
4545
rescue StandardError => e
4646
Rails.logger.error e.message
@@ -418,7 +418,7 @@ def update_or_create_udt_accounts!(local_block)
418418
:symbol, :decimal, :published, :code_hash, :type_hash, :created_at).take!
419419
if udt_account.present?
420420
case udt_type
421-
when "sudt", "omiga_inscription", "xudt", "xudt_compatible"
421+
when "sudt", "ssri", "omiga_inscription", "xudt", "xudt_compatible"
422422
udt_accounts_attributes << { id: udt_account.id, amount:,
423423
created_at: udt.created_at }
424424
when "m_nft_token", "nrc_721_token", "spore_cell", "did_cell"
@@ -447,7 +447,7 @@ def udt_type(cell_type)
447447

448448
def udt_account_amount(udt_type, type_hash, address)
449449
case udt_type
450-
when "sudt"
450+
when "sudt", "ssri"
451451
address.cell_outputs.live.udt.where(type_hash:).sum(:udt_amount)
452452
when "xudt", "xudt_compatible", "omiga_inscription", "m_nft_token", "spore_cell", "did_cell"
453453
address.cell_outputs.live.where(cell_type: udt_type).where(type_hash:).sum(:udt_amount)
@@ -763,7 +763,7 @@ def build_cells_and_locks!(
763763
build_cell_outputs!(node_block, outputs, ckb_txs, local_block, cell_outputs_attributes, output_capacities, tags,
764764
udt_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes, token_transfer_ckb_tx_ids)
765765
if cell_outputs_attributes.present?
766-
tx_hashes = cell_outputs_attributes.map { |attr| attr[:tx_hash] }
766+
tx_hashes = cell_outputs_attributes.pluck(:tx_hash)
767767
binary_hashes = CkbUtils.hexes_to_bins_sql(tx_hashes)
768768
CellOutput.pending.where("tx_hash IN (#{binary_hashes})").update_all(status: :live)
769769
id_hashes = CellOutput.upsert_all(cell_outputs_attributes, unique_by: %i[tx_hash cell_index status],
@@ -821,7 +821,7 @@ def build_cells_and_locks!(
821821
CellInput.upsert_all(cell_inputs_attributes,
822822
unique_by: %i[ckb_transaction_id index])
823823
if prev_cell_outputs_attributes.present?
824-
cell_ouput_ids = prev_cell_outputs_attributes.map { |attr| attr[:id] }
824+
cell_ouput_ids = prev_cell_outputs_attributes.pluck(:id)
825825
CellOutput.live.where(id: cell_ouput_ids).update_all(status: :dead)
826826
CellOutput.upsert_all(prev_cell_outputs_attributes,
827827
unique_by: %i[tx_hash cell_index status],
@@ -962,6 +962,12 @@ def build_cell_inputs(
962962
udt_address_ids[tx_index] << address_id
963963
contained_udt_ids[tx_index] << Udt.where(type_hash:,
964964
udt_type: "sudt").pick(:id)
965+
when "ssri"
966+
tags[tx_index] << "ssri"
967+
udt_address_ids[tx_index] << address_id
968+
contained_udt_ids[tx_index] << Udt.where(type_hash:,
969+
udt_type: "ssri").pick(:id)
970+
965971
when "omiga_inscription"
966972
tags[tx_index] << "omiga_inscription"
967973
udt_address_ids[tx_index] << address_id
@@ -1039,6 +1045,12 @@ def build_cell_outputs!(
10391045
contained_udt_ids[tx_index] << Udt.where(
10401046
type_hash: item.type.compute_hash, udt_type: "sudt",
10411047
).pick(:id)
1048+
elsif attr[:cell_type] == "ssri"
1049+
tags[tx_index] << "ssri"
1050+
udt_address_ids[tx_index] << address.id
1051+
contained_udt_ids[tx_index] << Udt.where(
1052+
type_hash: item.type.compute_hash, udt_type: "ssri",
1053+
).pick(:id)
10421054
elsif attr[:cell_type] == "omiga_inscription"
10431055
tags[tx_index] << "omiga_inscription"
10441056
udt_address_ids[tx_index] << address_id
@@ -1068,7 +1080,7 @@ def build_cell_outputs!(
10681080
end
10691081

10701082
def occupied?(type_hash, cell_data)
1071-
cell_data.present? && cell_data != "0x" || type_hash.present?
1083+
(cell_data.present? && cell_data != "0x") || type_hash.present?
10721084
end
10731085

10741086
def cell_output_attributes(output, address, ckb_transaction, local_block, cell_index, output_data)

app/models/contract.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class Contract < ApplicationRecord
22
has_many :cell_deps_out_points, foreign_key: :deployed_cell_output_id, primary_key: :deployed_cell_output_id
33
has_many :cell_dependencies, through: :cell_deps_out_points
4+
has_one :ssri_contract
45
belongs_to :deployed_cell_output, class_name: "CellOutput"
56
belongs_to :contract_cell, class_name: "CellOutput", optional: true
67

app/models/ssri_contract.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class SsriContract < ApplicationRecord
2+
belongs_to :contract
3+
4+
scope :udt, -> { where(is_udt: true) }
5+
6+
def self.udt_code_hashes
7+
Rails.cache.fetch("ssri_contracts:udt_code_hashes") do
8+
udt.pluck(:code_hash, :hash_type)
9+
end
10+
end
11+
end
12+
13+
# == Schema Information
14+
#
15+
# Table name: ssri_contracts
16+
#
17+
# id :bigint not null, primary key
18+
# contract_id :bigint
19+
# methods :string default([]), is an Array
20+
# is_udt :boolean
21+
# code_hash :binary
22+
# hash_type :string
23+
# created_at :datetime not null
24+
# updated_at :datetime not null
25+
#
26+
# Indexes
27+
#
28+
# index_ssri_contracts_on_contract_id (contract_id) UNIQUE
29+
#

app/models/udt.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Udt < ApplicationRecord
88
has_many :udt_holder_allocations
99

1010
enum udt_type: { sudt: 0, m_nft_token: 1, nrc_721_token: 2, spore_cell: 3,
11-
omiga_inscription: 4, xudt: 5, xudt_compatible: 6, did_cell: 7 }
11+
omiga_inscription: 4, xudt: 5, xudt_compatible: 6, did_cell: 7, ssri: 8 }
1212

1313
validates_presence_of :total_amount
1414
validates :decimal,
@@ -46,6 +46,13 @@ def type_script
4646
def holders_count
4747
udt_holder_allocations.sum("ckb_holder_count + btc_holder_count")
4848
end
49+
50+
def ssri_contract_outpoint
51+
return unless udt_type == "ssri"
52+
53+
cell = SsriContract.find_by(code_hash: code_hash, hash_type: hash_type).contract.deployed_cell_output
54+
{ tx_hash: cell.tx_hash, cell_index: cell.cell_index }
55+
end
4956
end
5057

5158
# == Schema Information

0 commit comments

Comments
 (0)