diff --git a/app/controllers/api/v2/bitcoin_addresses_controller.rb b/app/controllers/api/v2/bitcoin_addresses_controller.rb index f2ba1b5de..da7140337 100644 --- a/app/controllers/api/v2/bitcoin_addresses_controller.rb +++ b/app/controllers/api/v2/bitcoin_addresses_controller.rb @@ -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) diff --git a/app/interactions/addresses/ckb_transactions.rb b/app/interactions/addresses/ckb_transactions.rb index 9748499cb..66b770e57 100644 --- a/app/interactions/addresses/ckb_transactions.rb +++ b/app/interactions/addresses/ckb_transactions.rb @@ -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: }) @@ -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) diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index 2e3e48f92..cad92bd01 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -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