Skip to content

Commit 03b44e2

Browse files
authored
Merge pull request #2839 from nervosnetwork/testnet
Deploy to mainnet
2 parents 7902f0a + ad99202 commit 03b44e2

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

app/interactions/addresses/ckb_transactions.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,27 @@ def execute
1212
is_bitcoin = BitcoinUtils.valid_address?(key)
1313

1414
if is_bitcoin
15-
account_books = BtcAccountBook.includes(:bitcoin_address).
16-
where(bitcoin_address: { address_hash: key }).
15+
address = BitcoinAddress.find_by(address_hash: key)
16+
raise AddressNotFoundError unless address
17+
address = [address]
18+
19+
account_books = BtcAccountBook.
20+
where(bitcoin_address_id: address[0].id).
1721
order(account_books_ordering).
1822
page(page).per(page_size)
23+
24+
total_count = BtcAccountBook.where(bitcoin_address_id: address[0].id).count
1925
else
2026
address = Explore.run!(key:)
2127
raise AddressNotFoundError if address.is_a?(NullAddress)
2228

23-
address_id = address.map(&:id)
29+
address_id = address.map(&:id).first
2430
account_books = AccountBook.tx_committed.where(address_id:).
2531
order(account_books_ordering).
2632
select(:ckb_transaction_id).
2733
page(page).per(page_size)
34+
35+
total_count = Address.find(address_id).ckb_transactions_count
2836
end
2937

3038
ckb_transaction_ids = account_books.map(&:ckb_transaction_id)
@@ -36,8 +44,9 @@ def execute
3644
.includes(includes)
3745
.select(select_fields)
3846
.order(transactions_ordering)
47+
3948

40-
options = paginate_options(records, address_id)
49+
options = paginate_options(records, total_count)
4150
options.merge!(params: { previews: true, address_id: })
4251

4352
result = CkbTransactionsSerializer.new(records, options)
@@ -60,8 +69,7 @@ def transactions_ordering
6069
"ckb_transactions.id #{sort_order}"
6170
end
6271

63-
def paginate_options(records, address_id)
64-
total_count = Address.where(id: address_id).sum(:ckb_transactions_count)
72+
def paginate_options(records, total_count)
6573
count = [total_count, Settings.query_default_limit].min
6674
FastJsonapi::PaginationMetaGenerator.new(
6775
request:, records:, page:, page_size:, total_pages: (count.to_f / page_size).ceil, total_count:,

0 commit comments

Comments
 (0)