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 mainnet #1556

Merged
merged 15 commits into from
Jan 16, 2024
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
49 changes: 6 additions & 43 deletions app/controllers/api/v1/ckb_transactions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
module Api
module V1
class CkbTransactionsController < ApplicationController
before_action :validate_query_params,
only: %i[show display_inputs display_outputs]
before_action :find_transaction,
only: %i[show display_inputs display_outputs]
before_action :validate_pagination_params, :pagination_params,
only: %i[index display_inputs display_outputs]
before_action :validate_query_params, only: %i[show]
before_action :find_transaction,only: %i[show]
before_action :validate_pagination_params, :pagination_params, only: %i[index]

def index
if from_home_page?
Expand Down Expand Up @@ -109,43 +106,9 @@ def query
def show
expires_in 10.seconds, public: true, must_revalidate: true

render json: CkbTransactionSerializer.new(@ckb_transaction)
end

def display_inputs
expires_in 1.hour, public: true, must_revalidate: true

if @ckb_transaction.is_cellbase
cell_inputs = @ckb_transaction.cellbase_display_inputs
total_count = cell_inputs.count
else
cell_inputs = @ckb_transaction.cell_inputs.order(id: :asc).
page(@page).per(@page_size).fast_page
total_count = cell_inputs.total_count
cell_inputs = @ckb_transaction.normal_tx_display_inputs(cell_inputs)
end

render json: { data: cell_inputs,
meta: { total: total_count,
page_size: @page_size.to_i } }
end

def display_outputs
expires_in 1.hour, public: true, must_revalidate: true

if @ckb_transaction.is_cellbase
cell_outputs = @ckb_transaction.cellbase_display_outputs
total_count = cell_outputs.count
else
cell_outputs = @ckb_transaction.outputs.order(id: :asc).
page(@page).per(@page_size).fast_page
total_count = cell_outputs.total_count
cell_outputs = @ckb_transaction.normal_tx_display_outputs(cell_outputs)
end

render json: { data: cell_outputs,
meta: { total: total_count,
page_size: @page_size.to_i } }
render json: CkbTransactionSerializer.new(@ckb_transaction, {
params: { display_cells: params.fetch(:display_cells, true)
}})
end

private
Expand Down
70 changes: 70 additions & 0 deletions app/controllers/api/v1/omiga_inscriptions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
module Api
module V1
class OmigaInscriptionsController < ApplicationController
before_action :validate_query_params, only: :show
before_action :validate_pagination_params, :pagination_params,
only: :index

def index
udts = Udt.omiga_inscription

if stale?(udts)
udts = sort_udts(udts).page(@page).per(@page_size).fast_page
options = FastJsonapi::PaginationMetaGenerator.new(
request:,
records: udts,
page: @page,
page_size: @page_size,
).call

render json: UdtSerializer.new(udts, options)
end
end

def show
udt = Udt.find_by!(type_hash: params[:id])
render json: UdtSerializer.new(udt)
rescue ActiveRecord::RecordNotFound
raise Api::V1::Exceptions::UdtNotFoundError
end

private

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

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

render json: errors, status:
end
end

def pagination_params
@page = params[:page] || 1
@page_size = params[:page_size] || Udt.default_per_page
end

def sort_udts(records)
sort, order = params.fetch(:sort, "id.desc").split(".", 2)
sort =
case sort
when "created_time" then "block_timestamp"
when "transactions" then "h24_ckb_transactions_count"
else sort
end

if order.nil? || !order.match?(/^(asc|desc)$/i)
order = "asc"
end

if sort == "mint_status"
records.joins(:omiga_inscription_info).order("omiga_inscription_infos.mint_status #{order}")
else
records.order("#{sort} #{order}")
end
end
end
end
end
4 changes: 3 additions & 1 deletion app/controllers/api/v1/udt_queries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ class UdtQueriesController < ApplicationController
def index
udts = Udt.query_by_name_or_symbl(params[:q].downcase)

render json: UdtSerializer.new(udts, { fields: { udt: [:full_name, :symbol, :type_hash, :icon_file] } })
render json: UdtSerializer.new(udts,
{ fields: { udt: %i[full_name symbol
udt_type type_hash icon_file] } })
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/api/v1/udts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def index
end

def update
udt = Udt.find_by!(type_hash: params[:id], published: true)
udt = Udt.find_by!(type_hash: params[:id])
attrs = {
symbol: params[:symbol],
full_name: params[:full_name],
Expand All @@ -34,7 +34,8 @@ def update
icon_file: params[:icon_file],
uan: params[:uan],
display_name: params[:display_name],
email: params[:email]
email: params[:email],
published: true
}
if udt.email.blank?
raise Api::V1::Exceptions::UdtInfoInvalidError.new("Email can't be blank") if params[:email].blank?
Expand Down
57 changes: 56 additions & 1 deletion app/controllers/api/v2/ckb_transactions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module Api
module V2
class CkbTransactionsController < BaseController
# transaction lite info
before_action :set_page_and_page_size, only: %i[display_inputs display_outputs]

def details
ckb_transaction = CkbTransaction.where(tx_hash: params[:id]).order(tx_status: :desc).first
head :not_found and return if ckb_transaction.blank?
Expand All @@ -15,6 +16,55 @@ def details
render json: { data: transfers }
end

def display_inputs
expires_in 1.hour, public: true, must_revalidate: true

ckb_transaction = CkbTransaction.where(tx_hash: params[:id]).order(tx_status: :desc).first
head :not_found and return if ckb_transaction.blank?

if ckb_transaction.is_cellbase
cell_inputs = ckb_transaction.cellbase_display_inputs
total_count = cell_inputs.count
else
cell_inputs = ckb_transaction.cell_inputs.order(id: :asc).
page(@page).per(@page_size).fast_page
total_count = cell_inputs.total_count
cell_inputs = ckb_transaction.normal_tx_display_inputs(cell_inputs)
end

render json: {
data: cell_inputs,
meta: {
total: total_count,
page_size: @page_size.to_i,
},
}
end

def display_outputs
expires_in 1.hour, public: true, must_revalidate: true

ckb_transaction = CkbTransaction.where(tx_hash: params[:id]).order(tx_status: :desc).first
head :not_found and return if ckb_transaction.blank?

if ckb_transaction.is_cellbase
cell_outputs = ckb_transaction.cellbase_display_outputs
total_count = cell_outputs.count
else
cell_outputs = ckb_transaction.outputs.order(id: :asc).
page(@page).per(@page_size).fast_page
total_count = cell_outputs.total_count
cell_outputs = ckb_transaction.normal_tx_display_outputs(cell_outputs)
end

render json: {
data: cell_outputs,
meta: {
total: total_count, page_size: @page_size.to_i
},
}
end

private

def build_cell_capacities(outputs)
Expand Down Expand Up @@ -92,6 +142,11 @@ def token_unit(cell)
"CKB"
end
end

def set_page_and_page_size
@page = params.fetch(:page, 1)
@page_size = params.fetch(:page_size, CkbTransaction.default_per_page)
end
end
end
end
16 changes: 10 additions & 6 deletions app/models/cell_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ class CellInput < ApplicationRecord
belongs_to :previous_cell_output, class_name: "CellOutput", optional: true
belongs_to :block, optional: true

delegate :lock_script, :type_script, to: :previous_cell_output, allow_nil: true
delegate :lock_script, :type_script, to: :previous_cell_output,
allow_nil: true

enum cell_type: {
normal: 0, nervos_dao_deposit: 1, nervos_dao_withdrawing: 2, udt: 3, m_nft_issuer: 4,
m_nft_class: 5, m_nft_token: 6, nrc_721_token: 7, nrc_721_factory: 8, cota_registry: 9,
cota_regular: 10, spore_cluster: 11, spore_cell: 12 }
cota_regular: 10, spore_cluster: 11, spore_cell: 12, omiga_inscription_info: 13, omiga_inscription: 14,
xudt: 15
}

def output
previous_cell_output
end
Expand All @@ -24,17 +28,17 @@ def to_raw
{
previous_output: {
index: "0x#{(previous_index || previous_cell_output.cell_index).to_s(16)}",
tx_hash: previous_tx_hash || previous_cell_output.tx_hash
tx_hash: previous_tx_hash || previous_cell_output.tx_hash,
},
since: hex_since
since: hex_since,
}
else
{
previous_output: {
index: "0xffffffff",
tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000"
tx_hash: "0x0000000000000000000000000000000000000000000000000000000000000000",
},
since: hex_since
since: hex_since,
}
end
end
Expand Down
Loading
Loading