diff --git a/files/grest/rpc/pool/pool_updates.sql b/files/grest/rpc/pool/pool_updates.sql index ac4ca722..4cd4c48d 100644 --- a/files/grest/rpc/pool/pool_updates.sql +++ b/files/grest/rpc/pool/pool_updates.sql @@ -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(); \ No newline at end of file diff --git a/specs/results/koiosapi-guild.yaml b/specs/results/koiosapi-guild.yaml index 022ad899..1bfb461d 100644 --- a/specs/results/koiosapi-guild.yaml +++ b/specs/results/koiosapi-guild.yaml @@ -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 @@ -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" @@ -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: diff --git a/specs/results/koiosapi-mainnet.yaml b/specs/results/koiosapi-mainnet.yaml index fecaa9d7..f8005196 100644 --- a/specs/results/koiosapi-mainnet.yaml +++ b/specs/results/koiosapi-mainnet.yaml @@ -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 @@ -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" @@ -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: diff --git a/specs/results/koiosapi-preprod.yaml b/specs/results/koiosapi-preprod.yaml index ffdf51c6..222bbe72 100644 --- a/specs/results/koiosapi-preprod.yaml +++ b/specs/results/koiosapi-preprod.yaml @@ -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 @@ -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" @@ -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: diff --git a/specs/results/koiosapi-preview.yaml b/specs/results/koiosapi-preview.yaml index a3b6b0ed..25db005a 100644 --- a/specs/results/koiosapi-preview.yaml +++ b/specs/results/koiosapi-preview.yaml @@ -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 @@ -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" @@ -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: diff --git a/specs/templates/4-api-schemas.yaml b/specs/templates/4-api-schemas.yaml index 8cb76486..942a0582 100644 --- a/specs/templates/4-api-schemas.yaml +++ b/specs/templates/4-api-schemas.yaml @@ -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 @@ -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" @@ -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: