Skip to content

Commit

Permalink
BLOCK-1602 removed serialNumber from token metadata files + minor fix…
Browse files Browse the repository at this point in the history
…es (#17)
  • Loading branch information
ammanpashasc authored Aug 1, 2023
1 parent 59e715b commit 697bbfc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ The `upload.json` file contains all metadata (collection name, factory/token has
},
"environment": {
"env": "production",
"url": "https://www.my-nft-website.com"
"tokenUriTemplate": "{serial_number}",
"url": "https://www.my-nft-website.com",
"toolVersion": "1.4.0"
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metadata-tool",
"version": "1.3.0",
"version": "1.4.0",
"description": "",
"main": "index.ts",
"scripts": {
Expand Down Expand Up @@ -48,4 +48,4 @@
"singleQuote": true,
"printWidth": 120
}
}
}
12 changes: 4 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import { NFTData } from './types';
import { outputJsonFiles } from './utils/outputJsonFiles';
import { UploadOutput } from './types/uploadOutput';
import { UrlMapper } from './utils/urlMapper';
const { version } = require('../package.json');

const glob = promisify(globMod);

const main = async () => {
ReportGenerator.add('Started Program', false);
const VERSION = version;
ReportGenerator.add(`Started Metadata Tool v${VERSION}`, true);
ExitHandlers.init();

let fileType: 'csv' | 'json' = 'csv';
Expand Down Expand Up @@ -98,13 +100,6 @@ const main = async () => {
return;
}

// if (!isCSV && !files.includes(`defaultToken.json`)) {
// const errorMessage = ErrorGenerator.get('MISSING_DEFAULT_TOKEN_FILE', '.json');
// ReportGenerator.add(errorMessage);
// await promptUser(errorMessage);
// return;
// }

// if processing csv files, notify if tokens file is present
if (isCSV && files.includes(`tokens.${fileType}`)) {
ReportGenerator.add(`tokens.${fileType} file was also found in the provided directory.`, true);
Expand Down Expand Up @@ -254,6 +249,7 @@ const main = async () => {
env: config.environment,
tokenUriTemplate: nftData.factory.tokenUriTemplate,
url: config.environmentUrl,
toolVersion: VERSION,
},
};

Expand Down
1 change: 1 addition & 0 deletions src/types/uploadOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface UploadOutput {
env: string;
url: string;
tokenUriTemplate: '{serial_number}' | '{hash}'; // The uri template to follow to tokens - either "{serial_number}" or "{hash}"
toolVersion: string | undefined; // Version of this tool. Taken from package.json
};

/**
Expand Down
10 changes: 8 additions & 2 deletions src/utils/outputJsonFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ export async function outputJsonFiles(
};

if (data.defaultToken) {
// Don't include defaultToken.serialNumber when writing to file
ReportGenerator.add(`Writing defaultToken.json to file.`);
fs.writeFileSync(paths.defaultToken, JSON.stringify(data.defaultToken, null, 2));
fs.writeFileSync(
paths.defaultToken,
JSON.stringify({ ...data.defaultToken, serialNumber: undefined }, null, 2)
);
}

// Don't include factory.tokenUriTemplate when writing to file
ReportGenerator.add(`Writing factory.json to file.`);
fs.writeFileSync(paths.factory, JSON.stringify({ ...data.factory, tokenUriTemplate: undefined }, null, 2));

Expand Down Expand Up @@ -76,8 +81,9 @@ export async function outputJsonFiles(
for (let token of data.tokens) {
const tokenPath = normalizeUrl(path.join(workingDirectory, `/${token.serialNumber}.token.json`));

// Don't include token.serialNumber when writing to file
ReportGenerator.add(`Writing ${token.serialNumber}.token.json to file.`);
fs.writeFileSync(tokenPath, JSON.stringify(token, null, 2));
fs.writeFileSync(tokenPath, JSON.stringify({ ...token, serialNumber: undefined }, null, 2));

const tokenHash = await HashGenerator.create(tokenPath);
if (typeof tokenHash === 'undefined') {
Expand Down

0 comments on commit 697bbfc

Please sign in to comment.