Skip to content

Commit

Permalink
fix: market scan error
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulgalimov committed Apr 24, 2024
1 parent bf43eb2 commit daf84ba
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 37 deletions.
32 changes: 14 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unique-marketplace-backend",
"version": "3.0.246",
"version": "3.0.248",
"description": "Backend project for unique marketplace",
"author": "Unique Network",
"private": true,
Expand Down Expand Up @@ -65,7 +65,7 @@
"helmet": "^6.1.2",
"husky": "^8.0.3",
"minio": "^7.1.1",
"nestjs-graphile-worker": "^0.3.1",
"nestjs-graphile-worker": "^0.7.0",
"nestjs-typeorm-paginate": "^4.0.3",
"pg": "^8.9.0",
"pg-connection-string": "^2.5.0",
Expand Down
26 changes: 20 additions & 6 deletions packages/escrow/src/app/sdk.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Logger } from "@nestjs/common";
import { Injectable, Logger } from '@nestjs/common';

import {
ChainPropertiesResponse,
Expand Down Expand Up @@ -26,7 +26,6 @@ export type TokenBalance = {

@Injectable()
export class SdkService {

private logger = new Logger('SDK');
constructor(private readonly sdk: Sdk) {}

Expand Down Expand Up @@ -82,8 +81,19 @@ export class SdkService {
return [...new Set(recurseBundle(bundle))];
}

async getTokenSchema(collectionId: number, tokenId: number): Promise<TokenByIdResponse> {
return await this.sdk.tokens.get({ collectionId: collectionId, tokenId: tokenId });
async getTokenSchema(collectionId: number, tokenId: number): Promise<TokenByIdResponse | null> {
let token: TokenByIdResponse;
try {
token = await this.sdk.token.get({ collectionId: collectionId, tokenId: tokenId });
} catch (error) {
if (error.message === 'Token not found') {
return null;
}

throw error;
}

return token;
}

/**
Expand Down Expand Up @@ -150,12 +160,16 @@ export class SdkService {
* @param collectionId
* @param at
*/
async getSchemaToken(tokenId: number, collectionId: number): Promise<TokenByIdResponse> {
async getSchemaToken(tokenId: number, collectionId: number): Promise<TokenByIdResponse | null> {
let getSchema;
try {
getSchema = await this.sdk.token.get({ collectionId, tokenId });
} catch (e) {
this.logger.error(e);
if (e.message === 'Token not found') {
return null;
}

throw e;
}
if (!getSchema) {
return null;
Expand Down
5 changes: 2 additions & 3 deletions packages/escrow/src/collections/tokens.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ export class TokensService {
if (collection) {
const chain = await this.sdk.getChainProperties();
//Check token lives in the chain
try {
await this.sdk.getTokenSchema(collectionId, tokenId);
} catch (e) {
const token = await this.sdk.getTokenSchema(collectionId, tokenId);
if (token == null) {
await this.cleanTokenAndProperties(collectionId, tokenId, chain.token);
this.logger.error('Token not found or burned!');
return;
Expand Down
24 changes: 16 additions & 8 deletions packages/escrow/src/tasks/properties.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ export class PropertiesTask {
*/
@TaskHandler()
async handler(payload: Market.Payload, helpers: Helpers): Promise<void> {
this.addSearchIndexIfNotExists(payload);
await this.addSearchIndexIfNotExists(payload);
}

async getTokenInfoItems({ collectionId, tokenId }: CollectionToken): Promise<SerializeTokenType> {
const source = await this.preparePropertiesData(tokenId, collectionId);
return source;
return this.preparePropertiesData(tokenId, collectionId);
}

private findNestedToken(bundle: NestedToken, tokenId: number): NestedToken | undefined {
Expand All @@ -60,7 +59,7 @@ export class PropertiesTask {
collection: any;
isBundle: boolean;
serializeBundle: Array<BundleType>;
}> {
}> | null {
const { isBundle } = await this.sdkService.isBundle(tokenId, collectionId);
let token = null;
let serializeBundle = [];
Expand All @@ -69,6 +68,8 @@ export class PropertiesTask {
this.sdkService.getBundle(tokenId, collectionId),
this.sdkService.getTokenSchema(collectionId, tokenId),
]);
if (!tokenData) return null;

token = tokenData;

if (bundle.tokenId === tokenId) {
Expand All @@ -85,7 +86,9 @@ export class PropertiesTask {
serializeBundle = this.sdkService.serializeBunlde(token);
} else {
token = await this.sdkService.getTokenSchema(collectionId, tokenId);
if (!token) return null;
}

const collection = await this.sdkService.getSchemaCollection(collectionId);
return {
token,
Expand All @@ -95,7 +98,7 @@ export class PropertiesTask {
};
}

async addSearchIndexIfNotExists(collectionToken: CollectionToken): Promise<any> {
async addSearchIndexIfNotExists(collectionToken: CollectionToken): Promise<void> {
const { collectionId, tokenId, network } = collectionToken;

const dbIndexList = await this.propertiesRepository.find({
Expand All @@ -115,7 +118,9 @@ export class PropertiesTask {
}

const searchIndexItems = await this.getTokenInfoItems(collectionToken);
return this.saveProperties(collectionToken, searchIndexItems);
if (searchIndexItems) {
await this.saveProperties(collectionToken, searchIndexItems);
}
}

async saveProperties(collectionToken: CollectionToken, source: SerializeTokenType): Promise<PropertiesEntity[]> {
Expand Down Expand Up @@ -157,10 +162,13 @@ export class PropertiesTask {
return this.propertiesRepository.save(propertiesDataItems);
}

async preparePropertiesData(tokenId: number, collectionId: number): Promise<any> {
async preparePropertiesData(tokenId: number, collectionId: number): Promise<SerializeTokenType | null> {
const tokenData = await this.tokenWithCollection(tokenId, collectionId);
if (!tokenData) {
return null;
}

const source = new Set();
const source: Set<TokenInfo> = new Set();
// Collection
source
.add({
Expand Down

0 comments on commit daf84ba

Please sign in to comment.