From 992b4f35e192425926e0d7bcb89695040a3cd36d Mon Sep 17 00:00:00 2001 From: Rabbit Date: Tue, 7 Jan 2025 17:18:41 +0800 Subject: [PATCH] refactor: address live cells (#2392) --- app/interactions/addresses/live_cells.rb | 19 +++++++++---------- app/models/bitcoin_vout.rb | 4 ++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/interactions/addresses/live_cells.rb b/app/interactions/addresses/live_cells.rb index 0fc2ca757..0e3014163 100644 --- a/app/interactions/addresses/live_cells.rb +++ b/app/interactions/addresses/live_cells.rb @@ -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 diff --git a/app/models/bitcoin_vout.rb b/app/models/bitcoin_vout.rb index 3b4a7a6da..9191268ba 100644 --- a/app/models/bitcoin_vout.rb +++ b/app/models/bitcoin_vout.rb @@ -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