-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1791 from nervosnetwork/develop
Deploy to testnet
- Loading branch information
Showing
18 changed files
with
338 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,13 @@ | ||
module Api | ||
module V1 | ||
class SuggestQueriesController < ApplicationController | ||
before_action :validate_query_params | ||
|
||
def index | ||
json_response = SuggestQuery.new(params[:q]).find! | ||
json_response = SuggestQuery.new(params[:q], params[:filter_by]).find! | ||
|
||
render json: json_response | ||
rescue ActiveRecord::RecordNotFound | ||
raise Api::V1::Exceptions::SuggestQueryResultNotFoundError | ||
end | ||
|
||
private | ||
|
||
def validate_query_params | ||
validator = Validations::SuggestQuery.new(params) | ||
|
||
if validator.invalid? | ||
errors = validator.error_object[:errors] | ||
status = validator.error_object[:status] | ||
|
||
render json: errors, status: | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class XudtTag < ApplicationRecord | ||
belongs_to :udt | ||
|
||
VALID_TAGS = ["invalid", "suspicious", "out-of-length-range", "rgbpp-compatible", "layer-1-asset", "supply-limited", "duplicate", "layer-2-asset", "supply-unlimited"] | ||
end | ||
|
||
# == Schema Information | ||
# | ||
# Table name: xudt_tags | ||
# | ||
# id :bigint not null, primary key | ||
# udt_id :integer | ||
# udt_type_hash :string | ||
# tags :string default([]), is an Array | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
# Indexes | ||
# | ||
# index_xudt_tags_on_udt_id (udt_id) UNIQUE | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class TokenCollectionSerializer | ||
include FastJsonapi::ObjectSerializer | ||
|
||
attributes :standard, :name, :description, :icon_url, :symbol | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
class XudtTagWorker | ||
include Sidekiq::Job | ||
|
||
def perform | ||
udts = Udt.published_xudt.left_joins(:xudt_tag).where(xudt_tag: { id: nil }).limit(100) | ||
attrs = | ||
udts.map do |udt| | ||
tags = mark_tags(udt) | ||
{ udt_id: udt.id, udt_type_hash: udt.type_hash, tags: } | ||
end | ||
|
||
XudtTag.upsert_all(attrs, unique_by: :udt_id, on_duplicate: :update, update_only: :tags) | ||
end | ||
|
||
def mark_tags(udt) | ||
if invalid_char?(udt.symbol) | ||
["invalid"] | ||
elsif invisible_char?(udt.symbol) | ||
["suspicious"] | ||
elsif out_of_length?(udt.symbol) | ||
["out-of-length-range"] | ||
elsif first_xudt?(udt.symbol, udt.block_timestamp) | ||
if rgbpp_lock?(udt.issuer_address) | ||
["rgbpp-compatible", "layer-1-asset", "supply-limited"] | ||
else | ||
["rgbpp-compatible", "layer-2-asset", "supply-unlimited"] | ||
end | ||
elsif rgbpp_lock?(udt.issuer_address) | ||
["duplicate", "layer-1-asset", "supply-limited"] | ||
else | ||
["duplicate", "layer-2-asset", "supply-unlimited"] | ||
end | ||
end | ||
|
||
def invalid_char?(symbol) | ||
!symbol.ascii_only? | ||
end | ||
|
||
def invisible_char?(symbol) | ||
(symbol =~ /^[\x21-\x7E]+$/).nil? | ||
end | ||
|
||
def out_of_length?(symbol) | ||
symbol.length > 5 || symbol.length < 4 | ||
end | ||
|
||
def first_xudt?(symbol, block_timestamp) | ||
!Udt.xudt.where("LOWER(symbol) = ?", symbol.downcase).where("block_timestamp < ?", block_timestamp).exists? | ||
end | ||
|
||
def rgbpp_lock?(issuer_address) | ||
CkbUtils.parse_address(issuer_address).script.code_hash == Settings.rgbpp_code_hash | ||
end | ||
|
||
## TODO: current no this condition | ||
def omni_lock_with_supply_mode?(issuer_address); end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateXudtTags < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :xudt_tags do |t| | ||
t.integer :udt_id | ||
t.string :udt_type_hash | ||
t.string "tags", default: [], array: true | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :xudt_tags, :udt_id, unique: true | ||
end | ||
end |
Oops, something went wrong.