Skip to content
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
2 changes: 1 addition & 1 deletion app/interactions/addresses/ckb_transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def execute
select(:ckb_transaction_id).
page(page).per(page_size)

total_count = Address.find(address_id).ckb_transactions_count
total_count = Address.find(address_id).current_ckb_transactions_count
end

ckb_transaction_ids = account_books.map(&:ckb_transaction_id)
Expand Down
16 changes: 16 additions & 0 deletions app/models/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ def recalc_revalidate_balance!
save!
end

def current_balance
self.cell_outputs.live.sum(:capacity)
end

def current_ckb_transactions_count
AccountBook.where(address_id: self.id).count
end

def current_live_cells_count
self.cell_outputs.live.count
end

def current_balance_occupied
self.cell_outputs.live.occupied.sum(:capacity)
end

def cal_balance
total = cell_outputs.live.sum(:capacity)
occupied = cell_outputs.live.occupied.sum(:capacity)
Expand Down
16 changes: 16 additions & 0 deletions app/models/null_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ def balance
0
end

def current_balance
0
end

def current_ckb_transactions_count
0
end

def current_live_cells_count
0
end

def current_balance_occupied
0
end

def ckb_transactions_count
0
end
Expand Down
8 changes: 4 additions & 4 deletions app/serializers/address_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class AddressSerializer
object.query_address || object.address_hash
end
attribute :balance do |object|
object.balance.to_s
object.current_balance.to_s
end
attribute :transactions_count do |object|
object.ckb_transactions_count.to_s
object.current_ckb_transactions_count.to_s
end
attribute :dao_deposit do |object|
object.dao_deposit.to_s
Expand All @@ -27,7 +27,7 @@ class AddressSerializer
Settings.special_addresses[object.address_hash]
end
attribute :live_cells_count do |object|
object.live_cells_count.to_s
object.current_live_cells_count.to_s
end
attribute :mined_blocks_count do |object|
object.mined_blocks_count.to_s
Expand Down Expand Up @@ -144,7 +144,7 @@ class AddressSerializer
(object.interest.to_i + object.unclaimed_compensation.to_i).to_s
end
attribute :balance_occupied do |object|
object.balance_occupied.to_s
object.current_balance_occupied.to_s
end
attribute :bitcoin_address_hash do |object|
object.bitcoin_address&.address_hash
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v1/addresses_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class AddressesControllerTest < ActionDispatch::IntegrationTest
address_hash: "ckb1qyq0hcfpff4h8w8zvy44uurvlgdrr09tefwqx266dl")

valid_get api_v1_address_url(address.address_hash)
assert_equal "0", json.dig("data", 0, "attributes", "balance_occupied")
assert_equal "0.0", json.dig("data", 0, "attributes", "balance_occupied")
end

test "should return nrc 721 udt accounts with given address hash" do
Expand Down