Skip to content

Commit

Permalink
Update wallet08.mdx
Browse files Browse the repository at this point in the history
fix relative paths
  • Loading branch information
johnnygreeney authored Sep 12, 2024
1 parent c2532b3 commit 93986de
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions docs/pages/use-cases/WalletQueries/wallet08.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,26 @@ This query gathers data such as pool metadata, stake addresses, and block mintin
🔎 Here's a breakdown of what the query does:

The `SELECT ...` clause specifies the columns to be included in our results:
- `ph.id`, the id of the [pool_hash](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_hash) table
- `po.pool_name AS pool_name` is the pool's name, retrieved from the [pool_offline_data](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_offline_data) table
- `ph.id`, the id of the [pool_hash](/../../schema.md#pool_hash) table
- `po.pool_name AS pool_name` is the pool's name, retrieved from the [pool_offline_data](/../../schema.md#pool_offline_data) table
- `po.ticker_name AS pool_ticker`...the pool's ticker symbol.
- `ph.view AS pool_id`...the human-readable pool id.
- `ph.hash_raw AS pool_hash`...the pool's hash value.
- `pu.fixed_cost`...the pool's fixed cost, from [pool_update](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_update)
- `pu.margin`...the pool's margin, also from [pool_update](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_update)
- `pu.fixed_cost`...the pool's fixed cost, from [pool_update](/../../schema.md#pool_update)
- `pu.margin`...the pool's margin, also from [pool_update](/../../schema.md#pool_update)
- `pu.pledge AS declared_pledge`...the pool's declared pledge amount.
- `ltb.lifetime_blocks`... the total number of blocks minted by the pool (calculated in the subquery).
- `sa.view AS stake_account`...the stake address associated with the pool's rewards

The `FROM pool_hash ph` clause specifies that we are selecting data from the [pool_hash](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_hash)table, aliased as `ph`. This table likely stores core pool identification information.
The `FROM pool_hash ph` clause specifies that we are selecting data from the [pool_hash](/../../schema.md#pool_hash)table, aliased as `ph`. This table likely stores core pool identification information.

`LEFT JOIN pool_offline_data po ON ...` performs a left `JOIN` with the [pool_offline_data](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_offline_data) table. It matches rows based on `pool_id` and ensures that if multiple entries exist for the same pool, only the latest one is selected (using a subquery to find the maximum id).
`LEFT JOIN pool_offline_data po ON ...` performs a left `JOIN` with the [pool_offline_data](/../../schema.md#pool_offline_data) table. It matches rows based on `pool_id` and ensures that if multiple entries exist for the same pool, only the latest one is selected (using a subquery to find the maximum id).

`LEFT JOIN pool_update pu ON ...` is another `LEFT JOIN`, this time with [pool_update](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_update). It matches on `hash_id` and again selects the latest update for the pool using a similar subquery approach.
`LEFT JOIN pool_update pu ON ...` is another `LEFT JOIN`, this time with [pool_update](/../../schema.md#pool_update). It matches on `hash_id` and again selects the latest update for the pool using a similar subquery approach.

`LEFT JOIN stake_address sa ON ...` is another `LEFT JOIN` which connects to the [stake_address](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#stake_address) table to retrieve the stake address linked to the pool's rewards.
`LEFT JOIN stake_address sa ON ...` is another `LEFT JOIN` which connects to the [stake_address](/../../schema.md#stake_address) table to retrieve the stake address linked to the pool's rewards.

`LEFT JOIN (...) AS ltb ON ...` incorporates a subquery aliased as `ltb`. This subquery calculates the total number of blocks minted by the pool by joining [pool_hash](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_hash), [slot_leader](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#slot_leader) and [block](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#block) tables and counting the relevant blocks. The result is then joined back to the main query based on `poolId`.
`LEFT JOIN (...) AS ltb ON ...` incorporates a subquery aliased as `ltb`. This subquery calculates the total number of blocks minted by the pool by joining [pool_hash](/../../schema.md#pool_hash), [slot_leader](/../../schema.md#slot_leader) and [block](/../../schema.md#block) tables and counting the relevant blocks. The result is then joined back to the main query based on `poolId`.

`WHERE ph."view" = 'pool1j20l32n8un5gce4adk44n9zks8cdvnk3amgursud847cwnpgeg4'` filters the results to include only the data for the specific pool we are interested in.

Expand Down Expand Up @@ -135,18 +135,18 @@ Expected results format

🔎 Lets dig a little deeper to gain a better understanding.

The opening `SELECT sa."view" AS owner_account` clause specifies what data the query should return. It selects the view column from the [stake_address](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#stake_address) table (aliased as `sa`) and labels it as `owner_account` in the results.
The opening `SELECT sa."view" AS owner_account` clause specifies what data the query should return. It selects the view column from the [stake_address](/../../schema.md#stake_address) table (aliased as `sa`) and labels it as `owner_account` in the results.

`FROM pool_hash ph` clause means we are inspectig the [pool_hash](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_hash) table, giving it the alias `ph`. This table stores core information about stake pools, including their unique hashes.
`FROM pool_hash ph` clause means we are inspectig the [pool_hash](/../../schema.md#pool_hash) table, giving it the alias `ph`. This table stores core information about stake pools, including their unique hashes.

`JOIN pool_update pu ON ph.id = pu.hash_id` performs an INNER JOIN with the [pool_update](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_update) table (aliased as `pu`).
The join condition is `ph.id = pu.hash_id`, meaning it connects rows from [pool_hash](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_hash) and [pool_update](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_update) where their ids match. This links pool information with its update history.
`JOIN pool_update pu ON ph.id = pu.hash_id` performs an INNER JOIN with the [pool_update](/../../schema.md#pool_update) table (aliased as `pu`).
The join condition is `ph.id = pu.hash_id`, meaning it connects rows from [pool_hash](/../../schema.md#pool_hash) and [pool_update](/../../schema.md#pool_update) where their ids match. This links pool information with its update history.

`AND pu.id = (SELECT MAX(pu2.id) FROM pool_update pu2 WHERE ph.id = pu2.hash_id)` is a subquery within the `JOIN` condition. It ensures that only the latest update for each pool is considered. It finds the maximum id from the [pool_update](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_update) table (using the alias `pu2`) for the given `ph.id` and then uses that maximum id to filter the [pool_update](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_update) table in the main query.
`AND pu.id = (SELECT MAX(pu2.id) FROM pool_update pu2 WHERE ph.id = pu2.hash_id)` is a subquery within the `JOIN` condition. It ensures that only the latest update for each pool is considered. It finds the maximum id from the [pool_update](/../../schema.md#pool_update) table (using the alias `pu2`) for the given `ph.id` and then uses that maximum id to filter the [pool_update](/../../schema.md#pool_update) table in the main query.

`JOIN pool_owner po ON pu.id = po.pool_update_id` is another `INNER JOIN` with the [pool_owner](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#pool_owner) table. It connects based on `pu.id = po.pool_update_id`, associating the latest pool update with its owner information.
`JOIN pool_owner po ON pu.id = po.pool_update_id` is another `INNER JOIN` with the [pool_owner](/../../schema.md#pool_owner) table. It connects based on `pu.id = po.pool_update_id`, associating the latest pool update with its owner information.

`JOIN stake_address sa ON po.addr_id = sa.id` The final `INNER JOIN` connects to the [stake_address](https://github.com/cardano-foundation/cf-ledger-sync/blob/main/docs/pages/schema.md#stake_address) table. The condition `po.addr_id = sa.id` links the pool owner's information with the actual stake address details.
`JOIN stake_address sa ON po.addr_id = sa.id` The final `INNER JOIN` connects to the [stake_address](/../../schema.md#stake_address) table. The condition `po.addr_id = sa.id` links the pool owner's information with the actual stake address details.

`WHERE ph."view" = 'pool1j20l32n8un5gce4adk44n9zks8cdvnk3amgursud847cwnpgeg4'` filters the results to include only the data related to the specific pool we provided.

Expand Down

0 comments on commit 93986de

Please sign in to comment.