Skip to content

Commit

Permalink
Added get erc1155 token by id
Browse files Browse the repository at this point in the history
  • Loading branch information
acedward committed Apr 18, 2024
1 parent f28e4d8 commit 8d7c1a0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 6 deletions.
41 changes: 38 additions & 3 deletions packages/node-sdk/paima-db/src/sql/cde-erc1155.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ export const cdeErc1155GetAllTokens = new PreparedQuery<ICdeErc1155GetAllTokensP
export interface ICdeErc1155GetByTokenIdParams {
cde_id: number;
token_id: string;
wallet_address: string;
}

/** 'CdeErc1155GetByTokenId' return type */
Expand All @@ -199,15 +198,51 @@ export interface ICdeErc1155GetByTokenIdQuery {
result: ICdeErc1155GetByTokenIdResult;
}

const cdeErc1155GetByTokenIdIR: 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!"};
const cdeErc1155GetByTokenIdIR: any = {"usedParamSet":{"cde_id":true,"token_id":true},"params":[{"name":"cde_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":46,"b":53}]},{"name":"token_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":70,"b":79}]}],"statement":"SELECT * from cde_erc1155_data\nWHERE cde_id = :cde_id!\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 cdeErc1155GetByTokenId = new PreparedQuery<ICdeErc1155GetByTokenIdParams,ICdeErc1155GetByTokenIdResult>(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<ICdeErc1155GetByTokenIdAndWalletParams,ICdeErc1155GetByTokenIdAndWalletResult>(cdeErc1155GetByTokenIdAndWalletIR);


6 changes: 6 additions & 0 deletions packages/node-sdk/paima-db/src/sql/cde-erc1155.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
;
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
cdeErc1155GetTotalBalanceAllTokens,
cdeErc1155GetAllTokens,
cdeErc1155GetByTokenId,
cdeErc1155GetByTokenIdAndWallet,
} from '@paima/db';
import type {
OwnedNftsResponse,
Expand Down Expand Up @@ -186,13 +187,23 @@ export async function internalGetErc1155AllTokens(
}

export async function internalGetErc1155ByTokenId(
readonlyDBConn: Pool,
cde_id: number,
token_id: bigint
): Promise<ICdeErc1155GetByTokenIdResult | null> {
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<ICdeErc1155GetByTokenIdResult | null> {
return (
await cdeErc1155GetByTokenId.run(
await cdeErc1155GetByTokenIdAndWallet.run(
{ cde_id, wallet_address, token_id: String(token_id) },
readonlyDBConn
)
Expand Down
18 changes: 16 additions & 2 deletions packages/node-sdk/paima-utils-backend/src/cde-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
internalGetErc1155TotalBalanceAllTokens,
internalGetErc1155AllTokens,
internalGetErc1155ByTokenId,
internalGetErc1155ByTokenIdAndWallet,
} from './cde-access-internals.js';
import type {
ICdeCardanoGetProjectedNftResult,
Expand Down Expand Up @@ -175,17 +176,30 @@ 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<ICdeErc1155GetByTokenIdResult | null> {
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,
tokenId: bigint
): Promise<ICdeErc1155GetByTokenIdResult | null> {
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);
}

/**
Expand Down

0 comments on commit 8d7c1a0

Please sign in to comment.