Skip to content

Commit

Permalink
Merge pull request #2101 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
Deploy to testnet
  • Loading branch information
zmcNotafraid authored Jul 29, 2024
2 parents e5eeda8 + 8ff9f7c commit 2c5ca1e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
32 changes: 31 additions & 1 deletion app/models/concerns/cell_outputs/extra_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def m_nft_info
value = { issuer_name: CkbUtils.parse_issuer_data(data).info["name"] }
when "m_nft_class"
parsed_data = CkbUtils.parse_token_class_data(data)
value = { class_name: parsed_data.name, total: parsed_data.total }
value = { class_name: parsed_data.name, total: parsed_data.total, type_hash: }
when "m_nft_token"
# issuer_id size is 20 bytes, class_id size is 4 bytes
m_nft_class_type = TypeScript.where(
Expand All @@ -40,6 +40,9 @@ def m_nft_info
class_name: parsed_class_data.name,
token_id: type_script.args[50..-1],
total: parsed_class_data.total,
collection: {
type_hash: m_nft_class_type.script_hash,
},
}
else
value = { class_name: "", token_id: nil, total: "" }
Expand All @@ -51,6 +54,30 @@ def m_nft_info
CkbUtils.hash_value_to_s(value)
end

def dob_info
return unless cell_type.in?(%w(spore_cluster spore_cell did_cell))

case cell_type
when "spore_cluster"
tc = TokenCollection.find_by(sn: type_hash)
value = { cluster_name: tc&.name, published: !tc.nil?, type_hash: }
else
ti = TokenItem.find_by(type_script_id:)
coll = ti.collection

value = {
cluster_name: coll&.name,
token_id: ti.token_id,
collection: {
type_hash: coll&.sn,
},
published: true,
}
end

CkbUtils.hash_value_to_s(value)
end

def nrc_721_nft_info
return unless cell_type.in?(%w(nrc_721_token nrc_721_factory))

Expand Down Expand Up @@ -79,6 +106,9 @@ def nrc_721_nft_info
decimal: udt_account.decimal,
type_hash:,
published: true,
collection: {
type_hash: factory_cell&.type_script&.script_hash,
},
}
else
raise "invalid cell type"
Expand Down
2 changes: 2 additions & 0 deletions app/serializers/cell_output_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class CellOutputSerializer
object.m_nft_info.merge!(type: "m_nft")
when "nrc_721_token", "nrc_721_factory"
object.nrc_721_nft_info.merge!(type: "nrc_721")
when "spore_cluster", "spore_cell", "did_cell"
object.dob_info.merge!(type: "dob")
when "omiga_inscription_info", "omiga_inscription"
object.omiga_inscription_info.merge!(type: "omiga_inscription")
end
Expand Down
2 changes: 1 addition & 1 deletion app/workers/update_udt_info_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def perform(block_number)
}

# generate udt holder allocation
if udt.xudt_compatible? || udt.xudt? || xudt.omiga_inscription?
if udt.xudt_compatible? || udt.xudt? || udt.omiga_inscription?
$redis.sadd("udt_holder_allocation", type_hash)
end
end
Expand Down
15 changes: 8 additions & 7 deletions test/models/ckb_transaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
id from_cellbase capacity address_hash
generated_tx_hash cell_index cell_type since extra_info
).sort
expected_m_nft_attributes = %i(class_name total).sort
expected_m_nft_attributes = %i(class_name total type_hash).sort
expected_display_input = CkbUtils.hash_value_to_s(
id: m_nft_cell_output.id,
from_cellbase: false,
Expand Down Expand Up @@ -538,7 +538,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
id from_cellbase capacity address_hash
generated_tx_hash cell_index cell_type since extra_info
).sort
expected_m_nft_attributes = %i(class_name token_id total).sort
expected_m_nft_attributes = %i(class_name token_id total collection).sort
expected_display_input = CkbUtils.hash_value_to_s(
id: m_nft_cell_output.id,
from_cellbase: false,
Expand Down Expand Up @@ -604,7 +604,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
id capacity address_hash status consumed_tx_hash
cell_type extra_info
).sort
expected_m_nft_attributes = %i(class_name total).sort
expected_m_nft_attributes = %i(class_name total type_hash).sort
expected_display_output = CkbUtils.hash_value_to_s(
id: m_nft_cell_output.id,
capacity: m_nft_cell_output.capacity,
Expand Down Expand Up @@ -687,13 +687,14 @@ class CkbTransactionTest < ActiveSupport::TestCase
block: nrc_721_token_output_block)

nrc_factory_cell = create(:nrc_factory_cell,
code_hash: "0x00000000000000000000000000000000000000000000000000545950455f4944013620e2ced53373c5b55c5cef79b7fd0a875c60a70382a9e9664fe28e0bb345ab22c70f8e24a90dcccc7eb1ea669ac6cfecab095a1886af01d71612fdb3c836c8",
args: "0x3620e2ced53373c5b55c5cef79b7fd0a875c60a70382a9e9664fe28e0bb345ab",
code_hash: "0xf31f9c3241043976c93db9f203d765ce2c1d96465c918b93fbb117cd35bcfb98",
args: "0x47a6262383ad9b266c6fae7c460dc39261e4f914e77467426809ce0fd607baec",
verified: true)
nrc_721_factory_type_script = create(:type_script,
code_hash: nrc_factory_cell.code_hash,
hash_type: "type",
args: nrc_factory_cell.args)
args: nrc_factory_cell.args,
script_hash: "0xcf4f2494ea1fbebcd07a7445415a0e8b36be214af6257065888dae0ce1434434")
nrc_721_factory_cell_output = create(:cell_output,
block: nrc_721_token_output_block,
ckb_transaction: nrc_721_token_output_transaction,
Expand Down Expand Up @@ -729,7 +730,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
symbol: "TTF", amount: "", decimal: "", type_hash: "0x", published: true
}
token_info = {
symbol: "TTF", amount: udt_account.nft_token_id, decimal: "6", type_hash: "0x", published: true
symbol: "TTF", amount: udt_account.nft_token_id, decimal: "6", type_hash: "0x", published: true, collection: { type_hash: "0xcf4f2494ea1fbebcd07a7445415a0e8b36be214af6257065888dae0ce1434434" }
}
display_outputs = nrc_721_token_output_transaction.display_outputs
assert_equal factory_info.to_a,
Expand Down

0 comments on commit 2c5ca1e

Please sign in to comment.