@@ -18,6 +18,8 @@ they exist, the names of those queries will be included in parentheses.
1818### Chain meta data (` queryMeta ` )
1919``` sql
2020select * from meta ;
21+ ```
22+ ``` sql
2123 id | start_time | network_name
2224-- --+---------------------+--------------
2325 1 | 2017 - 09 - 23 21 :44 :51 | mainnet
@@ -40,6 +42,8 @@ select sum (value) / 1000000 as current_supply from tx_out as tx_outer where
4042 on tx_out .tx_id = tx_in .tx_out_id and tx_out .index = tx_in .tx_out_index
4143 where tx_outer .id = tx_out .id
4244 ) ;
45+ ```
46+ ``` sql
4347 current_supply
4448-- --------------------
4549 31112120630 .27526800
@@ -50,6 +54,8 @@ select sum (value) / 1000000 as current_supply from tx_out as tx_outer where
5054``` sql
5155select slot_no from block where block_no is not null
5256 order by block_no desc limit 1 ;
57+ ```
58+ ``` sql
5359 slot_no
5460-- -------
5561 4011090
@@ -60,6 +66,8 @@ select slot_no from block where block_no is not null
6066### Size of the cexplorer database
6167``` sql
6268select pg_size_pretty (pg_database_size (' cexplorer' ));
69+ ```
70+ ``` sql
6371 pg_size_pretty
6472-- --------------
6573 116 GB
@@ -69,6 +77,8 @@ select pg_size_pretty (pg_database_size ('cexplorer'));
6977### Size of the cexplorer database table
7078``` sql
7179select pg_size_pretty (pg_total_relation_size (' block' ));
80+ ```
81+ ``` sql
7282 pg_size_pretty
7383-- --------------
7484 2760 MB
8696 / (extract (epoch from (now () at time zone ' UTC' )) - extract (epoch from (min (time ) at time zone ' UTC' )))
8797 as sync_percent
8898 from block ;
99+ ```
100+ ``` sql
89101 sync_percent
90102-- ----------------
91103 97 .4357948804029
@@ -98,6 +110,8 @@ transactions.
98110To find out how far behind ` db-sync ` is:
99111``` sql
100112select now () - max (time ) as behind_by from block ;
113+ ```
114+ ``` sql
101115 behind_by
102116-- ----------------------
103117 4 days 20 :59 :39 .134497
@@ -133,6 +147,8 @@ select * from pool_update inner join pool_hash on pool_update.hash_id = pool_has
133147select stake_address .id as stake_address_id, tx_out .address , stake_address .view as stake_address
134148 from tx_out inner join stake_address on tx_out .stake_address_id = stake_address .id
135149 where address = ' addr1qx2kd28nq8ac5pr...08ly3tu9sy0f4qd' ;
150+ ```
151+ ``` sql
136152 stake_address_id | address | stake_address
137153-- ----------------+--------------------------------------+-------------------------------------
138154 42 | addr1qx2kd28nq8ac5p...8ly3tu9sy0f4qd | stake1u9ylzsgxaa6xct...nljg47zctvm3rc
@@ -142,6 +158,8 @@ select stake_address.id as stake_address_id, tx_out.address, stake_address.view
142158``` sql
143159select tx .id , tx .fee from tx
144160 where tx .hash = ' \x f9c0997afc8159dbe0568eadf0823112e0cc29cd097c8dc939ff44c372388bc0' ;
161+ ```
162+ ``` sql
145163 id | fee
146164-- -------+--------
147165 1000000 | 172433
@@ -152,6 +170,8 @@ select tx.id, tx.fee from tx
152170``` sql
153171select tx_out.* from tx_out inner join tx on tx_out .tx_id = tx .id
154172 where tx .hash = ' \x f9c0997afc8159dbe0568eadf0823112e0cc29cd097c8dc939ff44c372388bc0' ;
173+ ```
174+ ``` sql
155175 id | tx_id | index | address | value | address_raw | payment_cred
156176-- -------+---------+-------+-------------------------+--------------+---------------------------+--------------
157177 2205593 | 1000000 | 1 | DdzFFzCqrh...u6v9fWDrML | 149693067531 | \x82d8185842...1a20a42e6f |
@@ -165,6 +185,8 @@ select tx_out.* from tx_out
165185 inner join tx_in on tx_out .tx_id = tx_in .tx_out_id
166186 inner join tx on tx .id = tx_in .tx_in_id and tx_in .tx_out_index = tx_out .index
167187 where tx .hash = ' \x f9c0997afc8159dbe0568eadf0823112e0cc29cd097c8dc939ff44c372388bc0' ;
188+ ```
189+ ``` sql
168190 id | tx_id | index | address | value | address_raw | payment_cred
169191-- -------+--------+-------+-------------------------+--------------+---------------------------+--------------
170192 2195714 | 996126 | 4 | DdzFFzCqrh...dtq1FQQSCN | 158685237964 | \x82d8185842...1a330b42df |
@@ -194,7 +216,8 @@ select epoch_no, max (sync_secs) as sync_secs, sum (tx_count) as tx_count, sum (
194216 from epoch_sync_time
195217 )
196218 as derived_table group by epoch_no ;
197-
219+ ```
220+ ``` sql
198221 epoch_no | sync_secs | tx_count | sum_tx_size | reward_count | stake_count
199222-- --------+----------------+----------+-------------+--------------+-------------
200223 0 | 0 | 33 | 6093 | 0 | 0
@@ -220,6 +243,8 @@ Withdrawals are a feature of some transactions of the Shelley era and later.
220243select withdrawal.* from withdrawal
221244 inner join tx on withdrawal .tx_id = tx .id
222245 where tx .hash = ' \x 0b8c5be678209bb051a02904dd18896a929f9aca8aecd48850939a590175f7e8' ;
246+ ```
247+ ``` sql
223248 id | addr_id | amount | tx_id
224249-- -----+---------+-----------+---------
225250 27684 | 30399 | 154619825 | 2788211
@@ -230,7 +255,8 @@ Simplest query is:
230255``` sql
231256select pool_id, sum (amount) from epoch_stake
232257 where epoch_no = 216 group by pool_id ;
233-
258+ ```
259+ ``` sql
234260 pool_id | sum
235261-- -------+-----------------
236262 1 | 25326935163066
@@ -245,6 +271,8 @@ Or, to use the Bech32 pool identifier instead of the Postgres generated `pool_id
245271select pool_hash .view , sum (amount) as lovelace from epoch_stake
246272 inner join pool_hash on epoch_stake .pool_id = pool_hash .id
247273 where epoch_no = 216 group by pool_hash .id ;
274+ ```
275+ ``` sql
248276 view | lovelace
249277-- --------------------------------------------------------+-----------------
250278 pool10p6wd9k0fwk2zqkqnqr8efyr7gms627ujk9dxgk6majskhawr6r | 789466838780
@@ -263,6 +291,8 @@ select delegation.active_epoch_no, pool_hash.view from delegation
263291 inner join pool_hash on delegation .pool_hash_id = pool_hash .id
264292 where stake_address .view = ' stake1u8gsndukzghdukmqdsd7r7wd6kvamvjv2pzcgag8v6jd69qfqyl5h'
265293 order by active_epoch_no asc ;
294+ ```
295+ ``` sql
266296 active_epoch_no | view
267297-- ---------------+----------------------------------------------------------
268298 212 | pool1hwlghkwnjsjk8370qt3dvp23d7urwm36f95fmxcz3np2kghknj9
@@ -284,6 +314,8 @@ select reward.earned_epoch, pool_hash.view as delegated_pool, reward.amount as l
284314 inner join pool_hash on reward .pool_id = pool_hash .id
285315 where stake_address .view = ' stake1u8gsndukzghdukmqdsd7r7wd6kvamvjv2pzcgag8v6jd69qfqyl5h'
286316 order by earned_epoch asc ;
317+ ```
318+ ``` sql
287319 epoch_no | delegated_pool | lovelace
288320-- --------+----------------------------------------------------------+----------
289321 212 | pool1hwlghkwnjsjk8370qt3dvp23d7urwm36f95fmxcz3np2kghknj9 | 2953284
@@ -307,6 +339,8 @@ select block.block_no, block.epoch_no, pool_hash.view as pool_view
307339 inner join pool_hash on slot_leader .pool_hash_id = pool_hash .id
308340 where block .epoch_no = 220
309341 and pool_hash .view = ' pool137x32lrkprphrd0aa8x4jqz98z6lc0wawlc88hdjeps4qe408ad' ;
342+ ```
343+ ``` sql
310344 block_no | epoch_no | pool_view
311345-- --------+----------+----------------------------------------------------------
312346 4760198 | 220 | pool137x32lrkprphrd0aa8x4jqz98z6lc0wawlc88hdjeps4qe408ad
@@ -322,6 +356,8 @@ select block.epoch_no, count (*) as block_count
322356 inner join pool_hash on slot_leader .pool_hash_id = pool_hash .id
323357 where pool_hash .view = ' pool1nux6acnlx0du7ss9fhg2phjlaqe87l4wcurln5r6f0k8xreluez'
324358 group by block .epoch_no , pool_hash .view ;
359+ ```
360+ ``` sql
325361 epoch_no | block_count
326362-- --------+-------------
327363 212 | 1
@@ -336,6 +372,8 @@ select block.epoch_no, count (*) as block_count
336372select tx .id as tx_id, tx .block_id as tx_block_id, tx_out .address as tx_out_address
337373 from tx inner join tx_out on tx .id = tx_out .tx_id
338374 where tx .hash = ' \x 9053a4cf0c6c9fb29792c78e688c5915a02909d0073371d8fff1abba0bed3065' ;
375+ ```
376+ ``` sql
339377 tx_id | tx_block_id | tx_out_address
340378-- -------+-------------+------------------------------------------------------------
341379 3192730 | 5083822 | addr1vy6d0htdaa9k8du2262p2ju74s25g6rjyjsc9x2fky9r6jq402r08
@@ -353,6 +391,8 @@ cardano-cli transaction txid --tx-file metadata.txsigned
353391select stake_address .view as stake_address, epoch_stake .epoch_no , epoch_stake .amount
354392 from stake_address inner join epoch_stake on stake_address .id = epoch_stake .addr_id
355393 where stake_address .view = ' stake1u8mt5gqclkq0swmvzx9lvq4jgwsnx9yh030yrxwqwllu0mq2m0l4n' ;
394+ ```
395+ ``` sql
356396 stake_address | epoch_no | amount
357397-- -----------------------------------------------------------+----------+-------------
358398 stake1u8mt5gqclkq0swmvzx9lvq4jgwsnx9yh030yrxwqwllu0mq2m0l4n | 211 | 1561003730
@@ -367,6 +407,8 @@ from the treasury. These can be coalesced into single query via an SQL `union` o
367407select addr_id, amount, NULL as reward_epoch_no, tx_id as treasury_tx_id from treasury
368408 union
369409 select addr_id, amount, earned_epoch as reward_epoch_no, NULL as treasury_tx_id from reward ;
410+ ```
411+ ``` sql
370412 addr_id | amount | reward_epoch_no | treasury_tx_id
371413-- -------+---------------+-----------------+----------------
372414 3 | 1071786 | 216 |
@@ -401,7 +443,8 @@ The UTxO set is dependent on time, this will return it for a given timestamp
401443 and ( -- Only outputs consumed in the future or unconsumed outputs
402444 const .effective_time_ <= consuming_block .time or consuming_input .id IS NULL
403445 ) ;
404-
446+ ```
447+ ``` sql
405448 address | lovelace | timestamp
406449-- -----------------------------------------------------------+---------------+---------------------
407450 Ae2tdPwUPEZFdcW8MaYNxoJJkKmkSwJD5D4AdJPBLLn7PCVMenKMvwtWV8K | 1000000 | 2017 - 09 - 23 21 :44 :51
@@ -435,7 +478,8 @@ select
435478 left join tx as redemption_tx on redemption_tx .id = redemption_input .tx_in_id
436479 left join block as redemption_block on redemption_block .id = redemption_tx .block_id
437480 where genesis_block .epoch_no is null ;
438-
481+ ```
482+ ``` sql
439483 address | ada | redeemed_at | origin
440484-- -----------------------------------------------------------+------------+---------------------+------------------
441485 Ae2tdPwUPEZJkVfTW9cFmxAxsp1WtgV4hde53p5eLccUUFzQu8amyrLHcTL | 385509 | 2017 - 11 - 19 06 :36 :11 | Pre- Sale
@@ -455,6 +499,8 @@ select sum (value) / 1000000 as script_locked from tx_out as tx_outer where
455499 on tx_out .tx_id = tx_in .tx_out_id and tx_out .index = tx_in .tx_out_index
456500 where tx_outer .id = tx_out .id
457501 ) ;
502+ ```
503+ ``` sql
458504 script_locked
459505-- --------------------
460506 3695300 .068246000000
@@ -467,6 +513,8 @@ select sum (value) / 1000000 as script_locked from tx_out as tx_outer where
467513select tx .id as tx_id, tx .fee as fees, SUM (redeemer .fee ) as script_fees, SUM (redeemer .unit_mem ) as unit_mem,
468514 SUM (redeemer .unit_steps ) as unit_steps, tx .valid_contract as valid, count (redeemer .id ) scripts, tx .script_size
469515 from tx join redeemer on tx .id = redeemer .tx_id group by tx .id ;
516+ ```
517+ ``` sql
470518 tx_id | fees |script_fees |unit_mem |unit_steps | valid|scripts|script_size
471519 -- ----+----------+------------+----------+-----------+------+-------+-----------
472520 11812 |200193089 | 200000000 | 100000000 | 100000000 | t | 1 | 92
@@ -487,6 +535,8 @@ select SUM(value)/1000000 as lost_amount
487535 join tx_in on tx .id = tx_in .tx_in_id
488536 join tx_out on tx_in .tx_out_id = tx_out .id
489537 where tx .valid_contract = false ;
538+ ```
539+ ``` sql
490540 lost_amount
491541-- ------------------
492542 592003625 .28471400
@@ -500,6 +550,8 @@ select tx.id as tx_id, tx_out.value as tx_out_value, redeemer.unit_mem, redeemer
500550 join tx_in on tx_in .redeemer_id = redeemer .id
501551 join tx_out on tx_in .tx_out_id = tx_out .tx_id and tx_in .tx_out_index = tx_out .index
502552 where redeemer .script_hash = ' \x 8a08f851b22e5c54de087be307eeab3b5c8588a8cea8319867c786e0' ;
553+ ```
554+ ``` sql
503555 tx_id | tx_out_value | unit_mem | unit_steps | fee | purpose
504556-- -----+--------------+-------------+-------------+------------+---------
505557 10184 | 200000000 | 70000000 | 70000000 | 140000000 | spend
@@ -518,6 +570,8 @@ select redeemer.tx_id as tx_id, redeemer.unit_mem, redeemer.unit_steps, redeemer
518570 join multi_asset on redeemer .script_hash = multi_asset .policy
519571 join ma_tx_mint on ma_tx_mint .ident = multi_asset .id and redeemer .tx_id = ma_tx_mint .tx_id
520572 where purpose = ' mint' ;
573+ ```
574+ ``` sql
521575 tx_id | unit_mem | unit_steps | redeemer_fee | purpose | policy | name | quantity
522576-- ------+----------+------------+--------------+---------+------------------------------------------------------------+--------------------------+----------
523577 572051 | 994524 | 365737701 | 83754 | mint | \xfda1b6b487bee2e7f64ecf24d24b1224342484c0195ee1b7b943db50 | \x506c75747573436f696e | 100
@@ -544,6 +598,8 @@ select redeemer.tx_id as tx_id, redeemer.unit_mem, redeemer.unit_steps, redeemer
544598 LEFT JOIN multi_asset ON multi_asset .id = a .ident
545599 LEFT JOIN tx ON tx .id = a .mtx
546600 LEFT JOIN block ON block .id = tx .block_id ;
601+ ```
602+ ``` sql
547603 fingerprint | policy | name | ident | mints | quantity | created
548604-- --------------------------------------------+------------------------------------------------------------+------------------+-------+-------+----------------+---------------------
549605 asset1jtqefvdycrenq2ly6ct8rwcu5e58va432vj586 | \x476039a0949cf0b22f6a800f56780184c44533887ca6e821007840c3 | \x6e7574636f696e | 1 | 1 | 1 | 2021 - 02 - 03 20 :20 :46
@@ -562,8 +618,8 @@ select distinct on(block.hash) block.hash as block_hash , epoch_no, tx_count, po
562618 left join offchain_pool_data on offchain_pool_data .pmr_id = pool_metadata_ref .id
563619 where tx_count = 0 and epoch_no > 150
564620 order by block .hash , pool_update .active_epoch_no desc ;
565-
566-
621+ ```
622+ ``` sql
567623 block_hash | epoch_no | tx_count | pool_hash | pledge | active_epoch_no | url | ticker_name
568624-- ------------------------------------------------------------------+----------+----------+------------------------------------------------------------+-----------------+-----------------+------------------------------------------------------------------+-------------
569625 \x0000f4b44d1484d7280f087c1df94f068a02e23570e8ed9eb5c0dd980d4c46c1 | 165 | 0 | \xe402f5894b8a7073f198bb0710d6294f2ac354ede2577b5ce15159a4 | 50000000000 | 137 | https:// www .canadastakes .ca/ metadata/ can1- testnet- metadata .json |
@@ -605,8 +661,8 @@ select distinct on(block.hash) block.hash as block_hash , epoch_no, tx_count, po
605661 LEFT JOIN tx txr ON txr .id = re .tx_id
606662 LEFT JOIN block br ON br .id = txr .block_id
607663 WHERE (de .tx_id < re .tx_id OR de.* IS NULL );
608-
609-
664+ ```
665+ ``` sql
610666 address | delegated_now_poolid | delegated_now_epoch | delegated_before_poolid | delegated_before_epoch | addr_id | stake_key_registered
611667-- -----------------------------------------------------------+----------------------------------------------------------+---------------------+----------------------------------------------------------+------------------------+---------+----------------------
612668 stake1u9ylzsgxaa6xctf4juup682ar3juj85n8tx3hthnljg47zctvm3rc | pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy | 210 | | | 1 | 2020 - 07 - 29 22 :41 :31
0 commit comments