Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy to mainnet #2175

Merged
merged 6 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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)

Check warning on line 56 in app/controllers/api/v2/bitcoin_addresses_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/bitcoin_addresses_controller.rb#L56

Added line #L56 was not covered by tests

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
Loading