Skip to content

Commit

Permalink
add slot and pool fields to the delegation for pool query
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Oct 24, 2023
1 parent b9ad7ab commit 21785b0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
26 changes: 18 additions & 8 deletions docs/bin/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
}));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -21,15 +22,16 @@ 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:
* ```
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions webserver/shared/models/DelegationForPool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address } from "./Address";
import { Pool } from "./Pool";
import { Pool, PoolHex } from "./Pool";

export type DelegationForPoolRequest = {
pools: Pool[];
Expand All @@ -8,6 +8,7 @@ export type DelegationForPoolRequest = {

export type DelegationForPoolResponse = {
credential: Address;
isDelegation: boolean,
pool: PoolHex | null,
txId: string | null;
slot: number;
}[];

0 comments on commit 21785b0

Please sign in to comment.