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 #1517

Merged
merged 3 commits into from
Dec 1, 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
82 changes: 82 additions & 0 deletions app/controllers/api/v1/address_pending_transactions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
module Api
module V1
class AddressPendingTransactionsController < ApplicationController
before_action :validate_query_params
before_action :validate_pagination_params, :pagination_params
before_action :find_address

def show
expires_in 10.seconds, public: true, must_revalidate: true, stale_while_revalidate: 10.seconds

ckb_transactions = @address.ckb_transactions.tx_pending
ckb_transactions_ids = CellInput.where(ckb_transaction_id: ckb_transactions.ids).
where.not(previous_cell_output_id: nil, from_cell_base: false).
distinct.pluck(:ckb_transaction_id)
@ckb_transactions = CkbTransaction.where(id: ckb_transactions_ids).
order(transactions_ordering).page(@page).per(@page_size)

render json: serialized_ckb_transactions
end

private

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

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

render json: errors, status: status
end
end

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

def find_address
@address = Address.find_address!(params[:id])
raise Api::V1::Exceptions::AddressNotFoundError if @address.is_a?(NullAddress)
end

def transactions_ordering
sort, order = params.fetch(:sort, "id.desc").split(".", 2)
sort = case sort
when "time" then "block_timestamp"
else "id"
end

order = order.match?(/^(asc|desc)$/i) ? order : "asc"

"#{sort} #{order} NULLS LAST"
end

def serialized_ckb_transactions
options = FastJsonapi::PaginationMetaGenerator.new(
request: request,
records: @ckb_transactions,
page: @page,
page_size: @page_size
).call
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.serialized_json
else
ckb_transaction_serializer.serialized_json.gsub(
@address.address_hash, @address.query_address
)
end
else
ckb_transaction_serializer.serialized_json
end
end
end
end
end
4 changes: 4 additions & 0 deletions app/controllers/api/v1/market_data_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module V1
class MarketDataController < ApplicationController
skip_before_action :check_header_info

def index
render json: MarketData.new.indicators_json
end

def show
render json: MarketData.new(indicator: params[:id]).call
end
Expand Down
33 changes: 19 additions & 14 deletions app/controllers/api/v2/das_accounts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
module Api::V2
class DasAccountsController < BaseController
def query
das = DasIndexerService.instance
module Api
module V2
class DasAccountsController < BaseController
def query
das = DasIndexerService.instance

cache_keys = params[:addresses]
cache_keys = params[:addresses]

res = Rails.cache.read_multi(*cache_keys)
not_cached = cache_keys - res.keys
to_cache = {}
not_cached.each do |address|
name = das.reverse_record(address)
res[address] = name
to_cache[address] = name
res = Rails.cache.read_multi(*cache_keys)
not_cached = cache_keys - res.keys
to_cache = {}
not_cached.each do |address|
next unless QueryKeyUtils.valid_address?(address)

name = das.reverse_record(address)
res[address] = name
to_cache[address] = name
end
Rails.cache.write_multi(to_cache, expires_in: 1.hour)

render json: res
end
Rails.cache.write_multi(to_cache, expires_in: 1.hour)
render json: res
end
end
end
6 changes: 0 additions & 6 deletions app/models/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,6 @@ def self.find_address!(query_key)
end

def self.cached_find(query_key)
cache_key = query_key

unless QueryKeyUtils.valid_hex?(query_key)
cache_key = CkbUtils.parse_address(query_key).script.compute_hash
end

address =
if QueryKeyUtils.valid_hex?(query_key)
find_by(lock_hash: query_key)
Expand Down
4 changes: 4 additions & 0 deletions app/models/market_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def call
send(indicator)
end

def indicators_json
VALID_INDICATORS.index_with { |indicator| send(indicator) }
end

def ecosystem_locked
if current_timestamp < first_released_timestamp_other
ECOSYSTEM_QUOTA * 0.97
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
resources :daily_statistics, only: :show
resources :block_statistics, only: :show ## TODO: unused route
resources :epoch_statistics, only: :show
resources :market_data, only: :show
resources :market_data, only: [:index, :show]
resources :udts, only: %i(index show update) do
collection do
get :download_csv
Expand All @@ -64,6 +64,7 @@
resources :distribution_data, only: :show
resources :monetary_data, only: :show
resources :udt_verifications, only: :update
resources :address_pending_transactions, only: :show
end
end
draw "v2"
Expand Down
2 changes: 0 additions & 2 deletions lib/tasks/migration/fix_address_balance_occupied.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace :migration do
pr_merged_datetime = DateTime.new(2022,7,23,0,0,0)
addresses = Address.where("updated_at > ?", pr_merged_datetime).order(id: :asc)
addresses.find_each do |address|
puts "Address ID: #{address.id}"

occupied = address.cell_outputs.live.occupied.sum(:capacity)
address.update(balance_occupied: occupied)
end
Expand Down
Loading
Loading