Skip to content

Commit

Permalink
chore: add testnet xudt compatible contract (#1931)
Browse files Browse the repository at this point in the history
* chore: add testnet xudt compatible contract

Signed-off-by: Miles Zhang <mingchang555@hotmail.com>

* feat: support xudt_compatible api

Signed-off-by: Miles Zhang <mingchang555@hotmail.com>

---------

Signed-off-by: Miles Zhang <mingchang555@hotmail.com>
  • Loading branch information
zmcNotafraid committed Jun 6, 2024
1 parent c12c474 commit 5aadf7b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/controllers/api/v1/xudts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class XudtsController < ApplicationController
before_action :validate_pagination_params, :pagination_params, only: :index

def index
scope = Udt.xudt.includes(:xudt_tag)
scope = Udt.includes(:xudt_tag).where(udt_type: xudt_type_params)

if params[:symbol].present?
scope = scope.where("LOWER(symbol) = ?", params[:symbol].downcase)
Expand Down Expand Up @@ -104,6 +104,10 @@ def parse_tags
tags = params[:tags].split(",")
tags & XudtTag::VALID_TAGS
end

def xudt_type_params
params[:type].blank? ? "xudt" : "xudt_compatible"
end
end
end
end
2 changes: 1 addition & 1 deletion config/settings.mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ omiga_inscription_code_hash: "0x7490970e6af9b9fe63fc19fc523a12b2ec69027e6ae484ed
xudt_code_hash: "0x50bd8d6680b8b9cf98b73f3c08faf8b2a21914311954118ad6609be6e78a1b95"

# xudt compatible
xudt_compatible_code_hash: "0x74f8fd146cca83d5fa2acd8a2b0bc7f0408a38b79a173c1e8ca1fbdfc95122ff"
xudt_compatible_code_hash: "0x092c2c4a26ea475a8e860c29cf00502103add677705e2ccd8d6fe5af3caa5ae3"

unique_cell_code_hash: "0x2c8c11c985da60b0a330c61a85507416d6382c130ba67f0c47ab071e00aec628"

Expand Down
4 changes: 3 additions & 1 deletion config/settings.testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ omiga_inscription_code_hash: "0x3a241ceceede72a5f55c8fb985652690f09a517d6c9070f0
xudt_code_hash: "0x25c29dc317811a6f6f3985a7a9ebc4838bd388d19d0feeecf0bcd60f6c0975bb"
unique_cell_code_hash: "0x8e341bcfec6393dcd41e635733ff2dca00a6af546949f70c57a706c0f344df8b"

# xudt compatible
xudt_compatible_code_hash: "0x98701eaf939113606a8a70013fd2e8f27b8f1e234acdc329f3d71f9e9d3d3233"

# hash length of an attribute(especially which comes from bytea column),
# e.g. Block.uncle_block_hashes: "0x587f354162afd133b4a4f7a4b621d11e043c3c08b0af2801f1686b5403b14953", which has a length of 66 ( 2 + 64)
default_hash_length: "64"
Expand Down Expand Up @@ -82,4 +85,3 @@ proposal_window: 10
rgbpp_code_hash: "0x61ca7a4796a4eb19ca4f0d065cb9b10ddcf002f10f7cbb810c706cb6bb5c3248"
# btc time code hash
btc_time_code_hash: "0x00cdf8fab0f8ac638758ebf5ea5e4052b1d71e8a77b9f43139718621f6849326"

10 changes: 10 additions & 0 deletions test/controllers/api/v1/xudts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ class XudtsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end

test "should get success code when call xudt_compatible index " do
create(:udt, :xudt_compatible, published: true)

valid_get api_v1_xudts_url, params: {type: "xudt_compatible"}

assert_response :success
assert_equal 1, json["data"].length
end


test "filter xudt by symbol and tags" do
udt = create(:udt, :xudt, symbol: "CKBB")
create(:xudt_tag, udt:, tags: ["duplicate", "layer-1-asset", "supply-limited"])
Expand Down
9 changes: 9 additions & 0 deletions test/factories/udt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,14 @@
symbol { "BBQ" }
decimal { 8 }
end

trait :xudt_compatible do
udt_type { "xudt_compatible" }
published { true }
full_name { "XUDTCompatible" }
symbol { "XC" }
decimal { 8 }
end

end
end

0 comments on commit 5aadf7b

Please sign in to comment.