Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy to testnet #1435

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions app/controllers/api/v2/scripts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "jbuilder"

module Api
module V2
class ScriptsController < BaseController
Expand All @@ -8,48 +9,51 @@ class ScriptsController < BaseController
def general_info
head :not_found and return if @script.blank?

render json: {
data: get_script_content(@script)
}
expires_in 15.seconds, public: true, must_revalidate: true, stale_while_revalidate: 5.seconds
render json: { data: get_script_content }
end

def ckb_transactions
head :not_found and return if @script.blank?

expires_in 15.seconds, public: true, must_revalidate: true, stale_while_revalidate: 5.seconds
scope = CellDependency.where(contract_id: @contract.id).order(ckb_transaction_id: :desc)
tx_ids = scope.page(params[:page]).pluck(:ckb_transaction_id)
tx_ids = scope.page(@page).per(@page_size).pluck(:ckb_transaction_id)
@ckb_transactions = CkbTransaction.find(tx_ids)
@total = scope.count
end

def deployed_cells
head :not_found and return if @script.blank? || @script.contract.blank?

expires_in 15.seconds, public: true, must_revalidate: true, stale_while_revalidate: 5.seconds
@deployed_cells = @contract.deployed_cells.page(@page).per(@page_size).fast_page
end

def referring_cells
head :not_found and return if @script.blank?

expires_in 15.seconds, public: true, must_revalidate: true, stale_while_revalidate: 5.seconds
@referring_cells = @contract.referring_cells.page(@page).per(@page_size).fast_page
end

private

def get_script_content(script)
column_name = script.instance_of?(TypeScript) ? "type_script_id" : "lock_script_id"
@my_referring_cells = CellOutput.live.where(column_name => script.id)
@deployed_cells = @contract&.deployed_cell_outputs&.live
def get_script_content
referring_cells = @contract&.referring_cell_outputs
deployed_cells = @contract&.deployed_cell_outputs&.live
transactions = @contract&.cell_dependencies

{
id: script.id,
code_hash: script.code_hash,
hash_type: script.hash_type,
script_type: script.class.to_s,
capacity_of_deployed_cells: @deployed_cells&.sum(:capacity),
capacity_of_referring_cells: @my_referring_cells.sum(:capacity),
count_of_transactions: @contract&.ckb_transactions&.count.to_i,
count_of_deployed_cells: @deployed_cells&.count.to_i,
count_of_referring_cells: @my_referring_cells.size.to_i
id: @script.id,
code_hash: @script.code_hash,
hash_type: @script.hash_type,
script_type: @script.class.to_s,
capacity_of_deployed_cells: deployed_cells&.sum(:capacity),
capacity_of_referring_cells: referring_cells&.sum(:capacity),
count_of_transactions: transactions&.count.to_i,
count_of_deployed_cells: deployed_cells&.count.to_i,
count_of_referring_cells: referring_cells&.count.to_i
}
end

Expand Down
1 change: 1 addition & 0 deletions app/models/contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Contract < ApplicationRecord
has_many :deployed_cells
has_many :deployed_cell_outputs, through: :deployed_cells, source: :cell_output
has_many :referring_cells
has_many :referring_cell_outputs, through: :deployed_cells, source: :cell_output
has_many :cell_dependencies
has_many :ckb_transactions, through: :cell_dependencies

Expand Down
10 changes: 5 additions & 5 deletions app/services/das_indexer_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def reverse_record(ckb_address)
"key": "0x#{manager_addr}"
}
})
data = JSON.parse res.to_s
case data["errno"]
data = JSON.parse(res.to_s)

case data["err_no"]
when 0
return data["data"]["account"]
when 20007
return ""
else
raise data["errmsg"]
raise data["err_msg"] || "Unknown Error"
end

data["data"]["account"]
end
end
2 changes: 1 addition & 1 deletion app/views/api/v2/scripts/ckb_transactions.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ json.data do
json.display_outputs tx.display_outputs
end
json.meta do
json.total @total || @contract.ckb_transactions.count
json.total @total
json.page_size @page_size.to_i
end
end
2 changes: 1 addition & 1 deletion app/views/api/v2/scripts/deployed_cells.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ json.data do
json.type_script_id cell_output.type_script_id
end
json.meta do
json.total @deployed_cells.count
json.total @deployed_cells.total_count
json.page_size @page_size.to_i
end
end
2 changes: 1 addition & 1 deletion lib/tasks/migration/generate_referring_cells.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace :migration do
outputs.each do |output|
progress_bar.increment

contract = output.lock_script.contract
contract = output.lock_script&.contract
contract ||= output.type_script&.contract

next unless contract
Expand Down
Loading