Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy to testnet #2165

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/controllers/api/v2/bitcoin_addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@
render json: { data: { rgb_cells: cells }, meta: { total: bitcoin_vouts.total_count, page_size: @page_size } }
end

def udt_accounts
expires_in 1.minute, public: true, must_revalidate: true, stale_while_revalidate: 10.seconds

Check warning on line 49 in app/controllers/api/v2/bitcoin_addresses_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/bitcoin_addresses_controller.rb#L48-L49

Added lines #L48 - L49 were not covered by tests

address = Addresses::Explore.run!(key: params[:id])
address_ids = address.map(&:id)

Check warning on line 52 in app/controllers/api/v2/bitcoin_addresses_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/bitcoin_addresses_controller.rb#L51-L52

Added lines #L51 - L52 were not covered by tests

cell_types = %w(udt xudt xudt_compatible)
cell_outputs = CellOutput.live.includes(:bitcoin_vout).where(cell_outputs: { address_id: address_ids, cell_type: cell_types }).
where.not(bitcoin_vouts: { status: "unbound" }).group(:cell_type, :type_hash).sum(:udt_amount)

Check warning on line 56 in app/controllers/api/v2/bitcoin_addresses_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/bitcoin_addresses_controller.rb#L54-L56

Added lines #L54 - L56 were not covered by tests

udt_accounts = cell_outputs.map do |k, v|
udt = Udt.find_by(type_hash: k[1], published: true)
next unless udt

Check warning on line 60 in app/controllers/api/v2/bitcoin_addresses_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/bitcoin_addresses_controller.rb#L58-L60

Added lines #L58 - L60 were not covered by tests

{
symbol: udt.symbol,
decimal: udt.decimal,
amount: v,
type_hash: k[1],
udt_icon_file: udt.icon_file,
udt_type: udt.udt_type,
udt_type_script: udt.type_script,
}
end.compact

Check warning on line 71 in app/controllers/api/v2/bitcoin_addresses_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/bitcoin_addresses_controller.rb#L62-L71

Added lines #L62 - L71 were not covered by tests

render json: { data: { udt_accounts: } }
end

Check warning on line 74 in app/controllers/api/v2/bitcoin_addresses_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/api/v2/bitcoin_addresses_controller.rb#L73-L74

Added lines #L73 - L74 were not covered by tests

private

def set_pagination_params
Expand Down
4 changes: 2 additions & 2 deletions app/models/ckb_sync/new_node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -914,13 +914,13 @@ def prepare_script_ids(outputs)
local_cache.fetch("NodeData/LockScript/#{output.lock.code_hash}-#{output.lock.hash_type}-#{output.lock.args}") do
# TODO use LockScript.where(script_hash: output.lock.compute_hash).select(:id)&.first replace search by code_hash, hash_type and args query after script_hash has been filled
LockScript.where(code_hash: output.lock.code_hash, hash_type: output.lock.hash_type,
args: output.lock.args).take!
args: output.lock.args).order("id asc").first
end
if output.type.present?
local_cache.fetch("NodeData/TypeScript/#{output.type.code_hash}-#{output.type.hash_type}-#{output.type.args}") do
# TODO use TypeScript.where(script_hash: output.type.compute_hash).select(:id)&.first replace search by code_hash, hash_type and args query after script_hash has been filled
TypeScript.where(code_hash: output.type.code_hash, hash_type: output.type.hash_type,
args: output.type.args).take!
args: output.type.args).order("id asc").first
end
end
end
Expand Down
1 change: 1 addition & 0 deletions config/routes/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
resources :bitcoin_statistics, only: :index
resources :bitcoin_addresses, only: :show do
get :rgb_cells, on: :member
get :udt_accounts, on: :member
end
resources :rgb_live_cells, only: :index
end
Expand Down
87 changes: 87 additions & 0 deletions lib/tasks/migration/update_cell_output_script_id.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
namespace :migration do
desc "Usage: RAILS_ENV=production bundle exec rake migration:update_cell_output_script_id"
task update_cell_output_script_id: :environment do
ActiveRecord::Base.connection.execute("SET statement_timeout = 0")
p "==============lock scripts"
duplicate_script_hashes = LockScript.

Check warning on line 6 in lib/tasks/migration/update_cell_output_script_id.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/update_cell_output_script_id.rake#L4-L6

Added lines #L4 - L6 were not covered by tests
select(:script_hash).
group(:script_hash).
having("COUNT(*) > 1").
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?
script.destroy

Check warning on line 14 in lib/tasks/migration/update_cell_output_script_id.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/update_cell_output_script_id.rake#L11-L14

Added lines #L11 - L14 were not covered by tests
end
end
end; nil

duplicate_script_hashes.each_with_index do |lock_script_hash, index|
p lock_script_hash
p index
lock_script_ids = LockScript.where(script_hash: lock_script_hash).order("id asc").pluck(:id)
base_lock_script_id = lock_script_ids.delete_at(0)
lock_script_ids.each do |id|
CellOutput.where(lock_script_id: id).in_batches(of: 10000) do |batch|
batch.update_all(lock_script_id: base_lock_script_id)

Check warning on line 26 in lib/tasks/migration/update_cell_output_script_id.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/update_cell_output_script_id.rake#L19-L26

Added lines #L19 - L26 were not covered by tests
end
end
end; nil

duplicate_script_hashes = LockScript.

Check warning on line 31 in lib/tasks/migration/update_cell_output_script_id.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/update_cell_output_script_id.rake#L31

Added line #L31 was not covered by tests
select(:script_hash).
group(:script_hash).
having("COUNT(*) > 1").
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?
script.destroy

Check warning on line 39 in lib/tasks/migration/update_cell_output_script_id.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/update_cell_output_script_id.rake#L36-L39

Added lines #L36 - L39 were not covered by tests
end
end
end; nil

p "==============type scripts"
duplicate_type_script_hashes = TypeScript.

Check warning on line 45 in lib/tasks/migration/update_cell_output_script_id.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/update_cell_output_script_id.rake#L44-L45

Added lines #L44 - L45 were not covered by tests
select(:script_hash).
group(:script_hash).
having("COUNT(*) > 1").
pluck(:script_hash)

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?
script.destroy

Check warning on line 54 in lib/tasks/migration/update_cell_output_script_id.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/update_cell_output_script_id.rake#L51-L54

Added lines #L51 - L54 were not covered by tests
end
end
end; nil

duplicate_type_script_hashes.each_with_index do |type_script_hash, index|
p type_script_hash
p index
type_script_ids = TypeScript.where(script_hash: type_script_hash).order("id asc").pluck(:id)
base_type_script_id = type_script_ids.delete_at(0)
type_script_ids.each do |id|
CellOutput.where(type_script_id: id).in_batches(of: 10000) do |batch|
batch.update_all(type_script_id: base_type_script_id)

Check warning on line 66 in lib/tasks/migration/update_cell_output_script_id.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/update_cell_output_script_id.rake#L59-L66

Added lines #L59 - L66 were not covered by tests
end
end
end; nil

duplicate_type_script_hashes = TypeScript.

Check warning on line 71 in lib/tasks/migration/update_cell_output_script_id.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/update_cell_output_script_id.rake#L71

Added line #L71 was not covered by tests
select(:script_hash).
group(:script_hash).
having("COUNT(*) > 1").
pluck(:script_hash)

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?
script.destroy

Check warning on line 80 in lib/tasks/migration/update_cell_output_script_id.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/update_cell_output_script_id.rake#L77-L80

Added lines #L77 - L80 were not covered by tests
end
end
end; nil

puts "done"

Check warning on line 85 in lib/tasks/migration/update_cell_output_script_id.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/update_cell_output_script_id.rake#L85

Added line #L85 was not covered by tests
end
end
Loading