Skip to content

Commit

Permalink
refactor: address live cells
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Jan 7, 2025
1 parent 14fb832 commit c27fa0b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions app/interactions/addresses/live_cells.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ def execute
raise AddressNotFoundError if address.is_a?(NullAddress)

order_by, asc_or_desc = live_cells_ordering
cell_outputs = CellOutput.includes(:bitcoin_vout).where(
cell_outputs: { status: "live", address_id: address.map(&:id) },
)
cell_outputs = cell_outputs.where(bitcoin_vouts: { status: bound_status }) if bound_status
cell_output_ids = cell_outputs.pluck("cell_outputs.id")
records = CellOutput.where(id: cell_output_ids).order(order_by => asc_or_desc).
page(page).per(page_size).fast_page
options = FastJsonapi::PaginationMetaGenerator.new(
request:, records:, page:, page_size:,
).call
if bound_status
bitcoin_vouts = BitcoinVout.where(address_id: address.map(&:id), status: bound_status)
records = CellOutput.live.where(id: bitcoin_vouts.map(&:cell_output_id)).order(order_by => asc_or_desc).
page(page).per(page_size).fast_page
else
records = CellOutput.live.where(address_id: address.map(&:id)).order(order_by => asc_or_desc).
page(page).per(page_size).fast_page
end

options = FastJsonapi::PaginationMetaGenerator.new(request:, records:, page:, page_size:).call
CellOutputSerializer.new(records, options).serialized_json
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/bitcoin_vout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class BitcoinVout < ApplicationRecord
def commitment
return unless op_return?

script_pubkey = Bitcoin::Script.parse_from_payload(data.htb)
script_pubkey.op_return_data.bth
script_pub_key = Bitcoin::Script.parse_from_payload(data.htb)
script_pub_key.op_return_data.bth
end
end

Expand Down

0 comments on commit c27fa0b

Please sign in to comment.