Skip to content

Commit

Permalink
Update pgtyped (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt authored Dec 29, 2023
1 parent 6f425eb commit 382454f
Show file tree
Hide file tree
Showing 36 changed files with 408 additions and 251 deletions.
2 changes: 0 additions & 2 deletions deployment/config/indexer/docker.mainnet.env
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ PGPASSFILE="$(realpath secrets/.pgpass)"
# as this command will gracefully fallback to PGPASSFILE if no password is specified
# However, some dev tools like pgtyped & zapatos don't support .pgpass files
DATABASE_URL=postgresql://${PGUSER}:${PGPASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
# Needed for PgTyped
PGURI=$DATABASE_URL

CARDANO_NODE_VERSION=8.1.2
CARDANO_NODE_EXPOSED_PORT=3001
Expand Down
2 changes: 0 additions & 2 deletions deployment/config/indexer/docker.preprod.env
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ PGPASSFILE="$(realpath secrets/.pgpass)"
# as this command will gracefully fallback to PGPASSFILE if no password is specified
# However, some dev tools like pgtyped & zapatos don't support .pgpass files
DATABASE_URL=postgresql://${PGUSER}:${PGPASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
# Needed for PgTyped
PGURI=$DATABASE_URL

CARDANO_NODE_VERSION=8.1.2
CARDANO_NODE_EXPOSED_PORT=3001
Expand Down
2 changes: 0 additions & 2 deletions deployment/config/indexer/docker.preview.env
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ PGPASSFILE="$(realpath secrets/.pgpass)"
# as this command will gracefully fallback to PGPASSFILE if no password is specified
# However, some dev tools like pgtyped & zapatos don't support .pgpass files
DATABASE_URL=postgresql://${PGUSER}:${PGPASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
# Needed for PgTyped
PGURI=$DATABASE_URL

CARDANO_NODE_VERSION=8.1.2
CARDANO_NODE_EXPOSED_PORT=3001
Expand Down
12 changes: 2 additions & 10 deletions docs/bin/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,7 @@
"format": "double"
},
"txId": {
"type": "string",
"nullable": true
"type": "string"
},
"pool": {
"allOf": [
Expand Down Expand Up @@ -874,18 +873,12 @@
},
"plutusDatum": {
"type": "string",
"nullable": true,
"description": "Projected NFT datum: serialized state of the Projected NFT",
"example": "d8799fd8799f581c9040f057461d9adc09108fe5cb630077cf75c6e981d3ed91f6fb18f6ffd87980ff",
"pattern": "[0-9a-fA-F]+"
},
"status": {
"allOf": [
{
"$ref": "#/components/schemas/ProjectedNftStatus"
}
],
"nullable": true,
"$ref": "#/components/schemas/ProjectedNftStatus",
"description": "Projected NFT status: Lock / Unlocking / Claim / Invalid",
"example": "Lock"
},
Expand Down Expand Up @@ -929,7 +922,6 @@
},
"actionTxId": {
"type": "string",
"nullable": true,
"description": "Transaction id of related Projected NFT event",
"example": "28eb069e3e8c13831d431e3b2e35f58525493ab2d77fde83184993e4aa7a0eda",
"pattern": "[0-9a-fA-F]{64}"
Expand Down
2 changes: 0 additions & 2 deletions docs/docs/indexer/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ PGPASSFILE="$(realpath secrets/.pgpass)"
# as this command will gracefully fallback to PGPASSFILE if no password is specified
# However, some dev tools like pgtyped & zapatos don't support .pgpass files
DATABASE_URL=postgresql://${PGUSER}:${PGPASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
# Needed for PgTyped
PGURI=$DATABASE_URL
```

Please set `NETWORK`, `CONFIG_FILE` and postgres variables carefully. `CONFIG_FILE` should be located in `deployment/config/indexer` folder. You can use `CARP_CONFIG` env variable instead of `CONFIG_FILE` if you want to use just env variables for configuration.
Expand Down
2 changes: 0 additions & 2 deletions docs/docs/indexer/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ PGPASSFILE="$(realpath secrets/.pgpass)"
# as this command will gracefully fallback to PGPASSFILE if no password is specified
# However, some dev tools like pgtyped & zapatos don't support .pgpass files
DATABASE_URL=postgresql://${PGUSER}:${PGPASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
# Needed for PgTyped
PGURI=$DATABASE_URL
```

Variables related to postgres are described above in `Setting up the database` section.
4 changes: 2 additions & 2 deletions indexer/tasks/src/multiera/multiera_projected_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl TryFrom<i32> for ProjectedNftOperation {
3 => Ok(ProjectedNftOperation::ParseError),
4 => Ok(ProjectedNftOperation::NoDatum),
5 => Ok(ProjectedNftOperation::NotInlineDatum),
_ => Err("can't parse projeced nft operation".to_string()),
_ => Err("can't parse projected nft operation".to_string()),
}
}
}
Expand Down Expand Up @@ -565,7 +565,7 @@ impl AssetData {

#[derive(Debug, Clone, Default)]
struct ProjectedNftData {
pub previous_utxo_tx_hash: Vec<u8>,
pub previous_utxo_tx_hash: Vec<u8>, // warning: this isn't nullable, but can be an empty vector to represent null
pub previous_utxo_tx_output_index: Option<i64>,
pub address: Vec<u8>,
pub plutus_data: Vec<u8>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export class DelegationForPoolController extends Controller {
});

return data.map(data => ({
credential: data.credential as string,
credential: data.credential,
pool: data.pool,
txId: data.tx_id as string,
txId: data.tx_id,
slot: data.slot,
}));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class ProjectedNftRangeController extends Controller {
policyId: data.policy_id,
assetName: data.asset_name,
amount: data.amount,
status: data.status as ProjectedNftStatus | null,
status: data.status as ProjectedNftStatus,
plutusDatum: data.plutus_datum,
actionSlot: data.action_slot,
forHowLong: data.for_how_long,
Expand Down Expand Up @@ -108,7 +108,7 @@ export class ProjectedNftRangeController extends Controller {
policyId: data.policy_id,
assetName: data.asset_name,
amount: data.amount,
status: data.status as ProjectedNftStatus | null,
status: data.status as ProjectedNftStatus,
plutusDatum: data.plutus_datum,
actionSlot: data.action_slot,
forHowLong: data.for_how_long,
Expand Down
10 changes: 6 additions & 4 deletions webserver/server/app/models/address/sqlAddressUsed.queries.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/** Types generated for queries found in "app/models/address/sqlAddressUsed.sql" */
import { PreparedQuery } from '@pgtyped/query';
import { PreparedQuery } from '@pgtyped/runtime';

export type BufferArray = (Buffer)[];

export type NumberOrString = number | string;

/** 'SqlAddressUsed' parameters type */
export interface ISqlAddressUsedParams {
addresses: BufferArray | null | void;
after_tx_id: string | null | void;
until_tx_id: string | null | void;
addresses?: BufferArray | null | void;
after_tx_id?: NumberOrString | null | void;
until_tx_id?: NumberOrString | null | void;
}

/** 'SqlAddressUsed' return type */
Expand Down
10 changes: 6 additions & 4 deletions webserver/server/app/models/address/sqlCredentialUsed.queries.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/** Types generated for queries found in "app/models/address/sqlCredentialUsed.sql" */
import { PreparedQuery } from '@pgtyped/query';
import { PreparedQuery } from '@pgtyped/runtime';

export type BufferArray = (Buffer)[];

export type NumberOrString = number | string;

/** 'SqlCredentialUsed' parameters type */
export interface ISqlCredentialUsedParams {
after_tx_id: string | null | void;
credentials: BufferArray | null | void;
until_tx_id: string | null | void;
after_tx_id?: NumberOrString | null | void;
credentials?: BufferArray | null | void;
until_tx_id?: NumberOrString | null | void;
}

/** 'SqlCredentialUsed' return type */
Expand Down
2 changes: 1 addition & 1 deletion webserver/server/app/models/asset/assetUtxos.queries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** Types generated for queries found in "app/models/asset/assetUtxos.sql" */
import { PreparedQuery } from '@pgtyped/query';
import { PreparedQuery } from '@pgtyped/runtime';

/** 'AssetUtxos' parameters type */
export interface IAssetUtxosParams {
Expand Down
6 changes: 4 additions & 2 deletions webserver/server/app/models/block/sqlBlockLatest.queries.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/** Types generated for queries found in "app/models/block/sqlBlockLatest.sql" */
import { PreparedQuery } from '@pgtyped/query';
import { PreparedQuery } from '@pgtyped/runtime';

export type NumberOrString = number | string;

/** 'SqlBlockLatest' parameters type */
export interface ISqlBlockLatestParams {
offset: string | null | void;
offset?: NumberOrString | null | void;
}

/** 'SqlBlockLatest' return type */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/** Types generated for queries found in "app/models/credentials/sqlCredentialAddresses.sql" */
import { PreparedQuery } from '@pgtyped/query';
import { PreparedQuery } from '@pgtyped/runtime';

export type BufferArray = (Buffer)[];

export type NumberOrString = number | string;

/** 'SqlCredentialAddresses' parameters type */
export interface ISqlCredentialAddressesParams {
after_address: Buffer | null | void;
credentials: BufferArray | null | void;
double_limit: string | null | void;
limit: string | null | void;
until_tx_id: string | null | void;
after_address?: Buffer | null | void;
credentials?: BufferArray | null | void;
double_limit?: NumberOrString | null | void;
limit?: NumberOrString | null | void;
until_tx_id?: NumberOrString | null | void;
}

/** 'SqlCredentialAddresses' return type */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** Types generated for queries found in "app/models/delegation/delegationForAddress.sql" */
import { PreparedQuery } from '@pgtyped/query';
import { PreparedQuery } from '@pgtyped/runtime';

/** 'SqlStakeDelegationForAddress' parameters type */
export interface ISqlStakeDelegationForAddressParams {
Expand All @@ -9,8 +9,8 @@ export interface ISqlStakeDelegationForAddressParams {

/** 'SqlStakeDelegationForAddress' return type */
export interface ISqlStakeDelegationForAddressResult {
pool: string | null;
tx_id: string | null;
pool: string;
tx_id: string;
}

/** 'SqlStakeDelegationForAddress' query type */
Expand All @@ -19,12 +19,12 @@ export interface ISqlStakeDelegationForAddressQuery {
result: ISqlStakeDelegationForAddressResult;
}

const sqlStakeDelegationForAddressIR: any = {"usedParamSet":{"credential":true,"slot":true},"params":[{"name":"credential","required":true,"transform":{"type":"scalar"},"locs":[{"a":371,"b":382}]},{"name":"slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":405,"b":410}]}],"statement":"SELECT encode(pool_credential, 'hex') as pool, encode(\"Transaction\".hash, 'hex') as tx_id\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\t\"StakeCredential\".credential = :credential! AND\n\t\"Block\".slot <= :slot!\nORDER BY (\"Block\".height, \"Transaction\".tx_index) DESC\nLIMIT 1"};
const sqlStakeDelegationForAddressIR: any = {"usedParamSet":{"credential":true,"slot":true},"params":[{"name":"credential","required":true,"transform":{"type":"scalar"},"locs":[{"a":377,"b":388}]},{"name":"slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":411,"b":416}]}],"statement":"SELECT encode(pool_credential, 'hex') as \"pool!\", encode(\"Transaction\".hash, 'hex') as \"tx_id!\"\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\t\"StakeCredential\".credential = :credential! AND\n\t\"Block\".slot <= :slot!\nORDER BY (\"Block\".height, \"Transaction\".tx_index) DESC\nLIMIT 1"};

/**
* Query generated from SQL:
* ```
* SELECT encode(pool_credential, 'hex') as pool, encode("Transaction".hash, 'hex') as tx_id
* SELECT encode(pool_credential, 'hex') as "pool!", encode("Transaction".hash, 'hex') as "tx_id!"
* 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
@@ -1,5 +1,5 @@
/* @name sqlStakeDelegationForAddress */
SELECT encode(pool_credential, 'hex') as pool, encode("Transaction".hash, 'hex') as tx_id
SELECT encode(pool_credential, 'hex') as "pool!", encode("Transaction".hash, 'hex') as "tx_id!"
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
@@ -1,5 +1,5 @@
/** Types generated for queries found in "app/models/delegation/delegationsForPool.sql" */
import { PreparedQuery } from '@pgtyped/query';
import { PreparedQuery } from '@pgtyped/runtime';

/** 'SqlStakeDelegationByPool' parameters type */
export interface ISqlStakeDelegationByPoolParams {
Expand All @@ -10,10 +10,10 @@ export interface ISqlStakeDelegationByPoolParams {

/** 'SqlStakeDelegationByPool' return type */
export interface ISqlStakeDelegationByPoolResult {
credential: string | null;
credential: string;
pool: string | null;
slot: number;
tx_id: string | null;
tx_id: string;
}

/** 'SqlStakeDelegationByPool' query type */
Expand All @@ -22,16 +22,19 @@ 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":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"};
const sqlStakeDelegationByPoolIR: any = {"usedParamSet":{"pools":true,"min_slot":true,"max_slot":true},"params":[{"name":"pools","required":true,"transform":{"type":"array_spread"},"locs":[{"a":182,"b":188},{"a":604,"b":610},{"a":671,"b":677}]},{"name":"min_slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":702,"b":711}]},{"name":"max_slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":734,"b":743}]}],"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! \n\t\tTHEN encode(\"StakeDelegationCredentialRelation\".pool_credential, 'hex') \n\t\tELSE NULL\n\t\tEND 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,
* encode(credential, 'hex') as "credential!",
* encode("Transaction".hash, 'hex') as "tx_id!",
* "Block".slot,
* CASE WHEN "StakeDelegationCredentialRelation".pool_credential IN :pools! THEN encode("StakeDelegationCredentialRelation".pool_credential, 'hex') ELSE NULL END AS pool
* 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
9 changes: 6 additions & 3 deletions webserver/server/app/models/delegation/delegationsForPool.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
@param pools -> (...)
*/
SELECT
encode(credential, 'hex') as credential,
encode("Transaction".hash, 'hex') as tx_id,
encode(credential, 'hex') as "credential!",
encode("Transaction".hash, 'hex') as "tx_id!",
"Block".slot,
CASE WHEN "StakeDelegationCredentialRelation".pool_credential IN :pools! THEN encode("StakeDelegationCredentialRelation".pool_credential, 'hex') ELSE NULL END AS pool
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
16 changes: 9 additions & 7 deletions webserver/server/app/models/dex/sqlDexLastPrice.queries.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/** Types generated for queries found in "app/models/dex/sqlDexLastPrice.sql" */
import { PreparedQuery } from '@pgtyped/query';
import { PreparedQuery } from '@pgtyped/runtime';

export type BufferArray = (Buffer)[];

export type NumberOrString = number | string;

/** 'SqlDexLastPrice' parameters type */
export interface ISqlDexLastPriceParams {
asset_name1: BufferArray | null | void;
asset_name2: BufferArray | null | void;
operation1: string | null | void;
operation2: string | null | void;
policy_id1: BufferArray | null | void;
policy_id2: BufferArray | null | void;
asset_name1?: BufferArray | null | void;
asset_name2?: BufferArray | null | void;
operation1?: NumberOrString | null | void;
operation2?: NumberOrString | null | void;
policy_id1?: BufferArray | null | void;
policy_id2?: BufferArray | null | void;
}

/** 'SqlDexLastPrice' return type */
Expand Down
22 changes: 12 additions & 10 deletions webserver/server/app/models/dex/sqlDexMeanPrice.queries.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/** Types generated for queries found in "app/models/dex/sqlDexMeanPrice.sql" */
import { PreparedQuery } from '@pgtyped/query';
import { PreparedQuery } from '@pgtyped/runtime';

export type BufferArray = (Buffer)[];

export type stringArray = (string)[];
export type NumberOrString = number | string;

export type NumberOrStringArray = (NumberOrString)[];

/** 'SqlDexMeanPrice' parameters type */
export interface ISqlDexMeanPriceParams {
after_tx_id: string | null | void;
asset_name1: BufferArray | null | void;
asset_name2: BufferArray | null | void;
dexes: stringArray | null | void;
limit: string | null | void;
policy_id1: BufferArray | null | void;
policy_id2: BufferArray | null | void;
until_tx_id: string | null | void;
after_tx_id?: NumberOrString | null | void;
asset_name1?: BufferArray | null | void;
asset_name2?: BufferArray | null | void;
dexes?: NumberOrStringArray | null | void;
limit?: NumberOrString | null | void;
policy_id1?: BufferArray | null | void;
policy_id2?: BufferArray | null | void;
until_tx_id?: NumberOrString | null | void;
}

/** 'SqlDexMeanPrice' return type */
Expand Down
Loading

0 comments on commit 382454f

Please sign in to comment.