Skip to content

Commit

Permalink
Merge pull request #1951 from nervosnetwork/testnet
Browse files Browse the repository at this point in the history
Deploy to mainnet
  • Loading branch information
zmcNotafraid authored Jun 12, 2024
2 parents a5ace97 + 0e8bf15 commit 1381de1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v2/ckb_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def display_outputs
expires_in 15.seconds, public: true, must_revalidate: true

if @ckb_transaction.is_cellbase
cell_outputs = @ckb_transaction.cellbase_display_outputs.sort_by { |output| output[:id] }
cell_outputs = @ckb_transaction.cellbase_display_outputs.sort_by { |output| output[:id].to_i }
cell_outputs = Kaminari.paginate_array(cell_outputs).page(@page).per(@page_size)
total_count = cell_outputs.total_count
else
Expand Down
35 changes: 30 additions & 5 deletions app/controllers/api/v2/scripts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,26 @@ def referring_cells
head :not_found and return if @contract.blank?

expires_in 15.seconds, public: true, must_revalidate: true, stale_while_revalidate: 5.seconds
@referring_cells =
if @contract.referring_cells_count.zero?
CellOutput.none
else
@contract.referring_cell_outputs.live.page(@page).per(@page_size)

if @contract.referring_cells_count.zero?
@referring_cells = CellOutput.none
else
scope = @contract.referring_cell_outputs.live
if params[:args].present?
type_script = TypeScript.find_by(args: params[:args])
scope = scope.where(cell_outputs: { type_script_id: type_script.id })
end
if params[:address_hash].present?
address = Addresses::Explore.run!(key: params[:address_hash])
scope = if address.is_a?(NullAddress)
CellOutput.none
else
scope.where(cell_outputs: { address_id: address.map(&:id) })
end
end

@referring_cells = sort_referring_cells(scope).page(@page).per(@page_size)
end
end

private
Expand Down Expand Up @@ -88,6 +102,17 @@ def find_script
@contract = Contract.find_by(code_hash: params[:code_hash],
hash_type: params[:hash_type])
end

def sort_referring_cells(records)
sort, order = params.fetch(:sort, "block_timestamp.desc").split(".", 2)
sort =
case sort
when "created_time" then "block_timestamp"
else "block_timestamp"
end
order = "asc" unless order&.match?(/^(asc|desc)$/i)
records.order("#{sort} #{order}")
end
end
end
end
2 changes: 1 addition & 1 deletion app/models/bitcoin_annotation.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class BitcoinAnnotation < ApplicationRecord
belongs_to :ckb_transaction

enum :leap_direction, %i[in withinBTC]
enum :leap_direction, %i[in withinBTC leapoutBTC]
enum :transfer_step, %i[isomorphic unlock]
end

Expand Down
1 change: 1 addition & 0 deletions app/serializers/address_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class AddressSerializer
decimal: udt_account.decimal.to_s,
amount: udt_account.amount.to_s,
type_hash: udt_account.type_hash,
udt_icon_file: udt_account.udt_icon_file,
udt_type: udt_account.udt_type,
udt_type_script: udt_account.udt&.type_script,
}
Expand Down
2 changes: 2 additions & 0 deletions app/workers/bitcoin_transaction_detect_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def annotation_workflow_attributes(transaction)
end
elsif input_lock_types == ["btc_time"]
["in", "unlock"]
elsif [["btc_time", "rgbpp"], ["btc_time"]].include?(output_lock_types)
["leapoutBTC", "isomorphic"]
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/models/address_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ class AddressTest < ActiveSupport::TestCase
CkbSync::Api.any_instance.stubs(:calculate_dao_maximum_withdraw).returns("0x48e7b453400")
address = create(:address, is_depositor: true)
deposit_block = create(:block, :with_block_hash,
dao: "0xea43d76640436a33337e7de7ee60240035099074a869fc0000165f8ab3750207")
dao: "0xea43d76640436a33337e7de7ee60240035099074a869fc0000165f8ab3750207", number: 100)
deposit_tx = create(:ckb_transaction, block: deposit_block)
previous_output_block = create(:block, :with_block_hash,
dao: "0x28fbce93e82cbd2ff345ba74f2ba2300b0cd2c97f2953a000060983e29c50007")
dao: "0x28fbce93e82cbd2ff345ba74f2ba2300b0cd2c97f2953a000060983e29c50007", number: 101)
previous_output_tx = create(:ckb_transaction, block: previous_output_block)
create(:cell_output, block: previous_output_block,
capacity: 50000 * 10**8,
Expand All @@ -132,7 +132,7 @@ class AddressTest < ActiveSupport::TestCase
occupied_capacity: 6100000000,
dao: previous_output_block.dao)
nervos_dao_withdrawing_block = create(:block, :with_block_hash,
dao: "0x9a7a7ce1f34c6a332d147991f0602400aaf7346eb06bfc0000e2abc108760207", timestamp: CkbUtils.time_in_milliseconds(Time.current))
dao: "0x9a7a7ce1f34c6a332d147991f0602400aaf7346eb06bfc0000e2abc108760207", timestamp: CkbUtils.time_in_milliseconds(Time.current), number: 102)
nervos_dao_withdrawing_tx = create(:ckb_transaction,
block: nervos_dao_withdrawing_block)
create(:cell_input, block: nervos_dao_withdrawing_block,
Expand Down

0 comments on commit 1381de1

Please sign in to comment.