Skip to content

Commit

Permalink
Merge pull request #1933 from nervosnetwork/testnet
Browse files Browse the repository at this point in the history
Deploy to mainnet
  • Loading branch information
zmcNotafraid authored Jun 7, 2024
2 parents 0a0c148 + 26826a6 commit a5ace97
Show file tree
Hide file tree
Showing 26 changed files with 183 additions and 107 deletions.
116 changes: 58 additions & 58 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,72 @@ 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)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -357,30 +357,30 @@ 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
nokogiri (>= 1.6)
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)
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/api/v1/xudts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"] : "xudt_compatible"
end
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/concerns/cell_data_comparator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
6 changes: 4 additions & 2 deletions app/jobs/import_btc_time_cell_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
10 changes: 7 additions & 3 deletions app/jobs/import_rgbpp_cell_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -47,20 +47,23 @@ 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

# raw transactions may not include the block hash
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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/revert_block_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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: 15, unique_cell: 16, xudt_compatible: 17
}

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 @@ -28,6 +28,7 @@ class CellOutput < ApplicationRecord
omiga_inscription: 14,
xudt: 15,
unique_cell: 16,
xudt_compatible: 17,
}

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 @@ -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
Expand Down
Loading

0 comments on commit a5ace97

Please sign in to comment.