Query editor
WITH computebudget_a AS (SELECTt.id,CASEWHEN BYTEARRAY_SUBSTRING(from_base58(ixs.data), 1, 1) = 0x02THEN bytearray_to_bigint(bytearray_reverse(bytearray_substring(from_base58(ixs.data), 2, 4)))ELSE -1END as requestedUnitsFROM solana.transactions AS tLEFT JOIN UNNEST (instructions) AS ixs ON TRUEWHERE block_date = DATE '2024-01-16'and id = '{{tx_id}}'AND ixs.executing_account = 'ComputeBudget111111111111111111111111111111'),computebudget AS (SELECTid,requestedUnits,ROW_NUMBER() OVER(PARTITION BY id ORDER BY requestedUnits DESC) as "rn"FROM computebudget_a),ixs_a AS (SELECTt.id,t.block_slot,SPLIT(logs1.log, ' ')[2] as program_id,TRY_CAST(substr(SPLIT(logs1.log, ' ')[4], 2, 1) as int) as depth,CARDINALITY(log_messages) as final_log_index,logs1.nr as "rn"FROM solana.transactions AS t,UNNEST (log_messages) WITH ORDINALITY logs1(log, nr)WHERE block_date = DATE '2024-01-16'and id = '{{tx_id}}'AND logs1.log LIKE 'Program % invoke [%]'),ixs AS (SELECTa.id,a.program_id,a.block_slot,a.depth,a.rn as "index",COALESCE(MIN(b.rn), a.final_log_index) as "nextIndex"FROM ixs_a aLEFT JOIN ixs_a b ONa.id = b.idAND a.rn < b.rnAND a.depth >= b.depthGROUP BY a.id, a.program_id, a.depth, a.rn, a.final_log_index, a.block_slot),consumedunits_a AS (SELECTt.id,SPLIT(logs2.log, ' ')[2] as program_id,TRY_CAST(SPLIT(logs2.log, ' ')[4] AS BIGINT) AS computed_units_spent,TRY_CAST(SPLIT(logs2.log, ' ')[6] AS BIGINT) AS computed_units_allocated,logs2.nr as "rn"FROM solana.transactions AS t,UNNEST (t.log_messages) WITH ORDINALITY logs2(log, nr)WHERE block_date = DATE '2024-01-16'