Skip to content

Commit

Permalink
Merge pull request #2175 from nervosnetwork/testnet
Browse files Browse the repository at this point in the history
Deploy to mainnet
  • Loading branch information
rabbitz authored Sep 6, 2024
2 parents 02bb515 + 61686b4 commit 70e8207
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v2/bitcoin_addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def udt_accounts

cell_types = %w(udt xudt xudt_compatible)
cell_outputs = CellOutput.live.includes(:bitcoin_vout).where(cell_outputs: { address_id: address_ids, cell_type: cell_types }).
where.not(bitcoin_vouts: { status: "unbound" }).group(:cell_type, :type_hash).sum(:udt_amount)
where.not(bitcoin_vouts: { status: ["unbound", "binding"] }).group(:cell_type, :type_hash).sum(:udt_amount)

udt_accounts = cell_outputs.map do |k, v|
udt = Udt.find_by(type_hash: k[1], published: true)
Expand Down
17 changes: 8 additions & 9 deletions app/interactions/addresses/ckb_transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def execute
raise AddressNotFoundError if address.is_a?(NullAddress)

address_id = address.map(&:id)

order_by, asc_or_desc = account_books_ordering
records = CkbTransaction.tx_committed.joins(:account_books).where(
account_books: { address_id: },
).order(order_by => asc_or_desc, "ckb_transactions.tx_index" => "desc").distinct.page(page).per(page_size)

account_books = AccountBook.joins(:ckb_transaction).
where(account_books: { address_id: }, ckb_transactions: { tx_status: :committed }).
order(transactions_ordering).
select("DISTINCT account_books.ckb_transaction_id, ckb_transactions.block_timestamp, ckb_transactions.tx_index").
page(page).per(page_size)
records = CkbTransaction.where(id: account_books.map(&:ckb_transaction_id)).order(transactions_ordering)
options = paginate_options(records, address_id)
options.merge!(params: { previews: true, address: })

Expand All @@ -28,13 +28,12 @@ def execute

private

def account_books_ordering
def transactions_ordering
sort_by = "ckb_transactions.block_timestamp"
_, sort_order = sort.split(".", 2)

sort_order = "asc" unless sort_order&.match?(/^(asc|desc)$/i)

[sort_by, sort_order]
"#{sort_by} #{sort_order}, ckb_transactions.tx_index desc"
end

def paginate_options(records, address_id)
Expand Down
19 changes: 11 additions & 8 deletions config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ class Rack::Attack
self.throttled_responder =
lambda do |env|
match_data = env["rack.attack.match_data"]
now = match_data[:epoch_time]

headers = {
"RateLimit-Limit" => match_data[:limit].to_s,
"RateLimit-Remaining" => "0",
"RateLimit-Reset" => (now + (match_data[:period] - now % match_data[:period])).to_s,
}

[429, headers, ["Throttled\n"]]
if match_data
now = match_data[:epoch_time]
headers = {
"RateLimit-Limit" => match_data[:limit].to_s,
"RateLimit-Remaining" => "0",
"RateLimit-Reset" => (now + (match_data[:period] - now % match_data[:period])).to_s,
}
[429, headers, ["Throttled\n"]]
else
[429, {}, ["Throttled but no match data\n"]]
end
end
end

0 comments on commit 70e8207

Please sign in to comment.