diff --git a/packages/node-sdk/paima-db/src/sql/cde-erc1155.queries.ts b/packages/node-sdk/paima-db/src/sql/cde-erc1155.queries.ts index e7eae9a8..36bd4b64 100644 --- a/packages/node-sdk/paima-db/src/sql/cde-erc1155.queries.ts +++ b/packages/node-sdk/paima-db/src/sql/cde-erc1155.queries.ts @@ -182,7 +182,6 @@ export const cdeErc1155GetAllTokens = new PreparedQuery(cdeErc1155GetByTokenIdIR); + + +/** 'CdeErc1155GetByTokenIdAndWallet' parameters type */ +export interface ICdeErc1155GetByTokenIdAndWalletParams { + cde_id: number; + token_id: string; + wallet_address: string; +} + +/** 'CdeErc1155GetByTokenIdAndWallet' return type */ +export interface ICdeErc1155GetByTokenIdAndWalletResult { + balance: string; + cde_id: number; + token_id: string; + wallet_address: string; +} + +/** 'CdeErc1155GetByTokenIdAndWallet' query type */ +export interface ICdeErc1155GetByTokenIdAndWalletQuery { + params: ICdeErc1155GetByTokenIdAndWalletParams; + result: ICdeErc1155GetByTokenIdAndWalletResult; +} + +const cdeErc1155GetByTokenIdAndWalletIR: any = {"usedParamSet":{"cde_id":true,"wallet_address":true,"token_id":true},"params":[{"name":"cde_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":46,"b":53}]},{"name":"wallet_address","required":true,"transform":{"type":"scalar"},"locs":[{"a":76,"b":91}]},{"name":"token_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":108,"b":117}]}],"statement":"SELECT * from cde_erc1155_data\nWHERE cde_id = :cde_id!\nAND wallet_address = :wallet_address!\nAND token_id = :token_id!"}; + +/** + * Query generated from SQL: + * ``` + * SELECT * from cde_erc1155_data + * WHERE cde_id = :cde_id! + * AND wallet_address = :wallet_address! + * AND token_id = :token_id! + * ``` + */ +export const cdeErc1155GetByTokenIdAndWallet = new PreparedQuery(cdeErc1155GetByTokenIdAndWalletIR); + + diff --git a/packages/node-sdk/paima-db/src/sql/cde-erc1155.sql b/packages/node-sdk/paima-db/src/sql/cde-erc1155.sql index 9653d53f..4b313d6f 100644 --- a/packages/node-sdk/paima-db/src/sql/cde-erc1155.sql +++ b/packages/node-sdk/paima-db/src/sql/cde-erc1155.sql @@ -53,6 +53,12 @@ AND CAST(balance AS NUMERIC) > 0 /* @name cdeErc1155GetByTokenId */ SELECT * from cde_erc1155_data WHERE cde_id = :cde_id! +AND token_id = :token_id! +; + +/* @name cdeErc1155GetByTokenIdAndWallet */ +SELECT * from cde_erc1155_data +WHERE cde_id = :cde_id! AND wallet_address = :wallet_address! AND token_id = :token_id! ; 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 7b31ff7c..625ae5a3 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 @@ -20,6 +20,7 @@ import { cdeErc1155GetTotalBalanceAllTokens, cdeErc1155GetAllTokens, cdeErc1155GetByTokenId, + cdeErc1155GetByTokenIdAndWallet, } from '@paima/db'; import type { OwnedNftsResponse, @@ -186,13 +187,23 @@ export async function internalGetErc1155AllTokens( } export async function internalGetErc1155ByTokenId( + readonlyDBConn: Pool, + cde_id: number, + token_id: bigint +): Promise { + return ( + await cdeErc1155GetByTokenId.run({ cde_id, token_id: String(token_id) }, readonlyDBConn) + )[0]; +} + +export async function internalGetErc1155ByTokenIdAndWallet( readonlyDBConn: Pool, cde_id: number, wallet_address: string, token_id: bigint ): Promise { return ( - await cdeErc1155GetByTokenId.run( + await cdeErc1155GetByTokenIdAndWallet.run( { cde_id, wallet_address, token_id: String(token_id) }, readonlyDBConn ) 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 89969f50..b67d675a 100644 --- a/packages/node-sdk/paima-utils-backend/src/cde-access.ts +++ b/packages/node-sdk/paima-utils-backend/src/cde-access.ts @@ -18,6 +18,7 @@ import { internalGetErc1155TotalBalanceAllTokens, internalGetErc1155AllTokens, internalGetErc1155ByTokenId, + internalGetErc1155ByTokenIdAndWallet, } from './cde-access-internals.js'; import type { ICdeCardanoGetProjectedNftResult, @@ -175,9 +176,22 @@ export async function getErc1155AllTokens( } /** - * Get info on a specific token owned by a wallet within a single ERC-1155 contract. + * Get info on a specific token within a single ERC-1155 contract. */ export async function getErc1155ByTokenId( + readonlyDBConn: Pool, + cdeName: string, + tokenId: bigint +): Promise { + const cdeId = await getCdeIdByName(readonlyDBConn, cdeName); + if (cdeId === null) return null; + return await internalGetErc1155ByTokenId(readonlyDBConn, cdeId, tokenId); +} + +/** + * Get info on a specific token owned by a wallet within a single ERC-1155 contract. + */ +export async function getErc1155ByTokenIdAndWallet( readonlyDBConn: Pool, cdeName: string, wallet: string, @@ -185,7 +199,7 @@ export async function getErc1155ByTokenId( ): Promise { const cdeId = await getCdeIdByName(readonlyDBConn, cdeName); if (cdeId === null) return null; - return await internalGetErc1155ByTokenId(readonlyDBConn, cdeId, wallet, tokenId); + return await internalGetErc1155ByTokenIdAndWallet(readonlyDBConn, cdeId, wallet, tokenId); } /**