Skip to content

Commit

Permalink
fix: return integer for create_timestamp time extraction (nervosnetwo…
Browse files Browse the repository at this point in the history
…rk#1538)

* fix: return integer for create_timestamp time extraction

* fix: pending transaction income
  • Loading branch information
rabbitz authored and ttt12334 committed Dec 25, 2023
1 parent 6ca48be commit 2489eb2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app/models/ckb_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ def cell_deps
end

def income(address)
outputs.where(address: address).sum(:capacity) - inputs.where(address: address).sum(:capacity)
if tx_pending?
cell_outputs.where(address: address).sum(:capacity) - input_cells.where(address: address).sum(:capacity)
else
outputs.where(address: address).sum(:capacity) - inputs.where(address: address).sum(:capacity)
end
end

def dao_transaction?
Expand Down
6 changes: 4 additions & 2 deletions app/serializers/ckb_transaction_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class CkbTransactionSerializer
end

attribute :display_inputs do |object, params|
Rails.cache.fetch("display_inputs_previews_#{params[:previews].present?}_#{object.id}", expires_in: 1.day) do
cache_key = "display_inputs_previews_#{params[:previews].present?}_#{object.id}_#{object.inputs.cache_key}"
Rails.cache.fetch(cache_key, expires_in: 1.day) do
if params && params[:previews]
object.display_inputs(previews: true)
else
Expand All @@ -55,7 +56,8 @@ class CkbTransactionSerializer
end

attribute :display_outputs do |object, params|
Rails.cache.fetch("display_outputs_previews_#{params[:previews].present?}_#{object.id}", expires_in: 1.day) do
cache_key = "display_outputs_previews_#{params[:previews].present?}_#{object.id}_#{object.outputs.cache_key}"
Rails.cache.fetch(cache_key, expires_in: 1.day) do
if params && params[:previews]
object.display_outputs(previews: true)
else
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/ckb_transactions_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ class CkbTransactionsSerializer
end

attribute :create_timestamp do |object|
(object.created_at.to_f * 1000).to_s
(object.created_at.to_f * 1000).to_i.to_s
end
end

0 comments on commit 2489eb2

Please sign in to comment.