Skip to content

Commit

Permalink
Fix for pool updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlrt committed Oct 12, 2023
1 parent 4c4da66 commit bc7c646
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 38 deletions.
91 changes: 63 additions & 28 deletions files/grest/rpc/pool/pool_updates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,77 @@ RETURNS TABLE (
meta_url character varying,
meta_hash text,
meta_json jsonb,
pool_status text,
update_type text,
retiring_epoch word31type
)
LANGUAGE plpgsql
AS $$
#variable_conflict use_column
DECLARE
_current_epoch_no word31type;
BEGIN
SELECT COALESCE(MAX(no), 0) INTO _current_epoch_no FROM public.epoch;
RETURN QUERY
SELECT
tx_hash,
block_time::integer,
pool_id_bech32,
pool_id_hex,
active_epoch_no,
vrf_key_hash,
margin,
fixed_cost::text,
pledge::text,
reward_addr,
owners,
relays,
meta_url,
meta_hash,
pod.json,
pool_status,
retiring_epoch
FROM
grest.pool_info_cache AS pic
LEFT JOIN public.pool_offline_data AS pod ON pod.pmr_id = pic.meta_id
WHERE
_pool_bech32 IS NULL
OR
pool_id_bech32 = _pool_bech32
WITH
pool_reg AS (
SELECT
pic.tx_hash,
pic.block_time::integer,
pic.pool_id_bech32,
pic.pool_id_hex,
pic.active_epoch_no,
pic.vrf_key_hash,
pic.margin,
pic.fixed_cost::text,
pic.pledge::text,
pic.reward_addr,
pic.owners,
pic.relays,
pic.meta_url,
pic.meta_hash,
pod.json,
'registration' AS update_type,
NULL::word31type AS retiring_epoch
FROM
grest.pool_info_cache AS pic
LEFT JOIN public.pool_offline_data AS pod ON pod.pmr_id = pic.meta_id
LEFT JOIN public.pool_retire AS pr ON pic.pool_hash_id = pr.hash_id
WHERE _pool_bech32 IS NULL
OR pic.pool_id_bech32 = _pool_bech32),
pool_dereg AS (
SELECT
ENCODE(tx.hash::bytea, 'hex') AS tx_hash,
EXTRACT(EPOCH FROM b.time)::integer AS block_time,
ph.view AS pool_id_bech32,
ENCODE(ph.hash_raw::bytea, 'hex') AS pool_id_hex,
NULL::bigint AS active_epoch_no,
NULL AS vrf_key_hash,
NULL::bigint AS margin,
NULL as fixed_cost,
NULL AS pledge,
NULL AS reward_addr,
NULL::text[] AS owners,
NULL::jsonb[] AS relays,
NULL AS meta_url,
NULL AS meta_hash,
NULL::jsonb AS json,
CASE
WHEN pr.retiring_epoch IS NULL THEN 'registration'
ELSE 'deregistration'
END AS update_type,
pr.retiring_epoch::word31type
FROM public.pool_hash AS ph
LEFT JOIN pool_retire AS pr ON pr.hash_id = ph.id
INNER JOIN public.tx ON tx.id = pr.announced_tx_id
INNER JOIN public.block AS b ON b.id = tx.block_id
WHERE _pool_bech32 IS NULL
OR ph.view = _pool_bech32)
SELECT * FROM pool_reg
UNION SELECT * FROM pool_dereg
ORDER BY
tx_id DESC;
block_time DESC;
END;
$$;

COMMENT ON FUNCTION grest.pool_updates IS 'Return all pool_updates for all pools or only updates for specific pool if specified'; -- noqa: LT01

SELECT grest.pool_updates();
14 changes: 12 additions & 2 deletions specs/results/koiosapi-guild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2499,26 +2499,32 @@ components:
$ref: "#/components/schemas/pool_updates/items/properties/active_epoch_no"
vrf_key_hash:
type: string
nullable: true
description: Pool VRF key hash
example: 25efdad1bc12944d38e4e3c26c43565bec84973a812737b163b289e87d0d5ed3
margin:
type: number
nullable: true
description: Margin (decimal format)
example: 0.1
fixed_cost:
type: string
nullable: true
description: Pool fixed cost per epoch
example: "500000000"
pledge:
type: string
nullable: true
description: Pool pledge in lovelace
example: "64000000000000"
reward_addr:
type: string
nullable: true
description: Pool reward address
example: stake1uy6yzwsxxc28lfms0qmpxvyz9a7y770rtcqx9y96m42cttqwvp4m5
owners:
type: array
nullable: true
items:
type: string
description: Pool (co)owner address
Expand Down Expand Up @@ -2749,6 +2755,7 @@ components:
active_epoch_no:
type: integer
description: Epoch number in which the update becomes active
nullable: true
example: 324
vrf_key_hash:
$ref: "#/components/schemas/pool_info/items/properties/vrf_key_hash"
Expand All @@ -2770,8 +2777,11 @@ components:
$ref: "#/components/schemas/pool_info/items/properties/meta_hash"
meta_json:
$ref: "#/components/schemas/pool_info/items/properties/meta_json"
pool_status:
$ref: "#/components/schemas/pool_info/items/properties/pool_status"
update_type:
type: string
description: Type of update task
enum: ["registration", "deregistration"]
example: registered
retiring_epoch:
$ref: "#/components/schemas/pool_info/items/properties/retiring_epoch"
pool_relays:
Expand Down
14 changes: 12 additions & 2 deletions specs/results/koiosapi-mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2499,26 +2499,32 @@ components:
$ref: "#/components/schemas/pool_updates/items/properties/active_epoch_no"
vrf_key_hash:
type: string
nullable: true
description: Pool VRF key hash
example: 25efdad1bc12944d38e4e3c26c43565bec84973a812737b163b289e87d0d5ed3
margin:
type: number
nullable: true
description: Margin (decimal format)
example: 0.1
fixed_cost:
type: string
nullable: true
description: Pool fixed cost per epoch
example: "500000000"
pledge:
type: string
nullable: true
description: Pool pledge in lovelace
example: "64000000000000"
reward_addr:
type: string
nullable: true
description: Pool reward address
example: stake1uy6yzwsxxc28lfms0qmpxvyz9a7y770rtcqx9y96m42cttqwvp4m5
owners:
type: array
nullable: true
items:
type: string
description: Pool (co)owner address
Expand Down Expand Up @@ -2749,6 +2755,7 @@ components:
active_epoch_no:
type: integer
description: Epoch number in which the update becomes active
nullable: true
example: 324
vrf_key_hash:
$ref: "#/components/schemas/pool_info/items/properties/vrf_key_hash"
Expand All @@ -2770,8 +2777,11 @@ components:
$ref: "#/components/schemas/pool_info/items/properties/meta_hash"
meta_json:
$ref: "#/components/schemas/pool_info/items/properties/meta_json"
pool_status:
$ref: "#/components/schemas/pool_info/items/properties/pool_status"
update_type:
type: string
description: Type of update task
enum: ["registration", "deregistration"]
example: registered
retiring_epoch:
$ref: "#/components/schemas/pool_info/items/properties/retiring_epoch"
pool_relays:
Expand Down
14 changes: 12 additions & 2 deletions specs/results/koiosapi-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2499,26 +2499,32 @@ components:
$ref: "#/components/schemas/pool_updates/items/properties/active_epoch_no"
vrf_key_hash:
type: string
nullable: true
description: Pool VRF key hash
example: 25efdad1bc12944d38e4e3c26c43565bec84973a812737b163b289e87d0d5ed3
margin:
type: number
nullable: true
description: Margin (decimal format)
example: 0.1
fixed_cost:
type: string
nullable: true
description: Pool fixed cost per epoch
example: "500000000"
pledge:
type: string
nullable: true
description: Pool pledge in lovelace
example: "64000000000000"
reward_addr:
type: string
nullable: true
description: Pool reward address
example: stake1uy6yzwsxxc28lfms0qmpxvyz9a7y770rtcqx9y96m42cttqwvp4m5
owners:
type: array
nullable: true
items:
type: string
description: Pool (co)owner address
Expand Down Expand Up @@ -2749,6 +2755,7 @@ components:
active_epoch_no:
type: integer
description: Epoch number in which the update becomes active
nullable: true
example: 324
vrf_key_hash:
$ref: "#/components/schemas/pool_info/items/properties/vrf_key_hash"
Expand All @@ -2770,8 +2777,11 @@ components:
$ref: "#/components/schemas/pool_info/items/properties/meta_hash"
meta_json:
$ref: "#/components/schemas/pool_info/items/properties/meta_json"
pool_status:
$ref: "#/components/schemas/pool_info/items/properties/pool_status"
update_type:
type: string
description: Type of update task
enum: ["registration", "deregistration"]
example: registered
retiring_epoch:
$ref: "#/components/schemas/pool_info/items/properties/retiring_epoch"
pool_relays:
Expand Down
14 changes: 12 additions & 2 deletions specs/results/koiosapi-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2499,26 +2499,32 @@ components:
$ref: "#/components/schemas/pool_updates/items/properties/active_epoch_no"
vrf_key_hash:
type: string
nullable: true
description: Pool VRF key hash
example: 25efdad1bc12944d38e4e3c26c43565bec84973a812737b163b289e87d0d5ed3
margin:
type: number
nullable: true
description: Margin (decimal format)
example: 0.1
fixed_cost:
type: string
nullable: true
description: Pool fixed cost per epoch
example: "500000000"
pledge:
type: string
nullable: true
description: Pool pledge in lovelace
example: "64000000000000"
reward_addr:
type: string
nullable: true
description: Pool reward address
example: stake1uy6yzwsxxc28lfms0qmpxvyz9a7y770rtcqx9y96m42cttqwvp4m5
owners:
type: array
nullable: true
items:
type: string
description: Pool (co)owner address
Expand Down Expand Up @@ -2749,6 +2755,7 @@ components:
active_epoch_no:
type: integer
description: Epoch number in which the update becomes active
nullable: true
example: 324
vrf_key_hash:
$ref: "#/components/schemas/pool_info/items/properties/vrf_key_hash"
Expand All @@ -2770,8 +2777,11 @@ components:
$ref: "#/components/schemas/pool_info/items/properties/meta_hash"
meta_json:
$ref: "#/components/schemas/pool_info/items/properties/meta_json"
pool_status:
$ref: "#/components/schemas/pool_info/items/properties/pool_status"
update_type:
type: string
description: Type of update task
enum: ["registration", "deregistration"]
example: registered
retiring_epoch:
$ref: "#/components/schemas/pool_info/items/properties/retiring_epoch"
pool_relays:
Expand Down
14 changes: 12 additions & 2 deletions specs/templates/4-api-schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,26 +235,32 @@ schemas:
$ref: "#/components/schemas/pool_updates/items/properties/active_epoch_no"
vrf_key_hash:
type: string
nullable: true
description: Pool VRF key hash
example: 25efdad1bc12944d38e4e3c26c43565bec84973a812737b163b289e87d0d5ed3
margin:
type: number
nullable: true
description: Margin (decimal format)
example: 0.1
fixed_cost:
type: string
nullable: true
description: Pool fixed cost per epoch
example: "500000000"
pledge:
type: string
nullable: true
description: Pool pledge in lovelace
example: "64000000000000"
reward_addr:
type: string
nullable: true
description: Pool reward address
example: stake1uy6yzwsxxc28lfms0qmpxvyz9a7y770rtcqx9y96m42cttqwvp4m5
owners:
type: array
nullable: true
items:
type: string
description: Pool (co)owner address
Expand Down Expand Up @@ -485,6 +491,7 @@ schemas:
active_epoch_no:
type: integer
description: Epoch number in which the update becomes active
nullable: true
example: 324
vrf_key_hash:
$ref: "#/components/schemas/pool_info/items/properties/vrf_key_hash"
Expand All @@ -506,8 +513,11 @@ schemas:
$ref: "#/components/schemas/pool_info/items/properties/meta_hash"
meta_json:
$ref: "#/components/schemas/pool_info/items/properties/meta_json"
pool_status:
$ref: "#/components/schemas/pool_info/items/properties/pool_status"
update_type:
type: string
description: Type of update task
enum: ["registration", "deregistration"]
example: registered
retiring_epoch:
$ref: "#/components/schemas/pool_info/items/properties/retiring_epoch"
pool_relays:
Expand Down

0 comments on commit bc7c646

Please sign in to comment.