@@ -228,65 +228,6 @@ def create_token
228228 end
229229 end
230230
231- # Because the balance of address equals to the total capacity of all live cells in this address,
232- # So we can directly aggregate balance by address from database.
233- def self . refresh_address_balances
234- puts "refreshing all balances"
235- # fix balance and live cell count for all addresses
236- connection . execute <<-SQL
237- UPDATE addresses SET balance=sq.balance, live_cells_count=c
238- FROM (
239- SELECT address_id, SUM(capacity) as balance, COUNT(*) as c
240- FROM cell_outputs
241- WHERE status = 0
242- GROUP BY address_id
243- ) AS sq
244- WHERE addresses.id=sq.address_id;
245- SQL
246- # fix occupied balances for all addresses
247- puts "refreshing all occupied balances"
248- connection . execute <<-SQL
249- UPDATE addresses SET balance_occupied=sq.balance
250- FROM (
251- SELECT address_id, SUM(capacity) as balance
252- FROM cell_outputs
253- WHERE status = 0
254- AND "cell_outputs"."type_hash" IS NOT NULL AND "cell_outputs"."data" != '\x30 78'
255- GROUP BY address_id
256- ) AS sq
257- WHERE addresses.id=sq.address_id;
258- SQL
259- puts "refreshing dao deposits"
260- connection . execute <<-SQL
261- UPDATE addresses SET dao_deposit=sq.sum, is_depositor = sq.sum > 0
262- FROM (
263- SELECT address_id, SUM(capacity) as sum
264- FROM cell_outputs
265- WHERE status = 0
266- AND cell_type = 1
267- GROUP BY address_id
268- ) AS sq
269- WHERE addresses.id=sq.address_id;
270- SQL
271- end
272-
273- # update the history data, which cell_type should be "cota_registry" or "cota_regular"
274- def self . update_cell_types_for_cota
275- TypeScript . where ( code_hash : CkbSync ::Api . instance . cota_registry_code_hash ) . each do |type_script |
276- CellOutput . where ( type_script_id : type_script . id ) . each do |cell_output |
277- cell_output . cell_type = "cota_registry"
278- cell_output . save!
279- end
280- end
281-
282- TypeScript . where ( code_hash : CkbSync ::Api . instance . cota_regular_code_hash ) . each do |type_script |
283- CellOutput . where ( type_script_id : type_script . id ) . each do |cell_output |
284- cell_output . cell_type = "cota_regular"
285- cell_output . save!
286- end
287- end
288- end
289-
290231 def self . dead_reltuples_count
291232 sql = "SELECT reltuples FROM pg_class WHERE relname = 'cell_outputs_dead'"
292233 result = ActiveRecord ::Base . connection . execute ( sql )
0 commit comments