Skip to content

Commit

Permalink
Merge pull request #712 from nervosnetwork/rc/v0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda authored Jul 30, 2020
2 parents 28555b3 + e5059cd commit 455a466
Show file tree
Hide file tree
Showing 42 changed files with 1,377 additions and 224 deletions.
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Environment**

- **Operating system**: Linux / macOS / Windows
- **Arch**: x64
- **Installation**: GitHub Release

**Describe the bug**

_Your issue description goes here below. Try to include **actual** vs. **expected behavior** and **steps to reproduce** the issue._

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. excite come command
3. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: 'enhancement'
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/question-issue-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Question issue template
about: Ask a question
title: ''
labels: help wanted
assignees: ''

---


20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
# [v0.10.1](https://github.com/shaojunda/ckb-explorer/compare/v0.10.0...v0.10.1) (2020-07-17)
# [v0.11.0](https://github.com/nervosnetwork/ckb-explorer/compare/v0.10.1...v0.11.0) (2020-07-30)


### Bug Fixes
* [#703](https://github.com/nervosnetwork/ckb-explorer/pull/703): fix address nil when update udt accounts
* [#705](https://github.com/nervosnetwork/ckb-explorer/pull/705): fix zero division

### Performance Improvements

* [#697](https://github.com/nervosnetwork/ckb-explorer/pull/697): perf xxx transactions list
* perf address_dao_transactions
* perf address_transactions
* perf address_udt_transactions
* perf block_udt_transactions
* perf contract_transactions
* perf udt_transactions


# [v0.10.1](https://github.com/nervosnetwork/ckb-explorer/compare/v0.10.0...v0.10.1) (2020-07-17)


### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ GEM
i18n (1.8.3)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.2)
json (2.2.0)
json (2.3.1)
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
Expand Down
12 changes: 8 additions & 4 deletions app/controllers/api/v1/address_dao_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ 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.recent.page(@page).per(@page_size)
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_dao_transactions, page: @page, page_size: @page_size).call

render json: CkbTransactionSerializer.new(ckb_dao_transactions, options.merge({ params: { previews: true } }))
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)
json =
Rails.cache.realize(ckb_dao_transactions.cache_key, version: ckb_dao_transactions.cache_version) do
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_dao_transactions, page: @page, page_size: @page_size).call
CkbTransactionsSerializer.new(ckb_dao_transactions, options.merge(params: { previews: true })).serialized_json
end

render json: json
end

private
Expand Down
17 changes: 11 additions & 6 deletions app/controllers/api/v1/address_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ def show
@address = Address.find_address!(params[:id])
raise Api::V1::Exceptions::AddressNotFoundError if @address.is_a?(NullAddress)

@ckb_transactions = @address.custom_ckb_transactions.recent.page(@page).per(@page_size)
@options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: @ckb_transactions, page: @page, page_size: @page_size).call
@ckb_transactions = @address.custom_ckb_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase).recent.page(@page).per(@page_size)

render json: json_result
json =
Rails.cache.realize(@ckb_transactions.cache_key, version: @ckb_transactions.cache_version) do
@options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: @ckb_transactions, page: @page, page_size: @page_size).call
json_result
end

render json: json
end

private
Expand All @@ -33,16 +38,16 @@ def pagination_params
end

def json_result
ckb_transaction_serializer = CkbTransactionSerializer.new(@ckb_transactions, @options.merge({ params: { previews: true, address: @address } }))
ckb_transaction_serializer = CkbTransactionsSerializer.new(@ckb_transactions, @options.merge(params: { previews: true, address: @address }))

if QueryKeyUtils.valid_address?(params[:id])
if @address.address_hash == @address.query_address
ckb_transaction_serializer
ckb_transaction_serializer.serialized_json
else
ckb_transaction_serializer.serialized_json.gsub(@address.address_hash, @address.query_address)
end
else
ckb_transaction_serializer
ckb_transaction_serializer.serialized_json
end
end
end
Expand Down
12 changes: 8 additions & 4 deletions app/controllers/api/v1/address_udt_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ 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(params[:type_hash]).recent.page(@page).per(@page_size)
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_dao_transactions, page: @page, page_size: @page_size).call

render json: CkbTransactionSerializer.new(ckb_dao_transactions, options.merge({ params: { previews: true } }))
ckb_dao_transactions = address.ckb_udt_transactions(params[:type_hash]).select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase).recent.page(@page).per(@page_size)
json =
Rails.cache.realize(ckb_dao_transactions.cache_key, version: ckb_dao_transactions.cache_version) do
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_dao_transactions, page: @page, page_size: @page_size).call
CkbTransactionsSerializer.new(ckb_dao_transactions, options.merge(params: { previews: true })).serialized_json
end

render json: json
end

private
Expand Down
10 changes: 7 additions & 3 deletions app/controllers/api/v1/block_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ class BlockTransactionsController < ApplicationController

def show
block = Block.find_by!(block_hash: params[:id])
ckb_transactions = block.ckb_transactions.order(:id).page(@page).per(@page_size)
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_transactions, page: @page, page_size: @page_size).call
ckb_transactions = block.ckb_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase).order(:id).page(@page).per(@page_size)
json =
Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version) do
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_transactions, page: @page, page_size: @page_size).call
CkbTransactionsSerializer.new(ckb_transactions, options.merge(params: { previews: true })).serialized_json
end

render json: CkbTransactionSerializer.new(ckb_transactions, options.merge({ params: { previews: true } }))
render json: json
rescue ActiveRecord::RecordNotFound
raise Api::V1::Exceptions::BlockTransactionsNotFoundError
end
Expand Down
10 changes: 7 additions & 3 deletions app/controllers/api/v1/contract_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ def show
raise Api::V1::Exceptions::ContractNotFoundError if params[:id] != DaoContract::CONTRACT_NAME

dao_contract = DaoContract.default_contract
ckb_transactions = dao_contract.ckb_transactions.distinct.recent.page(@page).per(@page_size)
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_transactions, page: @page, page_size: @page_size).call
ckb_transactions = dao_contract.ckb_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase).recent.page(@page).per(@page_size)
json =
Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version) do
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_transactions, page: @page, page_size: @page_size).call
CkbTransactionsSerializer.new(ckb_transactions, options.merge(params: { previews: true })).serialized_json
end

render json: CkbTransactionSerializer.new(ckb_transactions, options.merge({ params: { previews: true } }))
render json: json
end

private
Expand Down
54 changes: 31 additions & 23 deletions app/controllers/api/v1/udt_transactions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
class Api::V1::UdtTransactionsController < ApplicationController
before_action :validate_query_params
before_action :validate_pagination_params, :pagination_params
module Api
module V1
class UdtTransactionsController < ApplicationController
before_action :validate_query_params
before_action :validate_pagination_params, :pagination_params

def show
udt = Udt.find_by!(type_hash: params[:id], published: true)
ckb_transactions = udt.ckb_transactions.recent.page(@page).per(@page_size)
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_transactions, page: @page, page_size: @page_size).call
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)
json =
Rails.cache.realize(ckb_transactions.cache_key, version: ckb_transactions.cache_version) do
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_transactions, page: @page, page_size: @page_size).call
CkbTransactionsSerializer.new(ckb_transactions, options.merge(params: { previews: true })).serialized_json
end

render json: CkbTransactionSerializer.new(ckb_transactions, options.merge({ params: { previews: true } }))
rescue ActiveRecord::RecordNotFound
raise Api::V1::Exceptions::UdtNotFoundError
end
render json: json
rescue ActiveRecord::RecordNotFound
raise Api::V1::Exceptions::UdtNotFoundError
end

private
private

def validate_query_params
validator = Validations::Udt.new(params)
def validate_query_params
validator = Validations::Udt.new(params)

if validator.invalid?
errors = validator.error_object[:errors]
status = validator.error_object[:status]
if validator.invalid?
errors = validator.error_object[:errors]
status = validator.error_object[:status]

render json: errors, status: status
end
end
render json: errors, status: status
end
end

def pagination_params
@page = params[:page] || 1
@page_size = params[:page_size] || CkbTransaction.default_per_page
def pagination_params
@page = params[:page] || 1
@page_size = params[:page_size] || CkbTransaction.default_per_page
end
end
end
end
40 changes: 6 additions & 34 deletions app/models/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,18 @@ class Address < ApplicationRecord
attr_accessor :query_address

def custom_ckb_transactions
ckb_transaction_ids = account_books.select(:ckb_transaction_id).distinct
CkbTransaction.where(id: ckb_transaction_ids)
CkbTransaction.where("contained_address_ids @> array[?]::bigint[]", [id])
end

def ckb_dao_transactions
ckb_transaction_ids = cell_outputs.where(cell_type: %w(nervos_dao_deposit nervos_dao_withdrawing)).select("ckb_transaction_id").distinct
CkbTransaction.where(id: ckb_transaction_ids)
CkbTransaction.where("contained_address_ids @> array[?]::bigint[]", [id]).where("tags @> array[?]::varchar[]", ["dao"])
end

def ckb_udt_transactions(type_hash)
sql =
<<-SQL
SELECT
generated_by_id ckb_transaction_id
FROM
cell_outputs
WHERE
address_id = #{id}
AND
cell_type = #{CellOutput::cell_types['udt']}
AND
type_hash = '#{type_hash}'
UNION
SELECT
consumed_by_id ckb_transaction_id
FROM
cell_outputs
WHERE
address_id = #{id}
AND
cell_type = #{CellOutput::cell_types['udt']}
AND
type_hash = '#{type_hash}'
AND
consumed_by_id is not null
SQL
ckb_transaction_ids = CellOutput.select("ckb_transaction_id").from("(#{sql}) as cell_outputs")
CkbTransaction.where(id: ckb_transaction_ids.distinct)
udt = Udt.where(type_hash: type_hash).select(:id).first
return [] if udt.blank?

CkbTransaction.where("contained_address_ids @> array[?]::bigint[]", [id]).where("contained_udt_ids @> array[?]::bigint[]", [udt.id])
end

def lock_info
Expand Down
Loading

0 comments on commit 455a466

Please sign in to comment.