Skip to content

Commit

Permalink
feat: search by type id (#1530)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz authored Dec 12, 2023
1 parent 9c3faaf commit 6d57d0b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/models/suggest_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ def find_udt_by_type_hash
UdtSerializer.new(udt) if udt.present?
end

def find_type_script_by_type_id
type_script = TypeScript.find_by(script_hash: query_key)
{ data: { args: type_script.args } } if type_script.present?
end

def find_by_hex
Block.cached_find(query_key) || find_ckb_transaction_by_hash || find_address_by_lock_hash || find_udt_by_type_hash
Block.cached_find(query_key) ||
find_ckb_transaction_by_hash ||
find_address_by_lock_hash ||
find_udt_by_type_hash ||
find_type_script_by_type_id
end
end
12 changes: 12 additions & 0 deletions test/controllers/api/v1/suggest_queries_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ class SuggestQueriesControllerTest < ActionDispatch::IntegrationTest

assert_equal response_json, response.body
end

test "should return a type_script when query key is a exist script hash" do
type_script = create(
:type_script,
code_hash: Settings.type_id_code_hash,
script_hash: "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
)

valid_get api_v1_suggest_queries_url, params: { q: type_script.script_hash }

assert_equal type_script.args, json.dig("data", "args")
end
end
end
end

0 comments on commit 6d57d0b

Please sign in to comment.