-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
269 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
webserver/server/app/models/asset/sqlMintRange.queries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/** Types generated for queries found in "app/models/asset/sqlMintRange.sql" */ | ||
import { PreparedQuery } from '@pgtyped/query'; | ||
|
||
/** 'SqlMintRange' parameters type */ | ||
export interface ISqlMintRangeParams { | ||
limit: string; | ||
max_slot: number; | ||
min_slot: number; | ||
} | ||
|
||
/** 'SqlMintRange' return type */ | ||
export interface ISqlMintRangeResult { | ||
action_slot: number; | ||
action_tx_id: string | null; | ||
amount: string; | ||
asset_name: string | null; | ||
policy_id: string | null; | ||
} | ||
|
||
/** 'SqlMintRange' query type */ | ||
export interface ISqlMintRangeQuery { | ||
params: ISqlMintRangeParams; | ||
result: ISqlMintRangeResult; | ||
} | ||
|
||
const sqlMintRangeIR: any = {"usedParamSet":{"min_slot":true,"max_slot":true,"limit":true},"params":[{"name":"min_slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":490,"b":499},{"a":942,"b":951}]},{"name":"max_slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":525,"b":534},{"a":989,"b":998}]},{"name":"limit","required":true,"transform":{"type":"scalar"},"locs":[{"a":1018,"b":1024}]}],"statement":"SELECT\n \"AssetMint\".amount as amount,\n encode(\"NativeAsset\".policy_id, 'hex') as policy_id,\n encode(\"NativeAsset\".asset_name, 'hex') as asset_name,\n encode(\"Transaction\".hash, 'hex') as action_tx_id,\n \"Block\".slot as action_slot\nFROM \"AssetMint\"\n JOIN \"NativeAsset\" ON \"NativeAsset\".id = \"AssetMint\".asset_id\n JOIN \"Transaction\" ON \"Transaction\".id = \"AssetMint\".tx_id\n JOIN \"Block\" ON \"Transaction\".block_id = \"Block\".id\nWHERE\n \"Block\".slot > :min_slot!\n AND \"Block\".slot <= :max_slot!\n AND \"Block\".height <= (\n SELECT MAX(\"Heights\".height) FROM\n (SELECT \"Block\".height as height FROM \"AssetMint\"\n JOIN \"NativeAsset\" ON \"NativeAsset\".id = \"AssetMint\".asset_id\n JOIN \"Transaction\" ON \"Transaction\".id = \"AssetMint\".tx_id\n JOIN \"Block\" ON \"Transaction\".block_id = \"Block\".id\n WHERE\n \"Block\".slot > :min_slot!\n AND \"Block\".slot <= :max_slot!\n LIMIT :limit!) AS \"Heights\"\n )\nORDER BY (\"Block\".height, \"Transaction\".tx_index) ASC"}; | ||
|
||
/** | ||
* Query generated from SQL: | ||
* ``` | ||
* SELECT | ||
* "AssetMint".amount as amount, | ||
* encode("NativeAsset".policy_id, 'hex') as policy_id, | ||
* encode("NativeAsset".asset_name, 'hex') as asset_name, | ||
* encode("Transaction".hash, 'hex') as action_tx_id, | ||
* "Block".slot as action_slot | ||
* FROM "AssetMint" | ||
* JOIN "NativeAsset" ON "NativeAsset".id = "AssetMint".asset_id | ||
* JOIN "Transaction" ON "Transaction".id = "AssetMint".tx_id | ||
* JOIN "Block" ON "Transaction".block_id = "Block".id | ||
* WHERE | ||
* "Block".slot > :min_slot! | ||
* AND "Block".slot <= :max_slot! | ||
* AND "Block".height <= ( | ||
* SELECT MAX("Heights".height) FROM | ||
* (SELECT "Block".height as height FROM "AssetMint" | ||
* JOIN "NativeAsset" ON "NativeAsset".id = "AssetMint".asset_id | ||
* JOIN "Transaction" ON "Transaction".id = "AssetMint".tx_id | ||
* JOIN "Block" ON "Transaction".block_id = "Block".id | ||
* WHERE | ||
* "Block".slot > :min_slot! | ||
* AND "Block".slot <= :max_slot! | ||
* LIMIT :limit!) AS "Heights" | ||
* ) | ||
* ORDER BY ("Block".height, "Transaction".tx_index) ASC | ||
* ``` | ||
*/ | ||
export const sqlMintRange = new PreparedQuery<ISqlMintRangeParams,ISqlMintRangeResult>(sqlMintRangeIR); | ||
|
||
|
||
/** 'SqlMintRangeByPolicyIds' parameters type */ | ||
export interface ISqlMintRangeByPolicyIdsParams { | ||
limit: string; | ||
max_slot: number; | ||
min_slot: number; | ||
policy_ids: readonly (Buffer)[]; | ||
} | ||
|
||
/** 'SqlMintRangeByPolicyIds' return type */ | ||
export interface ISqlMintRangeByPolicyIdsResult { | ||
action_slot: number; | ||
action_tx_id: string | null; | ||
amount: string; | ||
asset_name: string | null; | ||
policy_id: string | null; | ||
} | ||
|
||
/** 'SqlMintRangeByPolicyIds' query type */ | ||
export interface ISqlMintRangeByPolicyIdsQuery { | ||
params: ISqlMintRangeByPolicyIdsParams; | ||
result: ISqlMintRangeByPolicyIdsResult; | ||
} | ||
|
||
const sqlMintRangeByPolicyIdsIR: any = {"usedParamSet":{"min_slot":true,"max_slot":true,"policy_ids":true,"limit":true},"params":[{"name":"policy_ids","required":true,"transform":{"type":"array_spread"},"locs":[{"a":571,"b":582},{"a":1095,"b":1106}]},{"name":"min_slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":490,"b":499},{"a":990,"b":999}]},{"name":"max_slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":525,"b":534},{"a":1037,"b":1046}]},{"name":"limit","required":true,"transform":{"type":"scalar"},"locs":[{"a":1126,"b":1132}]}],"statement":"SELECT\n \"AssetMint\".amount as amount,\n encode(\"NativeAsset\".policy_id, 'hex') as policy_id,\n encode(\"NativeAsset\".asset_name, 'hex') as asset_name,\n encode(\"Transaction\".hash, 'hex') as action_tx_id,\n \"Block\".slot as action_slot\nFROM \"AssetMint\"\n JOIN \"NativeAsset\" ON \"NativeAsset\".id = \"AssetMint\".asset_id\n JOIN \"Transaction\" ON \"Transaction\".id = \"AssetMint\".tx_id\n JOIN \"Block\" ON \"Transaction\".block_id = \"Block\".id\nWHERE\n \"Block\".slot > :min_slot!\n AND \"Block\".slot <= :max_slot!\n AND \"NativeAsset\".policy_id IN :policy_ids!\n AND \"Block\".height <= (\n SELECT MAX(\"Heights\".height) FROM\n (SELECT \"Block\".height as height FROM \"AssetMint\"\n JOIN \"NativeAsset\" ON \"NativeAsset\".id = \"AssetMint\".asset_id\n JOIN \"Transaction\" ON \"Transaction\".id = \"AssetMint\".tx_id\n JOIN \"Block\" ON \"Transaction\".block_id = \"Block\".id\n WHERE\n \"Block\".slot > :min_slot!\n AND \"Block\".slot <= :max_slot!\n AND \"NativeAsset\".policy_id IN :policy_ids!\n LIMIT :limit!) AS \"Heights\"\n )\nORDER BY (\"Block\".height, \"Transaction\".tx_index) ASC"}; | ||
|
||
/** | ||
* Query generated from SQL: | ||
* ``` | ||
* SELECT | ||
* "AssetMint".amount as amount, | ||
* encode("NativeAsset".policy_id, 'hex') as policy_id, | ||
* encode("NativeAsset".asset_name, 'hex') as asset_name, | ||
* encode("Transaction".hash, 'hex') as action_tx_id, | ||
* "Block".slot as action_slot | ||
* FROM "AssetMint" | ||
* JOIN "NativeAsset" ON "NativeAsset".id = "AssetMint".asset_id | ||
* JOIN "Transaction" ON "Transaction".id = "AssetMint".tx_id | ||
* JOIN "Block" ON "Transaction".block_id = "Block".id | ||
* WHERE | ||
* "Block".slot > :min_slot! | ||
* AND "Block".slot <= :max_slot! | ||
* AND "NativeAsset".policy_id IN :policy_ids! | ||
* AND "Block".height <= ( | ||
* SELECT MAX("Heights".height) FROM | ||
* (SELECT "Block".height as height FROM "AssetMint" | ||
* JOIN "NativeAsset" ON "NativeAsset".id = "AssetMint".asset_id | ||
* JOIN "Transaction" ON "Transaction".id = "AssetMint".tx_id | ||
* JOIN "Block" ON "Transaction".block_id = "Block".id | ||
* WHERE | ||
* "Block".slot > :min_slot! | ||
* AND "Block".slot <= :max_slot! | ||
* AND "NativeAsset".policy_id IN :policy_ids! | ||
* LIMIT :limit!) AS "Heights" | ||
* ) | ||
* ORDER BY ("Block".height, "Transaction".tx_index) ASC | ||
* ``` | ||
*/ | ||
export const sqlMintRangeByPolicyIds = new PreparedQuery<ISqlMintRangeByPolicyIdsParams,ISqlMintRangeByPolicyIdsResult>(sqlMintRangeByPolicyIdsIR); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
import type { PoolClient } from 'pg'; | ||
import type { ISqlMintRangeResult} from '../models/assets/mintRange.queries'; | ||
import { sqlMintRange } from '../models/assets/mintRange.queries'; | ||
import type { ISqlMintRangeResult, ISqlMintRangeByPolicyIdsResult } from '../models/asset/sqlMintRange.queries'; | ||
import { sqlMintRange, sqlMintRangeByPolicyIds } from '../models/asset/sqlMintRange.queries'; | ||
import type { PolicyId } from "../../../shared/models/PolicyIdAssetMap"; | ||
|
||
export async function mintRange(request: { | ||
range: { minSlot: number, maxSlot: number }, | ||
params: { afterSlot: number, untilSlot: number, limit: number }, | ||
dbTx: PoolClient, | ||
}): Promise<ISqlMintRangeResult[]> { | ||
return (await sqlMintRange.run({ | ||
min_slot: request.range.minSlot, | ||
max_slot: request.range.maxSlot, | ||
min_slot: request.params.afterSlot, | ||
max_slot: request.params.untilSlot, | ||
limit: request.params.limit.toString(), | ||
}, request.dbTx)); | ||
} | ||
|
||
export async function mintRangeByPolicyIds(request: { | ||
range: { minSlot: number, maxSlot: number }, | ||
params: { afterSlot: number, untilSlot: number, limit: number }, | ||
policyIds: PolicyId[], | ||
dbTx: PoolClient, | ||
}): Promise<ISqlMintRangeResult[]> { | ||
}): Promise<ISqlMintRangeByPolicyIdsResult[]> { | ||
return (await sqlMintRangeByPolicyIds.run({ | ||
min_slot: request.range.minSlot, | ||
max_slot: request.range.maxSlot, | ||
policyIds: request.policyIds | ||
min_slot: request.params.afterSlot, | ||
max_slot: request.params.untilSlot, | ||
limit: request.params.limit.toString(), | ||
policy_ids: request.policyIds.map(id => Buffer.from(id, 'hex')), | ||
}, request.dbTx)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.