diff --git a/app/controllers/api/v1/address_dao_transactions_controller.rb b/app/controllers/api/v1/address_dao_transactions_controller.rb index 77a19922f..4231efae1 100644 --- a/app/controllers/api/v1/address_dao_transactions_controller.rb +++ b/app/controllers/api/v1/address_dao_transactions_controller.rb @@ -8,7 +8,7 @@ def show address = Address.find_address!(params[:id]) raise Api::V1::Exceptions::AddressNotFoundError if address.is_a?(NullAddress) - ckb_dao_transactions = address.ckb_dao_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at).recent.page(@page).per(@page_size).fast_page + ckb_dao_transactions = address.ckb_dao_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at).recent.page(@page).per(@page_size).fast_page json = Rails.cache.realize(ckb_dao_transactions.cache_key, version: ckb_dao_transactions.cache_version) do records_counter = RecordCounters::AddressDaoTransactions.new(address) diff --git a/app/controllers/api/v1/address_transactions_controller.rb b/app/controllers/api/v1/address_transactions_controller.rb index debafcb4e..86d9c2a7d 100644 --- a/app/controllers/api/v1/address_transactions_controller.rb +++ b/app/controllers/api/v1/address_transactions_controller.rb @@ -21,7 +21,7 @@ def show ckb_transaction_ids = tx_ids.map(&:ckb_transaction_id) ckb_transactions = CkbTransaction.where(id: ckb_transaction_ids). select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, - :is_cellbase, :updated_at, :capacity_involved). + :is_cellbase, :updated_at, :capacity_involved, :created_at). order(order_by => asc_or_desc) options = FastJsonapi::PaginationMetaGenerator.new( diff --git a/app/controllers/api/v1/address_udt_transactions_controller.rb b/app/controllers/api/v1/address_udt_transactions_controller.rb index 1e52bc3b7..5d95c3503 100644 --- a/app/controllers/api/v1/address_udt_transactions_controller.rb +++ b/app/controllers/api/v1/address_udt_transactions_controller.rb @@ -12,7 +12,9 @@ def show udt = Udt.find_by(type_hash: params[:type_hash], published: true) raise Api::V1::Exceptions::UdtNotFoundError if udt.blank? - ckb_dao_transactions = address.ckb_udt_transactions(udt.id).select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at).recent.page(@page).per(@page_size).fast_page + ckb_dao_transactions = address.ckb_udt_transactions(udt.id). + select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at). + recent.page(@page).per(@page_size).fast_page json = Rails.cache.realize(ckb_dao_transactions.cache_key, version: ckb_dao_transactions.cache_version) do records_counter = RecordCounters::AddressUdtTransactions.new(address, udt.id) diff --git a/app/controllers/api/v1/block_transactions_controller.rb b/app/controllers/api/v1/block_transactions_controller.rb index 27272b167..7ee14019a 100644 --- a/app/controllers/api/v1/block_transactions_controller.rb +++ b/app/controllers/api/v1/block_transactions_controller.rb @@ -6,7 +6,7 @@ class BlockTransactionsController < ApplicationController def show block = Block.find_by!(block_hash: params[:id]) ckb_transactions = block.ckb_transactions. - select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at). + select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at). order(is_cellbase: :desc, id: :asc) if params[:tx_hash].present? diff --git a/app/controllers/api/v1/ckb_transactions_controller.rb b/app/controllers/api/v1/ckb_transactions_controller.rb index 58d5d7e00..97a12fd36 100644 --- a/app/controllers/api/v1/ckb_transactions_controller.rb +++ b/app/controllers/api/v1/ckb_transactions_controller.rb @@ -8,7 +8,7 @@ class CkbTransactionsController < ApplicationController def index if from_home_page? ckb_transactions = CkbTransaction.tx_committed.recent.normal.select( - :id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved, :updated_at + :id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved, :updated_at, :created_at ).limit((Settings.homepage_transactions_records_count || 15).to_i) json = Rails.cache.realize(ckb_transactions.cache_key, @@ -18,7 +18,7 @@ def index render json: json else ckb_transactions = CkbTransaction.tx_committed.normal.select( - :id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved, :updated_at + :id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved, :updated_at, :created_at ) params[:sort] ||= "id.desc" @@ -84,7 +84,7 @@ def query CkbTransaction.recent.normal.page(@page).per(@page_size).fast_page end ckb_transactions = ckb_transactions.select(:id, :tx_hash, :block_id, - :block_number, :block_timestamp, :is_cellbase, :updated_at) + :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at) json = Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version, race_condition_ttl: 1.minute) do diff --git a/app/controllers/api/v1/contract_transactions_controller.rb b/app/controllers/api/v1/contract_transactions_controller.rb index 57389f5cf..de2f093ea 100644 --- a/app/controllers/api/v1/contract_transactions_controller.rb +++ b/app/controllers/api/v1/contract_transactions_controller.rb @@ -12,7 +12,7 @@ def show expires_in 10.seconds, public: true, must_revalidate: true, stale_while_revalidate: 5.seconds ckb_transactions = dao_contract.ckb_transactions.includes(:cell_inputs, :cell_outputs).tx_committed.select( - :id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at + :id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at ).order("ckb_transactions.block_timestamp desc nulls last, ckb_transactions.id desc") if params[:tx_hash].present? diff --git a/app/controllers/api/v1/udt_transactions_controller.rb b/app/controllers/api/v1/udt_transactions_controller.rb index 0d9012dc2..c91208775 100644 --- a/app/controllers/api/v1/udt_transactions_controller.rb +++ b/app/controllers/api/v1/udt_transactions_controller.rb @@ -9,7 +9,7 @@ def show ckb_transactions = udt.ckb_transactions.tx_committed. select(:id, :tx_hash, :block_id, :block_number, - :block_timestamp, :is_cellbase, :updated_at). + :block_timestamp, :is_cellbase, :updated_at, :created_at). order("ckb_transactions.block_timestamp desc nulls last, ckb_transactions.id desc") if params[:tx_hash].present? diff --git a/app/serializers/ckb_transactions_serializer.rb b/app/serializers/ckb_transactions_serializer.rb index 1fe281648..092895152 100644 --- a/app/serializers/ckb_transactions_serializer.rb +++ b/app/serializers/ckb_transactions_serializer.rb @@ -50,4 +50,12 @@ class CkbTransactionsSerializer object.income(params[:address]) end end + + attribute :created_at do |object| + object.created_at.to_s + end + + attribute :create_timestamp do |object| + (object.created_at.to_f * 1000).to_s + end end diff --git a/test/controllers/api/v1/address_dao_transactions_controller_test.rb b/test/controllers/api/v1/address_dao_transactions_controller_test.rb index 90c533b9d..7e736a078 100644 --- a/test/controllers/api/v1/address_dao_transactions_controller_test.rb +++ b/test/controllers/api/v1/address_dao_transactions_controller_test.rb @@ -89,7 +89,7 @@ class AddressDaoTransactionsControllerTest < ActionDispatch::IntegrationTest response_tx_transaction = json["data"].first - assert_equal %w(block_number block_timestamp display_inputs display_inputs_count display_outputs display_outputs_count income is_cellbase transaction_hash).sort, response_tx_transaction["attributes"].keys.sort + assert_equal %w(block_number block_timestamp display_inputs display_inputs_count display_outputs display_outputs_count income is_cellbase transaction_hash created_at create_timestamp).sort, response_tx_transaction["attributes"].keys.sort end test "should return error object when no records found by id" do diff --git a/test/controllers/api/v1/address_pending_transactions_controller_test.rb b/test/controllers/api/v1/address_pending_transactions_controller_test.rb index d9958fa57..c8a767963 100644 --- a/test/controllers/api/v1/address_pending_transactions_controller_test.rb +++ b/test/controllers/api/v1/address_pending_transactions_controller_test.rb @@ -148,6 +148,8 @@ class AddressPendingTransactionsControllerTest < ActionDispatch::IntegrationTest income is_cellbase transaction_hash + created_at + create_timestamp ).sort, response_tx_transaction["attributes"].keys.sort end diff --git a/test/controllers/api/v1/address_transactions_controller_test.rb b/test/controllers/api/v1/address_transactions_controller_test.rb index 0dd218518..000cf5edf 100644 --- a/test/controllers/api/v1/address_transactions_controller_test.rb +++ b/test/controllers/api/v1/address_transactions_controller_test.rb @@ -150,6 +150,8 @@ class AddressTransactionsControllerTest < ActionDispatch::IntegrationTest income is_cellbase transaction_hash + created_at + create_timestamp ).sort, response_tx_transaction["attributes"].keys.sort end diff --git a/test/controllers/api/v1/address_udt_transactions_controller_test.rb b/test/controllers/api/v1/address_udt_transactions_controller_test.rb index b15b6ea70..96499c036 100644 --- a/test/controllers/api/v1/address_udt_transactions_controller_test.rb +++ b/test/controllers/api/v1/address_udt_transactions_controller_test.rb @@ -94,7 +94,7 @@ class AddressUdtTransactionsControllerTest < ActionDispatch::IntegrationTest response_tx_transaction = json["data"].first - assert_equal %w(block_number block_timestamp display_inputs display_inputs_count display_outputs display_outputs_count income is_cellbase transaction_hash).sort, response_tx_transaction["attributes"].keys.sort + assert_equal %w(block_number block_timestamp display_inputs display_inputs_count display_outputs display_outputs_count income is_cellbase transaction_hash created_at create_timestamp).sort, response_tx_transaction["attributes"].keys.sort end test "should return error object when no records found by id" do diff --git a/test/controllers/api/v1/block_transactions_controller_test.rb b/test/controllers/api/v1/block_transactions_controller_test.rb index 0a074f0fa..99763ec8d 100644 --- a/test/controllers/api/v1/block_transactions_controller_test.rb +++ b/test/controllers/api/v1/block_transactions_controller_test.rb @@ -102,7 +102,7 @@ class BlockTransactionsControllerTest < ActionDispatch::IntegrationTest assert_equal %w( block_number block_timestamp display_inputs display_inputs_count display_outputs display_outputs_count - income is_cellbase transaction_hash + income is_cellbase transaction_hash created_at create_timestamp ).sort, response_tx_transaction["attributes"].keys.sort end diff --git a/test/controllers/api/v1/contract_transactions_controller_test.rb b/test/controllers/api/v1/contract_transactions_controller_test.rb index f937b97ee..7a938c4be 100644 --- a/test/controllers/api/v1/contract_transactions_controller_test.rb +++ b/test/controllers/api/v1/contract_transactions_controller_test.rb @@ -59,7 +59,7 @@ class ContractTransactionsControllerTest < ActionDispatch::IntegrationTest response_tx_transaction = json["data"].first - assert_equal %w(block_number block_timestamp display_inputs display_inputs_count display_outputs display_outputs_count income is_cellbase transaction_hash).sort, response_tx_transaction["attributes"].keys.sort + assert_equal %w(block_number block_timestamp display_inputs display_inputs_count display_outputs display_outputs_count income is_cellbase transaction_hash created_at create_timestamp).sort, response_tx_transaction["attributes"].keys.sort end test "should return error object when no records found by give contract name" do diff --git a/test/controllers/api/v1/udt_transactions_controller_test.rb b/test/controllers/api/v1/udt_transactions_controller_test.rb index feeabb370..2c3fea165 100644 --- a/test/controllers/api/v1/udt_transactions_controller_test.rb +++ b/test/controllers/api/v1/udt_transactions_controller_test.rb @@ -90,7 +90,7 @@ class UdtTransactionsControllerTest < ActionDispatch::IntegrationTest response_tx_transaction = json["data"].first assert_equal %w( - block_number block_timestamp display_inputs display_inputs_count + block_number block_timestamp display_inputs display_inputs_count created_at create_timestamp display_outputs display_outputs_count income is_cellbase transaction_hash ).sort, response_tx_transaction["attributes"].keys.sort