diff --git a/CHANGELOG.md b/CHANGELOG.md index 8afd51a89..2e6852eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +# [v0.12.1](https://github.com/nervosnetwork/ckb-explorer/compare/v0.12.0...v0.12.1) (2020-11-30) + + +### Bug Fixes + +[#749](https://github.com/nervosnetwork/ckb-explorer/pull/749): fix dao contract cache bug + + +### Features + +[#747](https://github.com/nervosnetwork/ckb-explorer/pull/747): support short acp address + + + # [v0.12.0](https://github.com/nervosnetwork/ckb-explorer/compare/v0.11.2...v0.12.0) (2020-11-10) diff --git a/Gemfile.lock b/Gemfile.lock index 0226e4845..843aa6e5e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,10 +8,10 @@ GIT GIT remote: https://github.com/nervosnetwork/ckb-sdk-ruby.git - revision: dfe4c30f3be49f89d2c8d88170a199cfa053d4fe + revision: bbe04b45aabcc112c2c13540a68ded989cc2eb00 branch: develop specs: - ckb-sdk-ruby (0.37.0) + ckb-sdk-ruby (0.38.1) bitcoin-secp256k1 (~> 0.5.2) net-http-persistent (~> 3.1.0) rbnacl (~> 7.1.1) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 47a732daa..ee49f53ee 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,8 +1,12 @@ -### Adapted CKB Version -[ckb 0.25.1](https://github.com/nervosnetwork/ckb/releases/tag/v0.25.1) and above +# [v0.12.1](https://github.com/nervosnetwork/ckb-explorer/compare/v0.12.0...v0.12.1) (2020-11-30) + + +### Bug Fixes + +[#749](https://github.com/nervosnetwork/ckb-explorer/pull/749): fix dao contract cache bug -# [v0.12.0](https://github.com/nervosnetwork/ckb-explorer/compare/v0.11.2...v0.12.0) (2020-11-10) ### Features -* [#739](https://github.com/nervosnetwork/ckb-explorer/pull/739): support querying transactions in the transaction pool \ No newline at end of file +[#747](https://github.com/nervosnetwork/ckb-explorer/pull/747): support short acp address + diff --git a/app/controllers/api/v1/address_dao_transactions_controller.rb b/app/controllers/api/v1/address_dao_transactions_controller.rb index 6e4b0466e..f7a25a068 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).recent.page(@page).per(@page_size) + 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) 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 aa8a0cdf0..8031e4397 100644 --- a/app/controllers/api/v1/address_transactions_controller.rb +++ b/app/controllers/api/v1/address_transactions_controller.rb @@ -8,10 +8,9 @@ def show @address = Address.find_address!(params[:id]) raise Api::V1::Exceptions::AddressNotFoundError if @address.is_a?(NullAddress) - @ckb_transactions = @address.custom_ckb_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase).recent.page(@page).per(@page_size) - + @ckb_transactions = @address.custom_ckb_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at).recent.page(@page).per(@page_size) json = - Rails.cache.realize(@ckb_transactions.cache_key, version: @ckb_transactions.cache_version) do + Rails.cache.realize("#{@ckb_transactions.cache_key}/#{@address.query_address}", version: @ckb_transactions.cache_version) do records_counter = RecordCounters::AddressTransactions.new(@address) @options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: @ckb_transactions, page: @page, page_size: @page_size, records_counter: records_counter).call json_result diff --git a/app/controllers/api/v1/address_udt_transactions_controller.rb b/app/controllers/api/v1/address_udt_transactions_controller.rb index f2ec5b158..f10a52de8 100644 --- a/app/controllers/api/v1/address_udt_transactions_controller.rb +++ b/app/controllers/api/v1/address_udt_transactions_controller.rb @@ -12,7 +12,7 @@ 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).recent.page(@page).per(@page_size) + 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) 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 5302bb349..1dd7191bc 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).order(:id).page(@page).per(@page_size) + ckb_transactions = block.ckb_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at).order(:id).page(@page).per(@page_size) json = Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version) do records_counter = RecordCounters::BlockTransactions.new(block) diff --git a/app/controllers/api/v1/blocks_controller.rb b/app/controllers/api/v1/blocks_controller.rb index 20a4ca1ae..dd4fc169c 100644 --- a/app/controllers/api/v1/blocks_controller.rb +++ b/app/controllers/api/v1/blocks_controller.rb @@ -6,13 +6,13 @@ class BlocksController < ApplicationController def index if from_home_page? - blocks = Block.recent.limit(ENV["HOMEPAGE_BLOCK_RECORDS_COUNT"].to_i).select(:id, :miner_hash, :number, :timestamp, :reward, :ckb_transactions_count, :live_cell_changes) + blocks = Block.recent.limit(ENV["HOMEPAGE_BLOCK_RECORDS_COUNT"].to_i).select(:id, :miner_hash, :number, :timestamp, :reward, :ckb_transactions_count, :live_cell_changes, :updated_at) json = Rails.cache.realize(blocks.cache_key, version: blocks.cache_version, race_condition_ttl: 3.seconds) do BlockListSerializer.new(blocks).serialized_json end else - blocks = Block.recent.select(:id, :miner_hash, :number, :timestamp, :reward, :ckb_transactions_count, :live_cell_changes).page(@page).per(@page_size) + blocks = Block.recent.select(:id, :miner_hash, :number, :timestamp, :reward, :ckb_transactions_count, :live_cell_changes, :updated_at).page(@page).per(@page_size) json = Rails.cache.realize(blocks.cache_key, version: blocks.cache_version, race_condition_ttl: 3.seconds) do records_counter = RecordCounters::Blocks.new diff --git a/app/controllers/api/v1/ckb_transactions_controller.rb b/app/controllers/api/v1/ckb_transactions_controller.rb index 55154c550..32f4b6423 100644 --- a/app/controllers/api/v1/ckb_transactions_controller.rb +++ b/app/controllers/api/v1/ckb_transactions_controller.rb @@ -6,14 +6,14 @@ class CkbTransactionsController < ApplicationController def index if from_home_page? - ckb_transactions = CkbTransaction.recent.normal.limit(ENV["HOMEPAGE_TRANSACTIONS_RECORDS_COUNT"].to_i).select(:id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved) + ckb_transactions = CkbTransaction.recent.normal.limit(ENV["HOMEPAGE_TRANSACTIONS_RECORDS_COUNT"].to_i).select(:id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved, :updated_at) json = Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version, race_condition_ttl: 3.seconds) do CkbTransactionListSerializer.new(ckb_transactions).serialized_json end render json: json else - ckb_transactions = CkbTransaction.recent.normal.page(@page).per(@page_size).select(:id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved) + ckb_transactions = CkbTransaction.recent.normal.page(@page).per(@page_size).select(:id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved, :updated_at) json = Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version, race_condition_ttl: 3.seconds) do records_counter = RecordCounters::Transactions.new diff --git a/app/controllers/api/v1/contract_transactions_controller.rb b/app/controllers/api/v1/contract_transactions_controller.rb index bc99141b3..a58c9053b 100644 --- a/app/controllers/api/v1/contract_transactions_controller.rb +++ b/app/controllers/api/v1/contract_transactions_controller.rb @@ -7,7 +7,7 @@ def show raise Api::V1::Exceptions::ContractNotFoundError if params[:id] != DaoContract::CONTRACT_NAME dao_contract = DaoContract.default_contract - ckb_transactions = dao_contract.ckb_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase).recent.page(@page).per(@page_size) + ckb_transactions = dao_contract.ckb_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at).recent.page(@page).per(@page_size) json = Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version) do records_counter = RecordCounters::DaoTransactions.new(dao_contract) diff --git a/app/controllers/api/v1/udt_transactions_controller.rb b/app/controllers/api/v1/udt_transactions_controller.rb index 1d4f99538..b54198a7d 100644 --- a/app/controllers/api/v1/udt_transactions_controller.rb +++ b/app/controllers/api/v1/udt_transactions_controller.rb @@ -6,7 +6,7 @@ class UdtTransactionsController < ApplicationController def show udt = Udt.find_by!(type_hash: params[:id], published: true) - ckb_transactions = udt.ckb_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase).recent.page(@page).per(@page_size) + ckb_transactions = udt.ckb_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at).recent.page(@page).per(@page_size) json = Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version) do records_counter = RecordCounters::UdtTransactions.new(udt) diff --git a/app/models/null_address.rb b/app/models/null_address.rb index caa891b4c..aa02ba04e 100644 --- a/app/models/null_address.rb +++ b/app/models/null_address.rb @@ -68,4 +68,5 @@ def unclaimed_compensation end alias_method :cached_lock_script, :lock_script + alias_method :query_address, :address_hash end diff --git a/app/serializers/address_serializer.rb b/app/serializers/address_serializer.rb index 4d3abffe3..536c318b0 100644 --- a/app/serializers/address_serializer.rb +++ b/app/serializers/address_serializer.rb @@ -1,7 +1,11 @@ class AddressSerializer include FastJsonapi::ObjectSerializer - attributes :address_hash, :lock_info + attributes :lock_info + + attribute :address_hash do |object| + object.query_address + end attribute :balance do |object| object.balance.to_s end diff --git a/lib/tasks/migration/update_short_acp_address.rake b/lib/tasks/migration/update_short_acp_address.rake new file mode 100644 index 000000000..3aa4df170 --- /dev/null +++ b/lib/tasks/migration/update_short_acp_address.rake @@ -0,0 +1,29 @@ +namespace :migration do + task :update_short_acp_address, [:mode] => :environment do |_, args| + mode = args[:mode].downcase + if mode == "testnet" + code_hash = "0x3419a1c09eb2567f6552ee7a8ecffd64155cffe0f1796e6e61ec088d740c1356" + else + code_hash = "0xd369597ff47f29fbc0d47d2e3775370d1250b85140c670e4718af712983a2354" + end + puts "mode: #{mode}" + address_ids = LockScript.where(code_hash: code_hash).pluck(:address_id).uniq + addresses = Address.where(id: address_ids) + progress_bar = ProgressBar.create({ + total: addresses.count, + format: "%e %B %p%% %c/%C" + }) + + addresses.each do |address| + s = address.lock_script + lock = CKB::Types::Script.new(s.to_node_lock) + short_acp_address = CKB::Address.new(lock, mode: mode).generate + puts "full address: #{address.address_hash}, short acp address: #{short_acp_address}" + address.update(address_hash: short_acp_address) + + progress_bar.increment + end + + puts "done" + end +end diff --git a/test/controllers/api/v1/udt_transactions_controller_test.rb b/test/controllers/api/v1/udt_transactions_controller_test.rb index 753fc53cf..8d939dec3 100644 --- a/test/controllers/api/v1/udt_transactions_controller_test.rb +++ b/test/controllers/api/v1/udt_transactions_controller_test.rb @@ -148,7 +148,7 @@ class Api::V1::UdtTransactionsControllerTest < ActionDispatch::IntegrationTest page = 2 page_size = 10 udt = create(:udt, :with_transactions, published: true) - udt_ckb_transactions = udt.ckb_transactions.order(block_timestamp: :desc).page(page).per(page_size) + udt_ckb_transactions = udt.ckb_transactions.order("block_timestamp desc nulls last, id desc").page(page).per(page_size) valid_get api_v1_udt_transaction_url(udt.type_hash), params: { page: page }