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 #2014

Merged
merged 2 commits into from
Jun 28, 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
32 changes: 32 additions & 0 deletions app/controllers/api/v2/bitcoin_addresses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Api
module V2
class BitcoinAddressesController < BaseController
before_action :set_pagination_params, only: %i[rgb_cells]
def show
expires_in 1.minute, public: true, must_revalidate: true, stale_while_revalidate: 10.seconds

Expand All @@ -17,6 +18,37 @@ def show

render json: { unbound_live_cells_count:, bound_live_cells_count: }
end

def rgb_cells
expires_in 1.minute, public: true, must_revalidate: true, stale_while_revalidate: 10.seconds

address = Addresses::Explore.run!(key: params[:id])
address_ids = address.map(&:id)

bitcoin_vouts = BitcoinVout.joins(:cell_output).
where(cell_outputs: { status: "live" }, bitcoin_vouts: { address_id: address_ids }).
select(:bitcoin_transaction_id, :index).
group(:bitcoin_transaction_id, :index).
page(@page).per(@page_size)

transaction_ids = bitcoin_vouts.map(&:bitcoin_transaction_id).uniq
transactions = BitcoinTransaction.where(id: transaction_ids).index_by(&:id)

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)
hash[[tx.tx_hash, vout.index]] = vouts.map { |v| CellOutputSerializer.new(v.cell_output).serializable_hash }
end

render json: { data: { rgb_cells: cells }, meta: { total: bitcoin_vouts.total_count, page_size: @page_size } }
end

private

def set_pagination_params
@page = params.fetch(:page, 1)
@page_size = params.fetch(:page_size, CellOutput.default_per_page)
end
end
end
end
6 changes: 2 additions & 4 deletions app/interactions/addresses/ckb_transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ def execute
address_id = address.map(&:id)

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

options = paginate_options(records, address_id)
options.merge!(params: { previews: true, address: })
Expand Down
4 changes: 3 additions & 1 deletion config/routes/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@

resources :rgb_transactions, only: :index
resources :bitcoin_statistics, only: :index
resources :bitcoin_addresses, only: :show
resources :bitcoin_addresses, only: :show do
get :rgb_cells, on: :member
end
end
end
Loading