Skip to content

Commit b95b223

Browse files
authored
Merge pull request #566 from nervosnetwork/rc/v0.9.4
[ᚬmaster] Rc/v0.9.4
2 parents 528db01 + 3e2e490 commit b95b223

28 files changed

+813
-797
lines changed

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Style/TrailingCommaInHashLiteral:
4040
Metrics/LineLength:
4141
Enabled: false
4242

43-
Layout/IndentFirstHashElement:
43+
Layout/FirstHashElementIndentation:
4444
EnforcedStyle: consistent
4545

4646
Style/BracesAroundHashParameters:

.rubocop_thoughtbot.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ Style/PerlBackrefs:
289289
Naming/PredicateName:
290290
Description: 'Check the names of predicate methods.'
291291
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark'
292-
NamePrefixBlacklist:
292+
ForbiddenPrefixes:
293293
- is_
294294
Exclude:
295295
- spec/**/*
@@ -403,7 +403,7 @@ Style/WordArray:
403403

404404
# Layout
405405

406-
Layout/AlignParameters:
406+
Layout/ParameterAlignment:
407407
Description: 'Here we check if the parameters on a multi-line method call or definition are aligned.'
408408
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-double-indent'
409409
Enabled: false
@@ -471,7 +471,7 @@ Lint/DeprecatedClassMethods:
471471
Description: 'Check for deprecated class method calls.'
472472
Enabled: false
473473

474-
Lint/DuplicatedKey:
474+
Lint/DuplicateHashKey:
475475
Description: 'Check for duplicate keys in hash literals.'
476476
Enabled: false
477477

@@ -487,7 +487,7 @@ Lint/FormatParameterMismatch:
487487
Description: 'The number of parameters to format/sprint must match the fields.'
488488
Enabled: false
489489

490-
Lint/HandleExceptions:
490+
Lint/SuppressedException:
491491
Description: "Don't suppress exception."
492492
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions'
493493
Enabled: false
@@ -533,7 +533,7 @@ Lint/UnderscorePrefixedVariableName:
533533
Description: 'Do not use prefix `_` for a variable that is used.'
534534
Enabled: false
535535

536-
Lint/UnneededCopDisableDirective:
536+
Lint/RedundantCopDisableDirective:
537537
Description: >-
538538
Checks for rubocop:disable comments that can be removed.
539539
Note: this cop is not disabled when disabling all cops.

CHANGELOG.md

Lines changed: 647 additions & 712 deletions
Large diffs are not rendered by default.

app/controllers/api/v1/address_transactions_controller.rb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ class AddressTransactionsController < ApplicationController
55
before_action :validate_pagination_params, :pagination_params
66

77
def show
8-
address = Address.find_address!(params[:id])
9-
raise Api::V1::Exceptions::AddressNotFoundError if address.is_a?(NullAddress)
8+
@address = Address.find_address!(params[:id])
9+
raise Api::V1::Exceptions::AddressNotFoundError if @address.is_a?(NullAddress)
1010

11-
presented_address = AddressPresenter.new(address)
12-
ckb_transactions = presented_address.ckb_transactions.recent.distinct.page(@page).per(@page_size)
13-
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_transactions, page: @page, page_size: @page_size).call
11+
presented_address = AddressPresenter.new(@address)
12+
@ckb_transactions = presented_address.ckb_transactions.recent.distinct.page(@page).per(@page_size)
13+
@options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: @ckb_transactions, page: @page, page_size: @page_size).call
1414

15-
render json: CkbTransactionSerializer.new(ckb_transactions, options.merge({ params: { previews: true, address: address } }))
15+
render json: json_result
1616
end
1717

1818
private
@@ -32,6 +32,20 @@ def pagination_params
3232
@page = params[:page] || 1
3333
@page_size = params[:page_size] || CkbTransaction.default_per_page
3434
end
35+
36+
def json_result
37+
ckb_transaction_serializer = CkbTransactionSerializer.new(@ckb_transactions, @options.merge({ params: { previews: true, address: @address } }))
38+
39+
if QueryKeyUtils.valid_address?(params[:id])
40+
if @address.address_hash == @address.query_address
41+
ckb_transaction_serializer
42+
else
43+
ckb_transaction_serializer.serialized_json.gsub(@address.address_hash, @address.query_address)
44+
end
45+
else
46+
ckb_transaction_serializer
47+
end
48+
end
3549
end
3650
end
3751
end

app/models/address.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Address < ApplicationRecord
1414

1515
after_commit :flush_cache
1616

17+
attr_accessor :query_address
18+
1719
def lock_script
1820
LockScript.where(address: self).first
1921
end
@@ -36,7 +38,14 @@ def self.cached_find(query_key)
3638
if QueryKeyUtils.valid_hex?(query_key)
3739
find_by(lock_hash: query_key)
3840
else
39-
where(address_hash: query_key).to_a.presence || NullAddress.new(query_key)
41+
lock_hash = CkbUtils.parse_address(query_key).script.compute_hash
42+
address = find_by(lock_hash: lock_hash)
43+
if address.present?
44+
address.query_address = query_key
45+
address
46+
else
47+
NullAddress.new(query_key)
48+
end
4049
end
4150
end
4251
end

app/models/cell_output.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class CellOutput < ApplicationRecord
1616

1717
attribute :tx_hash, :ckb_hash
1818

19-
scope :consumed_after, -> (block_timestamp) { where("consumed_block_timestamp >= ?", block_timestamp) }
20-
scope :consumed_before, -> (block_timestamp) { where("consumed_block_timestamp <= ?", block_timestamp) }
21-
scope :unconsumed_at, -> (block_timestamp) { where("consumed_block_timestamp > ? or consumed_block_timestamp is null", block_timestamp) }
22-
scope :generated_after, -> (block_timestamp) { where("block_timestamp >= ?", block_timestamp) }
23-
scope :generated_before, -> (block_timestamp) { where("block_timestamp <= ?", block_timestamp) }
19+
scope :consumed_after, ->(block_timestamp) { where("consumed_block_timestamp >= ?", block_timestamp) }
20+
scope :consumed_before, ->(block_timestamp) { where("consumed_block_timestamp <= ?", block_timestamp) }
21+
scope :unconsumed_at, ->(block_timestamp) { where("consumed_block_timestamp > ? or consumed_block_timestamp is null", block_timestamp) }
22+
scope :generated_after, ->(block_timestamp) { where("block_timestamp >= ?", block_timestamp) }
23+
scope :generated_before, ->(block_timestamp) { where("block_timestamp <= ?", block_timestamp) }
2424

2525
after_commit :flush_cache
2626

@@ -35,11 +35,12 @@ def node_output
3535
end
3636

3737
def cache_keys
38-
%W(previous_cell_output/#{tx_hash}/#{cell_index} normal_tx_display_inputs_previews_true_#{ckb_transaction_id}
39-
normal_tx_display_inputs_previews_false_#{ckb_transaction_id} normal_tx_display_inputs_previews_true_#{consumed_by_id}
40-
normal_tx_display_inputs_previews_false_#{consumed_by_id} normal_tx_display_outputs_previews_true_#{ckb_transaction_id}
41-
normal_tx_display_outputs_previews_false_#{ckb_transaction_id} normal_tx_display_outputs_previews_true_#{consumed_by_id}
42-
normal_tx_display_outputs_previews_false_#{consumed_by_id}
38+
%W(
39+
previous_cell_output/#{tx_hash}/#{cell_index} normal_tx_display_inputs_previews_true_#{ckb_transaction_id}
40+
normal_tx_display_inputs_previews_false_#{ckb_transaction_id} normal_tx_display_inputs_previews_true_#{consumed_by_id}
41+
normal_tx_display_inputs_previews_false_#{consumed_by_id} normal_tx_display_outputs_previews_true_#{ckb_transaction_id}
42+
normal_tx_display_outputs_previews_false_#{ckb_transaction_id} normal_tx_display_outputs_previews_true_#{consumed_by_id}
43+
normal_tx_display_outputs_previews_false_#{consumed_by_id}
4344
)
4445
end
4546

app/models/ckb_transaction.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class CkbTransaction < ApplicationRecord
1818
scope :recent, -> { order(block_timestamp: :desc) }
1919
scope :cellbase, -> { where(is_cellbase: true) }
2020
scope :normal, -> { where(is_cellbase: false) }
21-
scope :created_after, -> (block_timestamp) { where("block_timestamp >= ?", block_timestamp) }
22-
scope :created_before, -> (block_timestamp) { where("block_timestamp <= ?", block_timestamp) }
21+
scope :created_after, ->(block_timestamp) { where("block_timestamp >= ?", block_timestamp) }
22+
scope :created_before, ->(block_timestamp) { where("block_timestamp <= ?", block_timestamp) }
2323

2424
after_commit :flush_cache
2525
before_destroy :recover_dead_cell
@@ -104,7 +104,8 @@ def attributes_for_dao_input(nervos_dao_withdrawing_cell, is_phase2 = true)
104104
attributes = { compensation_started_block_number: compensation_started_block.number, compensation_ended_block_number: compensation_ended_block.number, compensation_started_timestamp: compensation_started_block.timestamp, compensation_ended_timestamp: compensation_ended_block.timestamp, interest: interest }
105105
if is_phase2
106106
locked_until_block = Block.select(:number, :timestamp).find(block_id)
107-
attributes.merge!({ locked_until_block_number: locked_until_block.number, locked_until_block_timestamp: locked_until_block.timestamp })
107+
attributes[:locked_until_block_number] = locked_until_block.number
108+
attributes[:locked_until_block_timestamp] = locked_until_block.timestamp
108109
end
109110

110111
CkbUtils.hash_value_to_s(attributes)

app/models/dao_contract.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ def estimated_apc(deposit_epoch = tip_block_fraction_epoch, deposited_epochs = E
3535
checkpoints.unshift(start_epoch_number.to_i) if checkpoints.empty? || checkpoints[0] > start_epoch_number
3636
checkpoints.push(scaled_end_epoch_number.to_i) if checkpoints.last < scaled_end_epoch_number
3737
end_epoch_numbers = checkpoints[1..-1]
38-
rates = end_epoch_numbers.each_with_index.map do |inner_end_epoch_number, index|
39-
epoch_index = deposit_epoch.index * 1800 / deposit_epoch.length
40-
start_epoch = OpenStruct.new(number: checkpoints[index], index: epoch_index, length: 1800)
41-
end_epoch = OpenStruct.new(number: inner_end_epoch_number, index: epoch_index, length: 1800)
42-
rate(start_epoch, end_epoch)
43-
end
38+
rates =
39+
end_epoch_numbers.each_with_index.map do |inner_end_epoch_number, index|
40+
epoch_index = deposit_epoch.index * 1800 / deposit_epoch.length
41+
start_epoch = OpenStruct.new(number: checkpoints[index], index: epoch_index, length: 1800)
42+
end_epoch = OpenStruct.new(number: inner_end_epoch_number, index: epoch_index, length: 1800)
43+
rate(start_epoch, end_epoch)
44+
end
4445
rate = rates.reduce(1) { |memo, rate| memo * (1 + rate) } - 1
4546
(rate * 100) / ratio
4647
end
@@ -89,7 +90,7 @@ def latest_daily_statistic
8990

9091
def alpha(start_epoch_number)
9192
i = ((start_epoch_number + 1) / EPOCHS_IN_PERIOD).floor
92-
p = PRIMARY_ISSUANCE_PER_YEAR_BASE / 2 ** i / 2190
93+
p = PRIMARY_ISSUANCE_PER_YEAR_BASE / 2**i / 2190
9394
p / SECONDARY_ISSUANCE_PER_EPOCH
9495
end
9596

@@ -105,8 +106,8 @@ def total_issuance(start_epoch)
105106

106107
def primary_issuance(start_epoch)
107108
epochs = (start_epoch.number / EPOCHS_IN_PERIOD).floor
108-
epochs.times.reduce(GENESIS_ISSUANCE) { |memo, item| memo + (ANNUAL_PRIMARY_ISSUANCE_BASE * YEARS_IN_PERIOD) / 2 ** item } \
109-
+ (ANNUAL_PRIMARY_ISSUANCE_BASE * ((start_epoch.number + 1 - epochs * EPOCHS_IN_PERIOD) / EPOCHS_IN_ONE_NATURAL_YEAR)) / 2 ** epochs
109+
epochs.times.reduce(GENESIS_ISSUANCE) { |memo, item| memo + (ANNUAL_PRIMARY_ISSUANCE_BASE * YEARS_IN_PERIOD) / 2**item } \
110+
+ (ANNUAL_PRIMARY_ISSUANCE_BASE * ((start_epoch.number + 1 - epochs * EPOCHS_IN_PERIOD) / EPOCHS_IN_ONE_NATURAL_YEAR)) / 2**epochs
110111
end
111112

112113
def secondary_issuance(start_epoch)

app/presenters/address_presenter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def id
88
end
99

1010
def address_hash
11-
object.first.address_hash
11+
object.first.query_address
1212
end
1313

1414
def balance

app/services/charts/block_statistic_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def call
1717
end
1818

1919
private
20+
2021
attr_reader :block_number
2122
end
2223
end

0 commit comments

Comments
 (0)