From 2d6691091186e7145ec909102ed6afd6f9bad83a Mon Sep 17 00:00:00 2001 From: shaojunda Date: Thu, 26 Nov 2020 16:33:24 +0800 Subject: [PATCH 1/8] chore: upgrade ckb-sdk-ruby to v0.38.1 --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) From 74d7661157de314aad81b04c82022f64f57b753e Mon Sep 17 00:00:00 2001 From: shaojunda Date: Fri, 27 Nov 2020 13:16:40 +0800 Subject: [PATCH 2/8] chore: show query address --- app/controllers/api/v1/address_transactions_controller.rb | 5 ++--- app/serializers/address_serializer.rb | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) 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/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 From c5217102661de7d489b3e87be6b38b9523de52d9 Mon Sep 17 00:00:00 2001 From: shaojunda Date: Fri, 27 Nov 2020 13:17:14 +0800 Subject: [PATCH 3/8] chore: add updated_at --- app/controllers/api/v1/address_dao_transactions_controller.rb | 2 +- app/controllers/api/v1/address_udt_transactions_controller.rb | 2 +- app/controllers/api/v1/block_transactions_controller.rb | 2 +- app/controllers/api/v1/blocks_controller.rb | 4 ++-- app/controllers/api/v1/ckb_transactions_controller.rb | 4 ++-- app/controllers/api/v1/contract_transactions_controller.rb | 2 +- app/controllers/api/v1/udt_transactions_controller.rb | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) 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_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) From 01dd425aec9799167b35b9cbe6db7b3f8552a52b Mon Sep 17 00:00:00 2001 From: shaojunda Date: Fri, 27 Nov 2020 15:41:55 +0800 Subject: [PATCH 4/8] feat: add task to update short acp address --- .../migration/update_short_acp_address.rake | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/tasks/migration/update_short_acp_address.rake 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..f71591999 --- /dev/null +++ b/lib/tasks/migration/update_short_acp_address.rake @@ -0,0 +1,22 @@ +namespace :migration do + task update_short_acp_address: :environment do + address_ids = LockScript.where(code_hash: "0xd369597ff47f29fbc0d47d2e3775370d1250b85140c670e4718af712983a2354").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).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 From 89b8cdf30850e10ce1cd3230092b16bfc6e1bb6f Mon Sep 17 00:00:00 2001 From: shaojunda Date: Fri, 27 Nov 2020 18:22:47 +0800 Subject: [PATCH 5/8] chore: support multiple mode --- lib/tasks/migration/update_short_acp_address.rake | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/tasks/migration/update_short_acp_address.rake b/lib/tasks/migration/update_short_acp_address.rake index f71591999..5f95ea9cd 100644 --- a/lib/tasks/migration/update_short_acp_address.rake +++ b/lib/tasks/migration/update_short_acp_address.rake @@ -1,6 +1,12 @@ namespace :migration do - task update_short_acp_address: :environment do - address_ids = LockScript.where(code_hash: "0xd369597ff47f29fbc0d47d2e3775370d1250b85140c670e4718af712983a2354").pluck(:address_id).uniq + task :update_short_acp_address, [:mode] => :environment do |_, args| + if args[:mode].downcase == "testnet" + code_hash = "0x3419a1c09eb2567f6552ee7a8ecffd64155cffe0f1796e6e61ec088d740c1356" + else + code_hash = "0xd369597ff47f29fbc0d47d2e3775370d1250b85140c670e4718af712983a2354" + end + puts "mode: #{args[: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, From 9cd60ae33f6154bdeaafc941fc05a3a271956240 Mon Sep 17 00:00:00 2001 From: shaojunda Date: Fri, 27 Nov 2020 18:49:25 +0800 Subject: [PATCH 6/8] chore: add query_address to null address --- app/models/null_address.rb | 1 + lib/tasks/migration/update_short_acp_address.rake | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) 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/lib/tasks/migration/update_short_acp_address.rake b/lib/tasks/migration/update_short_acp_address.rake index 5f95ea9cd..3aa4df170 100644 --- a/lib/tasks/migration/update_short_acp_address.rake +++ b/lib/tasks/migration/update_short_acp_address.rake @@ -1,11 +1,12 @@ namespace :migration do task :update_short_acp_address, [:mode] => :environment do |_, args| - if args[:mode].downcase == "testnet" + mode = args[:mode].downcase + if mode == "testnet" code_hash = "0x3419a1c09eb2567f6552ee7a8ecffd64155cffe0f1796e6e61ec088d740c1356" else code_hash = "0xd369597ff47f29fbc0d47d2e3775370d1250b85140c670e4718af712983a2354" end - puts "mode: #{args[:mode]}" + 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({ @@ -16,7 +17,7 @@ namespace :migration do addresses.each do |address| s = address.lock_script lock = CKB::Types::Script.new(s.to_node_lock) - short_acp_address = CKB::Address.new(lock).generate + 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) From 17a0b23d9df908262944153458f25a8c0945c49c Mon Sep 17 00:00:00 2001 From: shaojunda Date: Mon, 30 Nov 2020 19:12:13 +0800 Subject: [PATCH 7/8] chore: Bump version to v0.12.1 --- CHANGELOG.md | 14 ++++++++++++++ RELEASENOTES.md | 12 ++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) 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/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 + From 49f9122ecb1ef0b776c25c8d9fd3a26026c8ea73 Mon Sep 17 00:00:00 2001 From: shaojunda Date: Mon, 30 Nov 2020 19:23:29 +0800 Subject: [PATCH 8/8] chore: update test --- test/controllers/api/v1/udt_transactions_controller_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 }