Skip to content

Commit

Permalink
Merge pull request #2182 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
Deploy to testnet
  • Loading branch information
zmcNotafraid authored Sep 9, 2024
2 parents 61686b4 + 7c815d6 commit ce92264
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/models/xudt_tag.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class XudtTag < ApplicationRecord
belongs_to :udt

VALID_TAGS = ["unnamed", "invalid", "suspicious", "out-of-length-range", "rgb++", "layer-1-asset", "supply-limited", "utility", "layer-2-asset", "supply-unlimited"]
VALID_TAGS = ["invalid", "suspicious", "out-of-length-range", "rgb++", "layer-1-asset", "supply-limited", "utility", "layer-2-asset", "supply-unlimited"]
end

# == Schema Information
Expand Down
10 changes: 4 additions & 6 deletions app/workers/xudt_tag_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def perform
end

def mark_tags(udt)
if udt.symbol.blank?
["unnamed"]
elsif invalid_char?(udt.symbol)
if invalid_char?(udt.symbol)
["invalid"]
elsif invisible_char?(udt.symbol)
["suspicious"]
Expand All @@ -36,15 +34,15 @@ def mark_tags(udt)
end

def invalid_char?(symbol)
!symbol.ascii_only?
symbol.present? && !symbol.ascii_only?
end

def invisible_char?(symbol)
(symbol =~ /^[\x21-\x7E]+(?:\s[\x21-\x7E]+)?$/).nil?
symbol.present? && (symbol =~ /^[\x21-\x7E]+(?:\s[\x21-\x7E]+)?$/).nil?
end

def out_of_length?(symbol)
symbol.length > 60
symbol.present? && symbol.length > 60
end

def rgbpp_lock?(issuer_address)
Expand Down
63 changes: 63 additions & 0 deletions lib/tasks/migration/fix_missing_script.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace :migration do
desc "Usage: RAILS_ENV=production bundle exec rake migration:fix_missing_script"
task fix_missing_script: :environment do
ActiveRecord::Base.connection.execute("SET statement_timeout = 0")

puts "===============lock_script"
output_ids = CellOutput.left_outer_joins(:lock_script).where(lock_script: { id: nil }).select(:lock_script_id).distinct
output_ids.each do |output|
p output.lock_script_id
co = CellOutput.where(lock_script_id: output.lock_script_id).first
if co
rpc_tx = CkbSync::Api.instance.get_transaction(co.tx_hash)
lock = rpc_tx.transaction.outputs[co.cell_index].lock
local_lock = LockScript.find_by(script_hash: lock.compute_hash)
if local_lock
if output.lock_script_id < local_lock.id
ApplicationRecord.transaction do
CellOutput.where(lock_script_id: local_lock.id).in_batches(of: 10000) do |batch|
batch.update_all(lock_script_id: output.lock_script_id)
end
local_lock.update(id: output.lock_script_id)
end
else
CellOutput.where(lock_script_id: output.lock_script_id).in_batches(of: 10000) do |batch|
batch.update_all(lock_script_id: local_lock.id)
end
end
else
LockScript.create(id: output.lock_script_id, code_hash: lock.code_hash, hash_type: lock.hash_type, args: lock.args, script_hash: lock.compute_hash)
end
end
end; nil

puts "=============type script"
output_ids = CellOutput.left_outer_joins(:type_script).where.not(type_script_id: nil).where(type_script: { id: nil }).select(:type_script_id).distinct
output_ids.each do |output|
p output.type_script_id
co = CellOutput.where(type_script_id: output.type_script_id).first
if co
rpc_tx = CkbSync::Api.instance.get_transaction(co.tx_hash)
type = rpc_tx.transaction.outputs[co.cell_index].type
local_type = TypeScript.find_by(script_hash: type.compute_hash)
if local_type
if output.type_script_id < local_type.id
ApplicationRecord.transaction do
CellOutput.where(type_script_id: local_type.id).in_batches(of: 10000) do |batch|
batch.update_all(type_script_id: output.type_script_id)
end
local_type.update(id: output.type_script_id)
end
else
CellOutput.where(type_script_id: output.type_script_id).in_batches(of: 10000) do |batch|
batch.update_all(type_script_id: local_type.id)
end
end
else
TypeScript.create(id: output.type_script_id, code_hash: type.code_hash, hash_type: type.hash_type, args: type.args, script_hash: type.compute_hash)
end
end
end; nil
puts "done"
end
end
8 changes: 4 additions & 4 deletions lib/tasks/migration/update_cell_output_script_id.rake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace :migration do
pluck(:script_hash)
duplicate_script_hashes.each do |hash|
LockScript.where(script_hash: hash).each do |script|
unless CellOutput.live.where(lock_script_id: script.id).exists?
unless CellOutput.where(lock_script_id: script.id).exists?
script.destroy
end
end
Expand All @@ -35,7 +35,7 @@ namespace :migration do
pluck(:script_hash)
duplicate_script_hashes.each do |hash|
LockScript.where(script_hash: hash).each do |script|
unless CellOutput.live.where(lock_script_id: script.id).exists?
unless CellOutput.where(lock_script_id: script.id).exists?
script.destroy
end
end
Expand All @@ -50,7 +50,7 @@ namespace :migration do

duplicate_type_script_hashes.each do |hash|
TypeScript.where(script_hash: hash).each do |script|
unless CellOutput.live.where(type_script_id: script.id).exists?
unless CellOutput.where(type_script_id: script.id).exists?
script.destroy
end
end
Expand All @@ -76,7 +76,7 @@ namespace :migration do

duplicate_type_script_hashes.each do |hash|
TypeScript.where(script_hash: hash).each do |script|
unless CellOutput.live.where(type_script_id: script.id).exists?
unless CellOutput.where(type_script_id: script.id).exists?
script.destroy
end
end
Expand Down
10 changes: 1 addition & 9 deletions test/workers/xudt_tag_worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@ class XudtTagWorkerTest < ActiveJob::TestCase
@address = create(:address, address_hash: "ckb1qz7xc452rgxs5z0ks3xun46dmdp58sepg0ljtae8ck0d7nah945nvqgqqqqqqx3l3v4")
end

test "add tag to xudt compatible" do
create(:udt, :xudt_compatible, symbol: nil)
assert_changes -> { XudtTag.count }, from: 0, to: 1 do
XudtTagWorker.new.perform
end
assert_equal ["unnamed"], XudtTag.last.tags
end

test "when xudt with no symbol" do
create(:udt, :xudt, symbol: nil)
assert_changes -> { XudtTag.count }, from: 0, to: 1 do
XudtTagWorker.new.perform
end
assert_equal ["unnamed", "rgb++"], XudtTag.last.tags
assert_equal ["rgb++", "layer-2-asset", "supply-unlimited"], XudtTag.last.tags
end

test "insert to xudt_tags successfully" do
Expand Down

0 comments on commit ce92264

Please sign in to comment.