Skip to content

Commit

Permalink
Merge pull request #2014 from nervosnetwork/testnet
Browse files Browse the repository at this point in the history
Deploy to mainnet
  • Loading branch information
rabbitz authored Jun 28, 2024
2 parents 9e605fa + 1e95383 commit 457e7b8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
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

0 comments on commit 457e7b8

Please sign in to comment.