Skip to content

Commit

Permalink
Merge pull request #2021 from nervosnetwork/testnet
Browse files Browse the repository at this point in the history
Deploy to mainnet
  • Loading branch information
rabbitz authored Jul 9, 2024
2 parents 457e7b8 + 5c47421 commit 2b7eea8
Show file tree
Hide file tree
Showing 21 changed files with 201 additions and 318 deletions.
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 @@ -15,7 +15,11 @@ def index

if params[:tags].present?
tags = parse_tags
scope = scope.joins(:xudt_tag).where("xudt_tags.tags @> array[?]::varchar[]", tags).select("udts.*") unless tags.empty?
if params[:union].present?
scope = scope.joins(:xudt_tag).where("xudt_tags.tags && ARRAY[?]::varchar[]", tags).select("udts.*") unless tags.empty?
else
scope = scope.joins(:xudt_tag).where("xudt_tags.tags @> array[?]::varchar[]", tags).select("udts.*") unless tags.empty?
end
end

if stale?(scope)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/api/v2/bitcoin_addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def rgb_cells

cells = bitcoin_vouts.each_with_object({}) do |vout, hash|
tx = transactions[vout.bitcoin_transaction_id]
vouts = BitcoinVout.where(bitcoin_transaction_id: vout.bitcoin_transaction_id, index: vout.index).includes(:cell_output)
vouts = BitcoinVout.where(bitcoin_transaction_id: vout.bitcoin_transaction_id, index: vout.index).includes(:cell_output).where(
cell_outputs: { status: "live" },
)
hash[[tx.tx_hash, vout.index]] = vouts.map { |v| CellOutputSerializer.new(v.cell_output).serializable_hash }
end

Expand Down
6 changes: 5 additions & 1 deletion app/controllers/api/v2/nft/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ def index
end
if params[:tags].present?
tags = parse_tags
scope = scope.where("tags @> array[?]::varchar[]", tags) unless tags.empty?
if params[:union].present?
scope = scope.where("tags && ARRAY[?]::varchar[]", tags) unless tags.empty?
else
scope = scope.where("tags @> array[?]::varchar[]", tags) unless tags.empty?
end
end
pagy, collections = pagy(sort_collections(scope))

Expand Down
4 changes: 4 additions & 0 deletions app/controllers/api/v2/statistics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def transaction_fees

def contract_resource_distributed
contracts = Contract.filter_nil_hash_type
if params[:code_hashes].present?
hashes = params[:code_hashes].split(",")
contracts = contracts.where(code_hash: hashes)
end
if stale?(contracts)
expires_in 30.minutes, public: true
json = contracts.map do |contract|
Expand Down
58 changes: 41 additions & 17 deletions app/jobs/csv_exportable/export_dao_depositors_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,61 @@
module CsvExportable
class ExportDaoDepositorsJob < BaseExporter
def perform(args)
sql = "".dup
start_date, end_date = extract_dates(args)

if args[:start_date].present?
sql << "ckb_transactions.block_timestamp >= #{BigDecimal(args[:start_date])}"
end
rows = fetch_deposit_rows(start_date, end_date) + fetch_withdrawing_rows(start_date, end_date)

if args[:end_date].present?
sql << " AND ckb_transactions.block_timestamp <= #{BigDecimal(args[:end_date])}"
end
header = ["Address", "Capacity", "Txn hash", "Previous Txn hash", "UnixTimestamp", "date(UTC)"]
generate_csv(header, rows)
end

private

def extract_dates(args)
start_date = args[:start_date].present? ? BigDecimal(args[:start_date]) : nil
end_date = args[:end_date].present? ? BigDecimal(args[:end_date]) : nil
start_number = args[:start_number].presence
end_number = args[:end_number].presence

if args[:start_number].present?
sql << "ckb_transactions.block_number >= #{args[:start_number]}"
if start_number.present?
start_date = Block.find_by(number: start_number)&.timestamp
end

if args[:end_number].present?
sql << " AND ckb_transactions.block_number <= #{args[:end_number]}"
if end_number.present?
end_date = Block.find_by(number: end_number)&.timestamp
end

[start_date, end_date]
end

def build_sql_query(start_date, end_date)
sql = "".dup
sql << "block_timestamp >= #{start_date}" if start_date.present?
sql << " AND " if start_date.present? && end_date.present?
sql << "block_timestamp <= #{end_date}" if end_date.present?
sql
end

def fetch_deposit_rows(start_date, end_date)
sql = build_sql_query(start_date, end_date)
rows = []
CellOutput.left_joins(:ckb_transaction, :address).live.nervos_dao_deposit.where(sql).
select("cell_outputs.*, ckb_transactions.block_number, ckb_transactions.block_timestamp").find_in_batches(batch_size: 1000) do |cells|

CellOutput.includes(:address).live.nervos_dao_deposit.where(sql).find_in_batches(batch_size: 500) do |cells|
cells.each do |cell|
amount = CkbUtils.shannon_to_byte(BigDecimal(cell.capacity))
datetime = datetime_utc(cell.block_timestamp)
rows << [cell.address_hash, amount, cell.tx_hash, nil, cell.block_timestamp, datetime]
end
end

CellOutput.left_joins(:ckb_transaction, :address).live.nervos_dao_withdrawing.where(sql).
select("cell_outputs.*, ckb_transactions.block_number, ckb_transactions.block_timestamp").find_in_batches(batch_size: 1000) do |cells|
rows
end

def fetch_withdrawing_rows(start_date, end_date)
sql = build_sql_query(start_date, end_date)
rows = []

CellOutput.includes(:address).live.nervos_dao_withdrawing.where(sql).find_in_batches(batch_size: 500) do |cells|
cells.each do |cell|
cell_input = cell.ckb_transaction.cell_inputs.nervos_dao_deposit.first
previous_cell_output = cell_input.previous_cell_output
Expand All @@ -43,8 +68,7 @@ def perform(args)
end
end

header = ["Address", "Capacity", "Txn hash", "Previous Txn hash", "UnixTimestamp", "date(UTC)"]
generate_csv(header, rows)
rows
end
end
end
60 changes: 0 additions & 60 deletions app/jobs/import_btc_time_cell_job.rb

This file was deleted.

159 changes: 0 additions & 159 deletions app/jobs/import_rgbpp_cell_job.rb

This file was deleted.

7 changes: 0 additions & 7 deletions app/models/udt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ def type_script
hash_type:,
}
end

def holder_allocation
allocation = Rails.cache.read("udt_holders/#{type_hash}")
return unless allocation

CkbUtils.hash_value_to_s(allocation)
end
end

# == Schema Information
Expand Down
3 changes: 0 additions & 3 deletions app/serializers/udt_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class UdtSerializer
attribute :addresses_count do |object|
object.addresses_count.to_s
end
attribute :holder_allocation do |object|
object.holder_allocation
end
attribute :decimal do |object|
object.decimal.to_s
end
Expand Down
8 changes: 0 additions & 8 deletions app/workers/clean_up_worker.rb

This file was deleted.

Loading

0 comments on commit 2b7eea8

Please sign in to comment.