diff --git a/app/controllers/api/v2/bitcoin_addresses_controller.rb b/app/controllers/api/v2/bitcoin_addresses_controller.rb index 17e77809f..f2ba1b5de 100644 --- a/app/controllers/api/v2/bitcoin_addresses_controller.rb +++ b/app/controllers/api/v2/bitcoin_addresses_controller.rb @@ -45,6 +45,34 @@ def rgb_cells 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 + + address = Addresses::Explore.run!(key: params[:id]) + address_ids = address.map(&:id) + + 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) + + udt_accounts = cell_outputs.map do |k, v| + udt = Udt.find_by(type_hash: k[1], published: true) + next unless udt + + { + 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 + + render json: { data: { udt_accounts: } } + end + private def set_pagination_params diff --git a/config/routes/v2.rb b/config/routes/v2.rb index 19d447119..b431ae327 100644 --- a/config/routes/v2.rb +++ b/config/routes/v2.rb @@ -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