Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added get erc1155 token by id #349

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!
;
16 changes: 14 additions & 2 deletions packages/node-sdk/paima-utils-backend/src/cde-access-internals.ts
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 All @@ -30,6 +31,7 @@ import type {
import type {
ICdeCardanoAssetUtxosByAddressParams,
ICdeErc1155GetAllTokensResult,
ICdeErc1155GetByTokenIdAndWalletResult,
ICdeErc1155GetByTokenIdResult,
} from '@paima/db';

Expand Down Expand Up @@ -188,11 +190,21 @@ export async function internalGetErc1155AllTokens(
export async function internalGetErc1155ByTokenId(
readonlyDBConn: Pool,
cde_id: number,
wallet_address: string,
token_id: bigint
): Promise<ICdeErc1155GetByTokenIdResult | null> {
return (
await cdeErc1155GetByTokenId.run(
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<ICdeErc1155GetByTokenIdAndWalletResult | null> {
return (
await cdeErc1155GetByTokenIdAndWallet.run(
{ cde_id, wallet_address, token_id: String(token_id) },
readonlyDBConn
)
Expand Down
21 changes: 18 additions & 3 deletions packages/node-sdk/paima-utils-backend/src/cde-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import {
internalGetErc1155TotalBalanceAllTokens,
internalGetErc1155AllTokens,
internalGetErc1155ByTokenId,
internalGetErc1155ByTokenIdAndWallet,
} from './cde-access-internals.js';
import type {
ICdeCardanoGetProjectedNftResult,
ICdeErc1155GetAllTokensResult,
ICdeErc1155GetByTokenIdAndWalletResult,
ICdeErc1155GetByTokenIdResult,
} from '@paima/db/src';
export type { ICdeErc1155GetAllTokensResult };
Expand Down Expand Up @@ -175,17 +177,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,
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 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<ICdeErc1155GetByTokenIdAndWalletResult | null> {
const cdeId = await getCdeIdByName(readonlyDBConn, cdeName);
if (cdeId === null) return null;
return await internalGetErc1155ByTokenIdAndWallet(readonlyDBConn, cdeId, wallet, tokenId);
}

/**
Expand Down