Skip to content
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
5 changes: 5 additions & 0 deletions src/api/routes/ft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export const FtRoutes: FastifyPluginCallback<Record<never, never>, Server, TypeB
decimals: metadataBundle?.token?.decimals ?? undefined,
total_supply: metadataBundle?.token?.total_supply?.toString() ?? undefined,
token_uri: metadataBundle?.token?.uri ?? undefined,
description: metadataBundle?.metadataLocale?.metadata?.description ?? undefined,
tx_id: metadataBundle?.smartContract.tx_id,
sender_address: metadataBundle?.smartContract.principal.split('.')[0],
image_uri: metadataBundle?.metadataLocale?.metadata?.cached_image ?? undefined,
image_canonical_uri: metadataBundle?.metadataLocale?.metadata?.image ?? undefined,
metadata: parseMetadataLocaleBundle(metadataBundle?.metadataLocale),
});
} catch (error) {
Expand Down
45 changes: 26 additions & 19 deletions src/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,28 @@ export const MetadataLocalization = Type.Object({
locales: Type.Array(Type.String(), { examples: [['en', 'jp']] }),
});

const TokenDescription = Type.String({
examples: [
'Heavy hitters, all-stars and legends of the game join forces to create a collection of unique varsity jackets',
],
});

const TokenImage = Type.String({
format: 'uri',
examples: ['ipfs://ipfs/QmZMqhh2ztwuZ3Y8PyEp2z5auyH3TCm3nnr5ZfjjgDjd5q/12199.png'],
});

const TokenCachedImage = Type.String({
format: 'uri',
examples: ['https://ipfs.io/ipfs/QmZMqhh2ztwuZ3Y8PyEp2z5auyH3TCm3nnr5ZfjjgDjd5q/12199.png'],
});

export const Metadata = Type.Object({
sip: Type.Integer({ examples: [16] }),
name: Type.Optional(Type.String({ examples: ["Satoshi's Team #12200"] })),
description: Type.Optional(
Type.String({
examples: [
'Heavy hitters, all-stars and legends of the game join forces to create a collection of unique varsity jackets',
],
})
),
image: Type.Optional(
Type.String({
format: 'uri',
examples: ['ipfs://ipfs/QmZMqhh2ztwuZ3Y8PyEp2z5auyH3TCm3nnr5ZfjjgDjd5q/12199.png'],
})
),
cached_image: Type.Optional(
Type.String({
format: 'uri',
examples: ['https://ipfs.io/ipfs/QmZMqhh2ztwuZ3Y8PyEp2z5auyH3TCm3nnr5ZfjjgDjd5q/12199.png'],
})
),
description: Type.Optional(TokenDescription),
image: Type.Optional(TokenImage),
cached_image: Type.Optional(TokenCachedImage),
attributes: Type.Optional(Type.Array(MetadataAttribute)),
properties: Type.Optional(MetadataProperties),
localization: Type.Optional(MetadataLocalization),
Expand Down Expand Up @@ -167,6 +167,13 @@ export const FtMetadataResponse = Type.Object({
decimals: Type.Optional(Type.Integer({ examples: [8] })),
total_supply: Type.Optional(Type.String({ examples: ['9999980000000'] })),
token_uri: Type.Optional(TokenUri),
description: Type.Optional(TokenDescription),
image_uri: Type.Optional(TokenCachedImage),
image_canonical_uri: Type.Optional(TokenImage),
tx_id: Type.String({
examples: ['0xef2ac1126e16f46843228b1dk4830e19eb7599129e4jf392cab9e65ae83a45c0'],
}),
sender_address: Type.String({ examples: ['ST399W7Z9WS0GMSNQGJGME5JAENKN56D65VGMGKGA'] }),
metadata: Type.Optional(Metadata),
});

Expand Down
14 changes: 12 additions & 2 deletions src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ export class PgStore extends BasePgStore {
if (args.locale && !(await this.isTokenLocaleAvailable(tokenIdRes[0].id, args.locale))) {
throw new TokenLocaleNotFoundError();
}
return await this.getTokenMetadataBundleInternal(tokenIdRes[0].id, args.locale);
return await this.getTokenMetadataBundleInternal(
tokenIdRes[0].id,
args.contractPrincipal,
args.locale
);
});
}

Expand Down Expand Up @@ -442,6 +446,7 @@ export class PgStore extends BasePgStore {

private async getTokenMetadataBundleInternal(
tokenId: number,
smartContractPrincipal: string,
locale?: string
): Promise<DbTokenMetadataLocaleBundle> {
const tokenRes = await this.sql<DbToken[]>`
Expand Down Expand Up @@ -477,8 +482,13 @@ export class PgStore extends BasePgStore {
properties: properties,
};
}
const smartContract = await this.getSmartContract({ principal: smartContractPrincipal });
if (!smartContract) {
throw new TokenNotFoundError();
}
return {
token: token,
token,
smartContract,
metadataLocale: localeBundle,
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/pg/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export type DbSmartContract = {
id: number;
principal: string;
sip: DbSipNumber;
abi: string;
tx_id: string;
block_height: number;
token_count?: bigint;
Expand Down Expand Up @@ -188,14 +187,14 @@ export type DbMetadataLocaleBundle = {

export type DbTokenMetadataLocaleBundle = {
token: DbToken;
smartContract: DbSmartContract;
metadataLocale?: DbMetadataLocaleBundle;
};

export const SMART_CONTRACTS_COLUMNS = [
'id',
'principal',
'sip',
'abi',
'tx_id',
'block_height',
'token_count',
Expand Down
7 changes: 7 additions & 0 deletions tests/ft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ describe('FT routes', () => {
symbol: 'HELLO',
token_uri: 'http://test.com/uri.json',
total_supply: '1',
sender_address: 'SP2SYHR84SDJJDK8M09HFS4KBFXPPCX9H7RZ9YVTS',
tx_id: '0x123456',
});
});

Expand Down Expand Up @@ -182,6 +184,11 @@ describe('FT routes', () => {
token_uri: 'http://test.com/uri.json',
total_supply: '1',
decimals: 6,
sender_address: 'SP2SYHR84SDJJDK8M09HFS4KBFXPPCX9H7RZ9YVTS',
tx_id: '0x123456',
description: 'test',
image_canonical_uri: 'http://test.com/image.png',
image_uri: 'http://test.com/image.png?processed=true',
metadata: {
sip: 16,
description: 'test',
Expand Down