Skip to content

Commit

Permalink
feat: add live cells count to address serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Dec 19, 2019
1 parent e9dba91 commit f9bd5b4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/ckb_sync/node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ def update_previous_cell_output_status(ckb_transaction_id, previous_cell_output)
def update_address_balance_and_ckb_transactions_count(address)
address.balance = address.cell_outputs.live.sum(:capacity)
address.ckb_transactions_count = AccountBook.where(address: address).select(:ckb_transaction_id).distinct.count
address.live_cells_count = address.cell_outputs.live.count
address.save!
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/null_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def special?
Settings.special_addresses[address_hash].present?
end

def live_cells_count
0
end

def lock_script
parsed_address = CKB::AddressParser.new(address_hash).parse
raise Api::V1::Exceptions::AddressNotMatchEnvironmentError.new(ENV["CKB_NET_MODE"]) if parsed_address.mode != ENV["CKB_NET_MODE"]
Expand Down
4 changes: 4 additions & 0 deletions app/presenters/address_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def interest
object.reduce(0) { |sum, addr| sum + addr.interest.to_i }
end

def live_cells_count
object.reduce(0) { |sum, addr| sum + addr.live_cells_count.to_i }
end

def lock_script
object.first.cached_lock_script
end
Expand Down
4 changes: 3 additions & 1 deletion app/serializers/address_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ class AddressSerializer
attribute :is_special do |object|
object.special?.to_s
end

attribute :special_address, if: Proc.new { |record| record.special? } do |object|
Settings.special_addresses[object.address_hash]
end
attribute :live_cells_count do |object|
object.live_cells_count.to_s
end
end

0 comments on commit f9bd5b4

Please sign in to comment.