Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return integer for create_timestamp time extraction #1538

Merged
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
6 changes: 5 additions & 1 deletion app/models/ckb_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,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