From 21785b0b53e17b005896080221d4dc900f09b25d Mon Sep 17 00:00:00 2001 From: Enzo Cioppettini Date: Tue, 24 Oct 2023 00:18:30 -0300 Subject: [PATCH] add slot and pool fields to the delegation for pool query --- docs/bin/openapi.json | 26 +++++++++++++------ .../DelegationForPoolController.ts | 6 ++--- .../delegation/delegationsForPool.queries.ts | 8 +++--- .../models/delegation/delegationsForPool.sql | 3 ++- webserver/shared/models/DelegationForPool.ts | 5 ++-- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/docs/bin/openapi.json b/docs/bin/openapi.json index 748efc5b..70171b2f 100644 --- a/docs/bin/openapi.json +++ b/docs/bin/openapi.json @@ -323,34 +323,44 @@ ], "type": "object" }, + "PoolHex": { + "type": "string", + "example": "8200581c8baf48931c5187cd59fde553f4e7da2e1a2aa9202ec6e67815cb3f8a", + "pattern": "[0-9a-fA-F]{56}" + }, "DelegationForPoolResponse": { "items": { "properties": { + "slot": { + "type": "number", + "format": "double" + }, "txId": { "type": "string", "nullable": true }, - "isDelegation": { - "type": "boolean" + "pool": { + "allOf": [ + { + "$ref": "#/components/schemas/PoolHex" + } + ], + "nullable": true }, "credential": { "$ref": "#/components/schemas/Address" } }, "required": [ + "slot", "txId", - "isDelegation", + "pool", "credential" ], "type": "object" }, "type": "array" }, - "PoolHex": { - "type": "string", - "example": "8200581c8baf48931c5187cd59fde553f4e7da2e1a2aa9202ec6e67815cb3f8a", - "pattern": "[0-9a-fA-F]{56}" - }, "Pool": { "$ref": "#/components/schemas/PoolHex" }, diff --git a/webserver/server/app/controllers/DelegationForPoolController.ts b/webserver/server/app/controllers/DelegationForPoolController.ts index 0a569e7d..a2e6b8a5 100644 --- a/webserver/server/app/controllers/DelegationForPoolController.ts +++ b/webserver/server/app/controllers/DelegationForPoolController.ts @@ -3,11 +3,8 @@ import { StatusCodes } from 'http-status-codes'; import tx from 'pg-tx'; import pool from '../services/PgPoolSingleton'; import type { ErrorShape } from '../../../shared/errors'; -import { genErrorMessage } from '../../../shared/errors'; -import { Errors } from '../../../shared/errors'; import type { EndpointTypes } from '../../../shared/routes'; import { Routes } from '../../../shared/routes'; -import { getAddressTypes } from '../models/utils'; import { delegationsForPool } from '../services/DelegationForPool'; import { DelegationForPoolResponse } from '../../../shared/models/DelegationForPool'; @@ -37,8 +34,9 @@ export class DelegationForPoolController extends Controller { return data.map(data => ({ credential: data.credential as string, - isDelegation: data.is_delegation as boolean, + pool: data.pool, txId: data.tx_id as string, + slot: data.slot, })); }); diff --git a/webserver/server/app/models/delegation/delegationsForPool.queries.ts b/webserver/server/app/models/delegation/delegationsForPool.queries.ts index 75c9f0f9..45e1d7c4 100644 --- a/webserver/server/app/models/delegation/delegationsForPool.queries.ts +++ b/webserver/server/app/models/delegation/delegationsForPool.queries.ts @@ -11,7 +11,8 @@ export interface ISqlStakeDelegationByPoolParams { /** 'SqlStakeDelegationByPool' return type */ export interface ISqlStakeDelegationByPoolResult { credential: string | null; - is_delegation: boolean | null; + pool: string | null; + slot: number; tx_id: string | null; } @@ -21,7 +22,7 @@ export interface ISqlStakeDelegationByPoolQuery { result: ISqlStakeDelegationByPoolResult; } -const sqlStakeDelegationByPoolIR: any = {"usedParamSet":{"pools":true,"min_slot":true,"max_slot":true},"params":[{"name":"pools","required":true,"transform":{"type":"array_spread"},"locs":[{"a":160,"b":166},{"a":505,"b":511},{"a":572,"b":578}]},{"name":"min_slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":603,"b":612}]},{"name":"max_slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":635,"b":644}]}],"statement":"SELECT \n\tencode(credential, 'hex') as credential,\n\tencode(\"Transaction\".hash, 'hex') as tx_id,\n\tCOALESCE(\"StakeDelegationCredentialRelation\".pool_credential IN :pools!, false) as is_delegation\nFROM \"StakeDelegationCredentialRelation\"\nJOIN \"StakeCredential\" ON stake_credential = \"StakeCredential\".id\nJOIN \"Transaction\" ON \"Transaction\".id = \"StakeDelegationCredentialRelation\".tx_id\nJOIN \"Block\" ON \"Transaction\".block_id = \"Block\".id\nWHERE \n (\n\t\t\"StakeDelegationCredentialRelation\".pool_credential IN :pools! OR\n\t \t\"StakeDelegationCredentialRelation\".previous_pool IN :pools!\n\t) AND\n\t\"Block\".slot > :min_slot! AND\n\t\"Block\".slot <= :max_slot!\nORDER BY (\"Block\".height, \"Transaction\".tx_index) ASC"}; +const sqlStakeDelegationByPoolIR: any = {"usedParamSet":{"pools":true,"min_slot":true,"max_slot":true},"params":[{"name":"pools","required":true,"transform":{"type":"array_spread"},"locs":[{"a":176,"b":182},{"a":590,"b":596},{"a":657,"b":663}]},{"name":"min_slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":688,"b":697}]},{"name":"max_slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":720,"b":729}]}],"statement":"SELECT \n\tencode(credential, 'hex') as credential,\n\tencode(\"Transaction\".hash, 'hex') as tx_id,\n\t\"Block\".slot,\n\tCASE WHEN \"StakeDelegationCredentialRelation\".pool_credential IN :pools! THEN encode(\"StakeDelegationCredentialRelation\".pool_credential, 'hex') ELSE NULL END AS pool\nFROM \"StakeDelegationCredentialRelation\"\nJOIN \"StakeCredential\" ON stake_credential = \"StakeCredential\".id\nJOIN \"Transaction\" ON \"Transaction\".id = \"StakeDelegationCredentialRelation\".tx_id\nJOIN \"Block\" ON \"Transaction\".block_id = \"Block\".id\nWHERE \n (\n\t\t\"StakeDelegationCredentialRelation\".pool_credential IN :pools! OR\n\t \t\"StakeDelegationCredentialRelation\".previous_pool IN :pools!\n\t) AND\n\t\"Block\".slot > :min_slot! AND\n\t\"Block\".slot <= :max_slot!\nORDER BY (\"Block\".height, \"Transaction\".tx_index) ASC"}; /** * Query generated from SQL: @@ -29,7 +30,8 @@ const sqlStakeDelegationByPoolIR: any = {"usedParamSet":{"pools":true,"min_slot" * SELECT * encode(credential, 'hex') as credential, * encode("Transaction".hash, 'hex') as tx_id, - * COALESCE("StakeDelegationCredentialRelation".pool_credential IN :pools!, false) as is_delegation + * "Block".slot, + * CASE WHEN "StakeDelegationCredentialRelation".pool_credential IN :pools! THEN encode("StakeDelegationCredentialRelation".pool_credential, 'hex') ELSE NULL END AS pool * FROM "StakeDelegationCredentialRelation" * JOIN "StakeCredential" ON stake_credential = "StakeCredential".id * JOIN "Transaction" ON "Transaction".id = "StakeDelegationCredentialRelation".tx_id diff --git a/webserver/server/app/models/delegation/delegationsForPool.sql b/webserver/server/app/models/delegation/delegationsForPool.sql index c2ea2a57..2e9379c1 100644 --- a/webserver/server/app/models/delegation/delegationsForPool.sql +++ b/webserver/server/app/models/delegation/delegationsForPool.sql @@ -5,7 +5,8 @@ SELECT encode(credential, 'hex') as credential, encode("Transaction".hash, 'hex') as tx_id, - COALESCE("StakeDelegationCredentialRelation".pool_credential IN :pools!, false) as is_delegation + "Block".slot, + CASE WHEN "StakeDelegationCredentialRelation".pool_credential IN :pools! THEN encode("StakeDelegationCredentialRelation".pool_credential, 'hex') ELSE NULL END AS pool FROM "StakeDelegationCredentialRelation" JOIN "StakeCredential" ON stake_credential = "StakeCredential".id JOIN "Transaction" ON "Transaction".id = "StakeDelegationCredentialRelation".tx_id diff --git a/webserver/shared/models/DelegationForPool.ts b/webserver/shared/models/DelegationForPool.ts index fd7f05ac..37209e58 100644 --- a/webserver/shared/models/DelegationForPool.ts +++ b/webserver/shared/models/DelegationForPool.ts @@ -1,5 +1,5 @@ import { Address } from "./Address"; -import { Pool } from "./Pool"; +import { Pool, PoolHex } from "./Pool"; export type DelegationForPoolRequest = { pools: Pool[]; @@ -8,6 +8,7 @@ export type DelegationForPoolRequest = { export type DelegationForPoolResponse = { credential: Address; - isDelegation: boolean, + pool: PoolHex | null, txId: string | null; + slot: number; }[]; \ No newline at end of file