Skip to content

Commit

Permalink
support many simple nfts (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit authored Oct 31, 2023
1 parent 8c5be54 commit 0d9e16f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default {
vitMigratedAtBlock: getEnv('VIT_MIGRATED_AT_BLOCK'),
vitMigratedTS: Number(getEnv('VIT_MIGRATED_TS')),
readMigrateNfts: Boolean(getEnv('READ_MIGRATED_NFTS', '')),
old: getEnv('NFT_OLD', ''),
},
archive: {
uri: getEnv('ARCHIVE_URI'),
Expand Down
5 changes: 2 additions & 3 deletions src/handlers/cb-nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { BatchState } from '../batchState';
import { readFileSync } from 'fs';
import { MasterNftEvent } from '../types';
import { getDate } from '../utils';
import config from '../config';
import { getCollectionDescription, getCollectionName } from './helpers';

const meta = ProgramMetadata.from(readFileSync('./assets/cb-nft.meta.txt', 'utf8'));
Expand All @@ -24,8 +23,8 @@ export async function cbNftHandler(
let collection = await state.getCollection(source);
if (!collection) {
const [collectionName, collectionDesc] = await Promise.all([
getCollectionName(meta, config.nfts.cb),
getCollectionDescription(meta, config.nfts.cb),
getCollectionName(meta, source),
getCollectionDescription(meta, source),
]);
collection = state.newCollection(source, collectionName, collectionDesc);
}
Expand Down
5 changes: 2 additions & 3 deletions src/handlers/draft-nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ProgramMetadata } from '@gear-js/api';
import { BatchState } from '../batchState';
import { readFileSync } from 'fs';
import { DraftNftEvent } from '../types';
import config from '../config';
import { getCollectionDescription, getCollectionName } from './helpers';

const meta = ProgramMetadata.from(readFileSync('./assets/draft-nft.meta.txt', 'utf8'));
Expand All @@ -20,8 +19,8 @@ export async function draftNftHandler(
let collection = await state.getCollection(source);
if (!collection) {
const [collectionName, collectionDesc] = await Promise.all([
getCollectionName(meta, config.nfts.draft, '0x00'),
getCollectionDescription(meta, config.nfts.draft, '0x01'),
getCollectionName(meta, source, '0x00'),
getCollectionDescription(meta, source, '0x01'),
]);
collection = state.newCollection(source, collectionName, collectionDesc);
}
Expand Down
7 changes: 6 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { readMigratedNfts } from './handlers/vit-nft';
import { draftNftHandler } from './handlers/draft-nft';

const programs = [config.nfts.cb, config.nfts.vit];
const simpleNfts = [config.nfts.draft];

if (config.nfts.old !== '') {
simpleNfts.push(...config.nfts.old.split(','));
}

let isMigratedNftsSaved = !config.nfts.readMigrateNfts;

Expand Down Expand Up @@ -38,7 +43,7 @@ processor.run(new TypeormDatabase(), async (ctx) => {

if (programs.includes(source)) {
await cbNftHandler(state, payload, source, blockNumber, ts);
} else if (source === config.nfts.draft) {
} else if (simpleNfts.includes(source)) {
await draftNftHandler(state, payload, source, blockNumber, ts);
}
}
Expand Down

0 comments on commit 0d9e16f

Please sign in to comment.