diff --git a/package-lock.json b/package-lock.json index 51ab7dcf2..bf01190d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10347,7 +10347,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, "engines": { "node": ">=8" } @@ -11221,8 +11220,7 @@ "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "node_modules/base-x": { "version": "4.0.0", @@ -11388,7 +11386,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -12258,8 +12255,7 @@ "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", - "dev": true + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, "node_modules/conf": { "version": "10.2.0", @@ -15702,8 +15698,7 @@ "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", - "dev": true + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, "node_modules/fsevents": { "version": "2.3.3", @@ -19761,7 +19756,6 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "dev": true, "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -20448,7 +20442,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", - "dev": true, "dependencies": { "once": "^1.3.0", "wrappy": "1" @@ -21106,8 +21099,7 @@ "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, "node_modules/isomorphic-ws": { "version": "4.0.1", @@ -23174,7 +23166,6 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, "dependencies": { "brace-expansion": "^1.1.7" }, @@ -27337,7 +27328,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -30544,7 +30534,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -31169,8 +31158,7 @@ "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", - "dev": true, - "peer": true + "dev": true }, "node_modules/through": { "version": "2.3.8", @@ -34560,7 +34548,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, "dependencies": { "isexe": "^2.0.0" }, @@ -35465,6 +35452,7 @@ } }, "tmp-carp-client": { + "name": "@dcspark/carp-client", "version": "2.2.3", "license": "MIT", "dependencies": { diff --git a/packages/engine/paima-funnel/src/cde/caranoProjectedNFT.ts b/packages/engine/paima-funnel/src/cde/cardanoProjectedNFT.ts similarity index 63% rename from packages/engine/paima-funnel/src/cde/caranoProjectedNFT.ts rename to packages/engine/paima-funnel/src/cde/cardanoProjectedNFT.ts index 812a84a93..bed7daaf4 100644 --- a/packages/engine/paima-funnel/src/cde/caranoProjectedNFT.ts +++ b/packages/engine/paima-funnel/src/cde/cardanoProjectedNFT.ts @@ -1,11 +1,11 @@ -import { ChainDataExtensionDatumType, DEFAULT_FUNNEL_TIMEOUT, timeout } from '@paima/utils'; import type { CdeCardanoProjectedNFTDatum, ChainDataExtensionCardanoProjectedNFT, ChainDataExtensionDatum, -} from '@paima/runtime'; +} from '@paima/sm'; +import { ChainDataExtensionDatumType, DEFAULT_FUNNEL_TIMEOUT, timeout } from '@paima/utils'; import { Routes, query } from '@dcspark/carp-client/client/src'; -import {ProjectedNftRangeResponse} from "@dcspark/carp-client/shared/models/ProjectedNftRange"; +import type { ProjectedNftRangeResponse } from "@dcspark/carp-client/shared/models/ProjectedNftRange"; export default async function getCdeData( url: string, @@ -21,24 +21,37 @@ export default async function getCdeData( DEFAULT_FUNNEL_TIMEOUT ); - return events.map(e => eventToCdeDatum(e, extension, getBlockNumber(e.slot))); + return events.map(e => eventToCdeDatum(e, extension, getBlockNumber(e.actionSlot))).filter(e => e != null).map(e => e!!); } function eventToCdeDatum( event: ProjectedNftRangeResponse[0], extension: ChainDataExtensionCardanoProjectedNFT, blockNumber: number -): CdeCardanoProjectedNFTDatum { +): CdeCardanoProjectedNFTDatum | null { + if (event.ownerAddress == null || event.actionTxId == null || event.status == null) { + return null; + } + return { cdeId: extension.cdeId, cdeDatumType: ChainDataExtensionDatumType.CardanoProjectedNFT, blockNumber, payload: { - address: event.address, + ownerAddress: event.ownerAddress!!, + + actionTxId: event.actionTxId, + actionOutputIndex: event.actionOutputIndex || undefined, + + previousTxHash: event.previousTxHash || undefined, + previousTxOutputIndex: event.previousTxOutputIndex || undefined, + asset: event.asset, amount: event.amount, status: event.status, - plutusDatum: event.plutusDatum, + plutusDatum: event.plutusDatum || "", + + forHowLong: event.forHowLong || undefined, }, scheduledPrefix: extension.scheduledPrefix, }; diff --git a/packages/engine/paima-sm/src/cde-cardano-projected-nft.ts b/packages/engine/paima-sm/src/cde-cardano-projected-nft.ts index cb8285403..3663d9eee 100644 --- a/packages/engine/paima-sm/src/cde-cardano-projected-nft.ts +++ b/packages/engine/paima-sm/src/cde-cardano-projected-nft.ts @@ -1,33 +1,64 @@ import { ENV } from '@paima/utils'; -import type { CdeCardanoProjectedNFTDatum } from '@paima/runtime'; -import { createScheduledData, cdeCardanoProjectedNftInsertData } from '@paima/db'; +import type { CdeCardanoProjectedNFTDatum } from './types'; +import {createScheduledData, cdeCardanoProjectedNftInsertData, cdeCardanoProjectedNftUpdateData} from '@paima/db'; import type { SQLUpdate } from '@paima/db'; export default async function processDatum(cdeDatum: CdeCardanoProjectedNFTDatum): Promise { const cdeId = cdeDatum.cdeId; const prefix = cdeDatum.scheduledPrefix; - const address = cdeDatum.payload.address; + const ownerAddress = cdeDatum.payload.ownerAddress; + const previousTxHash = cdeDatum.payload.previousTxHash; + const previousOutputIndex = cdeDatum.payload.previousTxOutputIndex; + const currentTxHash = cdeDatum.payload.actionTxId; + const currentOutputIndex = cdeDatum.payload.actionOutputIndex; const amount = cdeDatum.payload.amount; const asset = cdeDatum.payload.asset; const status = cdeDatum.payload.status; const datum = cdeDatum.payload.plutusDatum; + const forHowLong = cdeDatum.payload.forHowLong; const scheduledBlockHeight = Math.max(cdeDatum.blockNumber, ENV.SM_START_BLOCKHEIGHT + 1); - const scheduledInputData = `${prefix}|${address}|${asset}|${amount}|${status}|${datum}`; + const scheduledInputData = `${prefix}|${ownerAddress}|${previousTxHash}|${previousOutputIndex}|${currentTxHash}|${currentOutputIndex}|${status}`; + if (previousTxHash === undefined || previousOutputIndex === undefined) { + const updateList: SQLUpdate[] = [ + createScheduledData(scheduledInputData, scheduledBlockHeight), + [ + cdeCardanoProjectedNftInsertData, + { + cde_id: cdeId, + owner_address: ownerAddress, + current_tx_hash: currentTxHash, + current_tx_output_index: currentOutputIndex, + asset: asset, + amount: amount, + status: status, + plutus_datum: datum, + for_how_long: forHowLong + }, + ], + ]; + return updateList; + } const updateList: SQLUpdate[] = [ createScheduledData(scheduledInputData, scheduledBlockHeight), [ - cdeCardanoProjectedNftInsertData, + cdeCardanoProjectedNftUpdateData, { cde_id: cdeId, - address: cdeDatum.payload.address, - asset: cdeDatum.payload.asset, - amount: cdeDatum.payload.amount, - status: cdeDatum.payload.status, - datum: cdeDatum.payload.plutusDatum + owner_address: ownerAddress, + new_tx_hash: currentTxHash, + new_tx_output_index: currentOutputIndex, + previous_tx_hash: previousTxHash, + previous_tx_output_index: previousOutputIndex, + asset: asset, + amount: amount, + status: status, + plutus_datum: datum, + for_how_long: forHowLong }, ], ]; return updateList; + } diff --git a/packages/engine/paima-sm/src/types.ts b/packages/engine/paima-sm/src/types.ts index 428e30130..336d00de1 100644 --- a/packages/engine/paima-sm/src/types.ts +++ b/packages/engine/paima-sm/src/types.ts @@ -71,6 +71,23 @@ interface CdeDatumCardanoPoolPayload { pool: string | undefined; } +interface CdeDatumCardanoProjectedNFTPayload { + ownerAddress: string, + + actionTxId: string, + actionOutputIndex: number | undefined, + + previousTxHash: string | undefined, + previousTxOutputIndex: number | undefined, + + asset: string, + amount: number, + status: string, + plutusDatum: string, + + forHowLong: number | undefined, +} + type ChainDataExtensionPayload = | CdeDatumErc20TransferPayload | CdeDatumErc721MintPayload @@ -80,7 +97,8 @@ type ChainDataExtensionPayload = // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents | CdeDatumGenericPayload | CdeDatumErc6551RegistryPayload - | CdeDatumCardanoPoolPayload; + | CdeDatumCardanoPoolPayload + | CdeDatumCardanoProjectedNFTPayload; interface CdeDatumBase { cdeId: number; @@ -129,6 +147,12 @@ export interface CdeCardanoPoolDatum extends CdeDatumBase { scheduledPrefix: string; } +export interface CdeCardanoProjectedNFTDatum extends CdeDatumBase { + cdeDatumType: ChainDataExtensionDatumType.CardanoProjectedNFT; + payload: CdeDatumCardanoProjectedNFTPayload; + scheduledPrefix: string; +} + export type ChainDataExtensionDatum = | CdeErc20TransferDatum | CdeErc721MintDatum @@ -136,7 +160,8 @@ export type ChainDataExtensionDatum = | CdeErc20DepositDatum | CdeGenericDatum | CdeErc6551RegistryDatum - | CdeCardanoPoolDatum; + | CdeCardanoPoolDatum + | CdeCardanoProjectedNFTDatum; export enum CdeEntryTypeName { Generic = 'generic', @@ -145,6 +170,7 @@ export enum CdeEntryTypeName { ERC721 = 'erc721', ERC6551Registry = 'erc6551-registry', CardanoDelegation = 'cardano-stake-delegation', + CardanoProjectedNFT = 'cardano-projected-nft', } const EvmAddress = Type.Transform(Type.RegExp('0x[0-9a-fA-F]{40}')) @@ -262,6 +288,21 @@ export type ChainDataExtensionCardanoDelegation = ChainDataExtensionBase & cdeType: ChainDataExtensionType.CardanoPool; }; +export const ChainDataExtensionCardanoProjectedNFTConfig = Type.Intersect([ + Type.Object({ + type: Type.Literal(CdeEntryTypeName.CardanoProjectedNFT), + contract: Type.String(), + scheduledPrefix: Type.String(), + startSlot: Type.Number(), + stopSlot: Type.Optional(Type.Number()), + name: Type.String(), + }), +]); +export type ChainDataExtensionCardanoProjectedNFT = ChainDataExtensionBase & + Static & { + cdeType: ChainDataExtensionType.CardanoProjectedNFT; +}; + export const CdeConfig = Type.Object({ extensions: Type.Array( Type.Union([ @@ -271,6 +312,7 @@ export const CdeConfig = Type.Object({ ChainDataExtensionGenericConfig, ChainDataExtensionErc6551RegistryConfig, ChainDataExtensionCardanoDelegationConfig, + ChainDataExtensionCardanoProjectedNFTConfig, ]) ), }); @@ -295,7 +337,8 @@ export type ChainDataExtension = | ChainDataExtensionErc20Deposit | ChainDataExtensionGeneric | ChainDataExtensionErc6551Registry - | ChainDataExtensionCardanoDelegation; + | ChainDataExtensionCardanoDelegation + | ChainDataExtensionCardanoProjectedNFT; export type GameStateTransitionFunctionRouter = ( blockHeight: number diff --git a/packages/node-sdk/paima-db/migrations/up.sql b/packages/node-sdk/paima-db/migrations/up.sql index a23f6583e..7ca28f822 100644 --- a/packages/node-sdk/paima-db/migrations/up.sql +++ b/packages/node-sdk/paima-db/migrations/up.sql @@ -97,10 +97,15 @@ CREATE TABLE cde_cardano_pool_delegation ( CREATE TABLE cde_cardano_projected_nft ( cde_id INTEGER NOT NULL, id SERIAL, - address TEXT NOT NULL, + owner_address TEXT NOT NULL, + previous_tx_hash TEXT, + previous_tx_output_index INTEGER, + current_tx_hash TEXT NOT NULL, + current_tx_output_index INTEGER, asset TEXT NOT NULL, - amount TEXT NOT NULL, + amount BIGINT NOT NULL, status TEXT NOT NULL, - datum TEXT NOT NULL, + plutus_datum TEXT NOT NULL, + for_how_long BIGINT, PRIMARY KEY (cde_id, id) ); \ No newline at end of file diff --git a/packages/node-sdk/paima-db/src/index.ts b/packages/node-sdk/paima-db/src/index.ts index cabb199be..590c9f1bc 100644 --- a/packages/node-sdk/paima-db/src/index.ts +++ b/packages/node-sdk/paima-db/src/index.ts @@ -31,6 +31,8 @@ export type * from './sql/emulated.queries.js'; export type * from './types.js'; export * from './sql/cde-cardano-pool-delegation.queries.js'; export type * from './sql/cde-cardano-pool-delegation.queries.js'; +export * from './sql/cde-cardano-projected-nft.queries.js'; +export type * from './sql/cde-cardano-projected-nft.queries.js'; export * from './sql/cde-tracking-cardano.queries.js'; export type * from './sql/cde-tracking-cardano.queries.js'; diff --git a/packages/node-sdk/paima-db/src/paima-tables.ts b/packages/node-sdk/paima-db/src/paima-tables.ts index 02178a43b..e3a41659e 100644 --- a/packages/node-sdk/paima-db/src/paima-tables.ts +++ b/packages/node-sdk/paima-db/src/paima-tables.ts @@ -277,6 +277,45 @@ const TABLE_DATA_CDE_CARDANO_POOL: TableData = { creationQuery: QUERY_CREATE_TABLE_CDE_CARDANO_POOL, }; +const QUERY_CREATE_TABLE_CDE_CARDANO_PROJECTED_NFT = ` +CREATE TABLE cde_cardano_projected_nft ( + cde_id INTEGER NOT NULL, + id SERIAL, + owner_address TEXT NOT NULL, + previous_tx_hash TEXT, + previous_tx_output_index INTEGER, + current_tx_hash TEXT NOT NULL, + current_tx_output_index INTEGER, + asset TEXT NOT NULL, + amount BIGINT NOT NULL, + status TEXT NOT NULL, + plutus_datum TEXT NOT NULL, + for_how_long BIGINT, + PRIMARY KEY (cde_id, id) +) +`; + +const TABLE_DATA_CDE_CARDANO_PROJECTED_NFT: TableData = { + tableName: 'cde_cardano_projected_nft', + primaryKeyColumns: ['cde_id', 'id'], + columnData: packTuples([ + ['cde_id', 'integer', 'NO', ''], + ['id', 'integer', 'NO', ''], + ['owner_address', 'text', 'NO', ''], + ['previous_tx_hash', 'text', 'YES', ''], + ['previous_tx_output_index', 'integer', 'YES', ''], + ['current_tx_hash', 'text', 'NO', ''], + ['current_tx_output_index', 'integer', 'YES', ''], + ['asset', 'text', 'NO', ''], + ['amount', 'bigint', 'NO', ''], + ['status', 'text', 'NO', ''], + ['plutus_datum', 'text', 'NO', ''], + ['for_how_long', 'bigint', 'NO', ''], + ]), + serialColumns: ['id'], + creationQuery: QUERY_CREATE_TABLE_CDE_CARDANO_PROJECTED_NFT, +}; + const QUERY_CREATE_TABLE_EMULATED = ` CREATE TABLE emulated_block_heights ( deployment_chain_block_height INTEGER PRIMARY KEY, @@ -311,5 +350,6 @@ export const TABLES: TableData[] = [ TABLE_DATA_CDE_GENERIC_DATA, TABLE_DATA_CDE_ERC6551_REGISTRY, TABLE_DATA_CDE_CARDANO_POOL, + TABLE_DATA_CDE_CARDANO_PROJECTED_NFT, TABLE_DATA_EMULATED, ]; diff --git a/packages/node-sdk/paima-db/src/sql/cde-cardano-projected-nft.queries.ts b/packages/node-sdk/paima-db/src/sql/cde-cardano-projected-nft.queries.ts new file mode 100644 index 000000000..0058bc79e --- /dev/null +++ b/packages/node-sdk/paima-db/src/sql/cde-cardano-projected-nft.queries.ts @@ -0,0 +1,151 @@ +/** Types generated for queries found in "src/sql/cde-cardano-projected-nft.sql" */ +import { PreparedQuery } from '@pgtyped/runtime'; + +export type NumberOrString = number | string; + +/** 'CdeCardanoGetProjectedNft' parameters type */ +export interface ICdeCardanoGetProjectedNftParams { + owner_address: string; +} + +/** 'CdeCardanoGetProjectedNft' return type */ +export interface ICdeCardanoGetProjectedNftResult { + amount: string; + asset: string; + cde_id: number; + current_tx_hash: string; + current_tx_output_index: number | null; + for_how_long: string | null; + id: number; + owner_address: string; + plutus_datum: string; + previous_tx_hash: string | null; + previous_tx_output_index: number | null; + status: string; +} + +/** 'CdeCardanoGetProjectedNft' query type */ +export interface ICdeCardanoGetProjectedNftQuery { + params: ICdeCardanoGetProjectedNftParams; + result: ICdeCardanoGetProjectedNftResult; +} + +const cdeCardanoGetProjectedNftIR: any = {"usedParamSet":{"owner_address":true},"params":[{"name":"owner_address","required":true,"transform":{"type":"scalar"},"locs":[{"a":62,"b":76}]}],"statement":"SELECT * FROM cde_cardano_projected_nft\nWHERE owner_address = :owner_address!"}; + +/** + * Query generated from SQL: + * ``` + * SELECT * FROM cde_cardano_projected_nft + * WHERE owner_address = :owner_address! + * ``` + */ +export const cdeCardanoGetProjectedNft = new PreparedQuery(cdeCardanoGetProjectedNftIR); + + +/** 'CdeCardanoProjectedNftInsertData' parameters type */ +export interface ICdeCardanoProjectedNftInsertDataParams { + amount: NumberOrString; + asset: string; + cde_id: number; + current_tx_hash: string; + current_tx_output_index: number; + for_how_long: NumberOrString; + owner_address: string; + plutus_datum: string; + status: string; +} + +/** 'CdeCardanoProjectedNftInsertData' return type */ +export type ICdeCardanoProjectedNftInsertDataResult = void; + +/** 'CdeCardanoProjectedNftInsertData' query type */ +export interface ICdeCardanoProjectedNftInsertDataQuery { + params: ICdeCardanoProjectedNftInsertDataParams; + result: ICdeCardanoProjectedNftInsertDataResult; +} + +const cdeCardanoProjectedNftInsertDataIR: any = {"usedParamSet":{"cde_id":true,"owner_address":true,"current_tx_hash":true,"current_tx_output_index":true,"asset":true,"amount":true,"status":true,"plutus_datum":true,"for_how_long":true},"params":[{"name":"cde_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":214,"b":221}]},{"name":"owner_address","required":true,"transform":{"type":"scalar"},"locs":[{"a":237,"b":251}]},{"name":"current_tx_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":267,"b":283}]},{"name":"current_tx_output_index","required":true,"transform":{"type":"scalar"},"locs":[{"a":299,"b":323}]},{"name":"asset","required":true,"transform":{"type":"scalar"},"locs":[{"a":339,"b":345}]},{"name":"amount","required":true,"transform":{"type":"scalar"},"locs":[{"a":361,"b":368}]},{"name":"status","required":true,"transform":{"type":"scalar"},"locs":[{"a":384,"b":391}]},{"name":"plutus_datum","required":true,"transform":{"type":"scalar"},"locs":[{"a":407,"b":420}]},{"name":"for_how_long","required":true,"transform":{"type":"scalar"},"locs":[{"a":436,"b":449}]}],"statement":"INSERT INTO cde_cardano_projected_nft(\n cde_id,\n owner_address,\n current_tx_hash,\n current_tx_output_index,\n asset,\n amount,\n status,\n plutus_datum,\n for_how_long\n) VALUES (\n :cde_id!,\n :owner_address!,\n :current_tx_hash!,\n :current_tx_output_index!,\n :asset!,\n :amount!,\n :status!,\n :plutus_datum!,\n :for_how_long!\n )"}; + +/** + * Query generated from SQL: + * ``` + * INSERT INTO cde_cardano_projected_nft( + * cde_id, + * owner_address, + * current_tx_hash, + * current_tx_output_index, + * asset, + * amount, + * status, + * plutus_datum, + * for_how_long + * ) VALUES ( + * :cde_id!, + * :owner_address!, + * :current_tx_hash!, + * :current_tx_output_index!, + * :asset!, + * :amount!, + * :status!, + * :plutus_datum!, + * :for_how_long! + * ) + * ``` + */ +export const cdeCardanoProjectedNftInsertData = new PreparedQuery(cdeCardanoProjectedNftInsertDataIR); + + +/** 'CdeCardanoProjectedNftUpdateData' parameters type */ +export interface ICdeCardanoProjectedNftUpdateDataParams { + amount: NumberOrString; + asset: string; + cde_id: number; + for_how_long: NumberOrString; + new_tx_hash: string; + new_tx_output_index: number; + owner_address: string; + plutus_datum: string; + previous_tx_hash: string; + previous_tx_output_index: number; + status: string; +} + +/** 'CdeCardanoProjectedNftUpdateData' return type */ +export interface ICdeCardanoProjectedNftUpdateDataResult { + previous_tx_hash: string | null; + previous_tx_output_index: number | null; +} + +/** 'CdeCardanoProjectedNftUpdateData' query type */ +export interface ICdeCardanoProjectedNftUpdateDataQuery { + params: ICdeCardanoProjectedNftUpdateDataParams; + result: ICdeCardanoProjectedNftUpdateDataResult; +} + +const cdeCardanoProjectedNftUpdateDataIR: any = {"usedParamSet":{"previous_tx_hash":true,"previous_tx_output_index":true,"new_tx_hash":true,"new_tx_output_index":true,"status":true,"plutus_datum":true,"for_how_long":true,"cde_id":true,"owner_address":true,"asset":true,"amount":true},"params":[{"name":"previous_tx_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":60,"b":77},{"a":415,"b":432}]},{"name":"previous_tx_output_index","required":true,"transform":{"type":"scalar"},"locs":[{"a":111,"b":136},{"a":468,"b":493}]},{"name":"new_tx_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":161,"b":173}]},{"name":"new_tx_output_index","required":true,"transform":{"type":"scalar"},"locs":[{"a":206,"b":226}]},{"name":"status","required":true,"transform":{"type":"scalar"},"locs":[{"a":242,"b":249}]},{"name":"plutus_datum","required":true,"transform":{"type":"scalar"},"locs":[{"a":271,"b":284}]},{"name":"for_how_long","required":true,"transform":{"type":"scalar"},"locs":[{"a":306,"b":319}]},{"name":"cde_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":340,"b":347}]},{"name":"owner_address","required":true,"transform":{"type":"scalar"},"locs":[{"a":373,"b":387}]},{"name":"asset","required":true,"transform":{"type":"scalar"},"locs":[{"a":511,"b":517}]},{"name":"amount","required":true,"transform":{"type":"scalar"},"locs":[{"a":536,"b":543}]}],"statement":"UPDATE cde_cardano_projected_nft\nSET\n previous_tx_hash = :previous_tx_hash!,\n previous_tx_output_index = :previous_tx_output_index!,\n current_tx_hash = :new_tx_hash!,\n current_tx_output_index = :new_tx_output_index!,\n status = :status!,\n plutus_datum = :plutus_datum!,\n for_how_long = :for_how_long!\nWHERE\n cde_id = :cde_id!\n AND owner_address = :owner_address!\n AND current_tx_hash = :previous_tx_hash!\n AND current_tx_output_index = :previous_tx_output_index!\n AND asset = :asset!\n AND amount = :amount!\nRETURNING previous_tx_hash, previous_tx_output_index"}; + +/** + * Query generated from SQL: + * ``` + * UPDATE cde_cardano_projected_nft + * SET + * previous_tx_hash = :previous_tx_hash!, + * previous_tx_output_index = :previous_tx_output_index!, + * current_tx_hash = :new_tx_hash!, + * current_tx_output_index = :new_tx_output_index!, + * status = :status!, + * plutus_datum = :plutus_datum!, + * for_how_long = :for_how_long! + * WHERE + * cde_id = :cde_id! + * AND owner_address = :owner_address! + * AND current_tx_hash = :previous_tx_hash! + * AND current_tx_output_index = :previous_tx_output_index! + * AND asset = :asset! + * AND amount = :amount! + * RETURNING previous_tx_hash, previous_tx_output_index + * ``` + */ +export const cdeCardanoProjectedNftUpdateData = new PreparedQuery(cdeCardanoProjectedNftUpdateDataIR); + + diff --git a/packages/node-sdk/paima-db/src/sql/cde-cardano-projected-nft.sql b/packages/node-sdk/paima-db/src/sql/cde-cardano-projected-nft.sql index 400765902..44e61fbfe 100644 --- a/packages/node-sdk/paima-db/src/sql/cde-cardano-projected-nft.sql +++ b/packages/node-sdk/paima-db/src/sql/cde-cardano-projected-nft.sql @@ -1,28 +1,45 @@ /* @name cdeCardanoGetProjectedNft */ SELECT * FROM cde_cardano_projected_nft -WHERE address = :address!; +WHERE owner_address = :owner_address!; /* @name cdeCardanoProjectedNftInsertData */ -INSERT INTO cde_cardano_pool_delegation( +INSERT INTO cde_cardano_projected_nft( cde_id, - address, + owner_address, + current_tx_hash, + current_tx_output_index, asset, amount, status, - datum, + plutus_datum, + for_how_long ) VALUES ( :cde_id!, - :address!, - :asset! - :amount! - :status! - :datum! - ) ON CONFLICT (cde_id, address) DO -UPDATE SET pool = :pool!; + :owner_address!, + :current_tx_hash!, + :current_tx_output_index!, + :asset!, + :amount!, + :status!, + :plutus_datum!, + :for_how_long! + ); -cde_id: cdeId, - address: cdeDatum.payload.address, - asset: cdeDatum.payload.asset, - amount: cdeDatum.payload.amount, - status: cdeDatum.payload.status, - datum: cdeDatum.payload.plutusDatum \ No newline at end of file +/* @name cdeCardanoProjectedNftUpdateData */ +UPDATE cde_cardano_projected_nft +SET + previous_tx_hash = :previous_tx_hash!, + previous_tx_output_index = :previous_tx_output_index!, + current_tx_hash = :new_tx_hash!, + current_tx_output_index = :new_tx_output_index!, + status = :status!, + plutus_datum = :plutus_datum!, + for_how_long = :for_how_long! +WHERE + cde_id = :cde_id! + AND owner_address = :owner_address! + AND current_tx_hash = :previous_tx_hash! + AND current_tx_output_index = :previous_tx_output_index! + AND asset = :asset! + AND amount = :amount! +RETURNING previous_tx_hash, previous_tx_output_index; \ No newline at end of file diff --git a/packages/node-sdk/paima-db/src/sql/cde-tracking-cardano.queries.ts b/packages/node-sdk/paima-db/src/sql/cde-tracking-cardano.queries.ts index 1a8ad4abd..c8df1a0b7 100644 --- a/packages/node-sdk/paima-db/src/sql/cde-tracking-cardano.queries.ts +++ b/packages/node-sdk/paima-db/src/sql/cde-tracking-cardano.queries.ts @@ -15,7 +15,7 @@ export interface IMarkCardanoCdeSlotProcessedQuery { result: IMarkCardanoCdeSlotProcessedResult; } -const markCardanoCdeSlotProcessedIR: any = {"usedParamSet":{"slot":true},"params":[{"name":"slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":53,"b":58},{"a":100,"b":105}]}],"statement":"INSERT INTO cde_tracking_cardano(id,slot)\nVALUES (0, :slot!)\nON CONFLICT (id) \nDO UPDATE SET slot = :slot!"}; +const markCardanoCdeSlotProcessedIR: any = {"usedParamSet":{"slot":true},"params":[{"name":"slot","required":true,"transform":{"type":"scalar"},"locs":[{"a":53,"b":58},{"a":99,"b":104}]}],"statement":"INSERT INTO cde_tracking_cardano(id,slot)\nVALUES (0, :slot!)\nON CONFLICT (id)\nDO UPDATE SET slot = :slot!"}; /** * Query generated from SQL: @@ -34,7 +34,7 @@ export type IGetCardanoLatestProcessedCdeSlotParams = void; /** 'GetCardanoLatestProcessedCdeSlot' return type */ export interface IGetCardanoLatestProcessedCdeSlotResult { - slot: number | null; + slot: number; } /** 'GetCardanoLatestProcessedCdeSlot' query type */ diff --git a/packages/node-sdk/paima-utils-backend/src/cde-access-internals.ts b/packages/node-sdk/paima-utils-backend/src/cde-access-internals.ts index 836a66c56..330b5ffd3 100644 --- a/packages/node-sdk/paima-utils-backend/src/cde-access-internals.ts +++ b/packages/node-sdk/paima-utils-backend/src/cde-access-internals.ts @@ -13,7 +13,7 @@ import { cdeErc6551GetOwnedAccounts, cdeErc6551GetOwner, cdeCardanoPoolGetAddressDelegation, - cdeCardanoGetProjectedNft, + cdeCardanoGetProjectedNft, ICdeCardanoGetProjectedNftResult, } from '@paima/db'; import type { OwnedNftsResponse, GenericCdeDataUnit, TokenIdPair } from './types.js'; @@ -194,12 +194,9 @@ export async function internalGetCardanoAddressDelegation( export async function internalGetCardanoProjectedNft( readonlyDBConn: Pool, - address: string -): Promise { - const results = await cdeCardanoGetProjectedNft.run({ address }, readonlyDBConn); - if (results.length === 0) { - return null; - } + owner_address: string +): Promise { + const results = await cdeCardanoGetProjectedNft.run({ owner_address }, readonlyDBConn); - return results[0].pool; + return results; } diff --git a/packages/node-sdk/paima-utils-backend/src/cde-access.ts b/packages/node-sdk/paima-utils-backend/src/cde-access.ts index eca573931..fd5b1610e 100644 --- a/packages/node-sdk/paima-utils-backend/src/cde-access.ts +++ b/packages/node-sdk/paima-utils-backend/src/cde-access.ts @@ -16,6 +16,7 @@ import { internalGetCardanoProjectedNft, } from './cde-access-internals.js'; import type { OwnedNftsResponse, GenericCdeDataUnit, TokenIdPair } from './types.js'; +import {ICdeCardanoGetProjectedNftResult} from "@paima/db/src"; /** * Fetch the owner of the NFT from the database @@ -172,9 +173,9 @@ export async function getCardanoAddressDelegation( /** * Fetch the pool this address is delegating to, if any. */ -export async function getCardanoAddressProjectedNft( +export async function getCardanoAddressProjectedNfts( readonlyDBConn: Pool, address: string -): Promise { +): Promise { return await internalGetCardanoProjectedNft(readonlyDBConn, address); } diff --git a/tmp-carp-client/shared/models/ProjectedNftRange.d.ts b/tmp-carp-client/shared/models/ProjectedNftRange.d.ts index 12f6d1140..dbdc24339 100644 --- a/tmp-carp-client/shared/models/ProjectedNftRange.d.ts +++ b/tmp-carp-client/shared/models/ProjectedNftRange.d.ts @@ -3,11 +3,19 @@ export declare type ProjectedNftRangeRequest = { }; export declare type ProjectedNftRangeResponse = { - txId: string | null, - slot: number, - address: string | null, + actionSlot: number, + + ownerAddress: string | null, + + actionTxId: string | null, + actionOutputIndex: number | null, + + previousTxHash: string | null, + previousTxOutputIndex: number | null, + asset: string, amount: number, status: string | null, plutusDatum: string | null, + forHowLong: number | null, }[]; \ No newline at end of file