Init
This commit is contained in:
commit
e5a7886b9c
7 files changed
+316
No files matched your search
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Token Schema",
|
||||
"description": "Schema for validating token information in a blockchain context.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "The name of the token."
|
||||
},
|
||||
"ticker": {
|
||||
"type": "string",
|
||||
"description": "The short name of the token."
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
"description": "The full name of the network or token."
|
||||
},
|
||||
"iconFileName": {
|
||||
"type": "string",
|
||||
"description": "The icon file name for the token."
|
||||
},
|
||||
"infoURL": {
|
||||
"type": "string",
|
||||
"format": "uri",
|
||||
"description": "URL for additional information about the token."
|
||||
},
|
||||
"contractAddress": {
|
||||
"type": "string",
|
||||
"description": "The smart contract address of the token."
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"fungible",
|
||||
"nft"
|
||||
],
|
||||
"description": "The type of token (fungible or NFT)."
|
||||
},
|
||||
"decimals": {
|
||||
"type": "integer",
|
||||
"description": "The number of decimal places."
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"description": "A description of the token.",
|
||||
"default": ""
|
||||
},
|
||||
"website": {
|
||||
"type": "string",
|
||||
"format": "uri",
|
||||
"description": "Link to the project's website.",
|
||||
"default": ""
|
||||
},
|
||||
"whitepaper": {
|
||||
"type": "string",
|
||||
"format": "uri",
|
||||
"description": "Link to the project's whitepaper.",
|
||||
"default": ""
|
||||
},
|
||||
"initialSupply": {
|
||||
"type": "number",
|
||||
"description": "The initial supply of tokens.",
|
||||
"default": 0
|
||||
},
|
||||
"totalSupply": {
|
||||
"type": "number",
|
||||
"description": "The total supply of tokens.",
|
||||
"default": 0
|
||||
},
|
||||
"maxSupply": {
|
||||
"type": "number",
|
||||
"description": "The maximum supply of tokens.",
|
||||
"default": 0
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"ticker",
|
||||
"title",
|
||||
"iconFileName",
|
||||
"infoURL",
|
||||
"contractAddress",
|
||||
"type",
|
||||
"decimals"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
const Ajv = require('ajv');
|
||||
const addFormats = require('ajv-formats');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const schema = require('./token-schema.json');
|
||||
|
||||
function validateJsonFile(filePath) {
|
||||
try {
|
||||
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
const valid = validate(data);
|
||||
if (valid) {
|
||||
console.log(`File ${path.basename(filePath)} is valid.`);
|
||||
} else {
|
||||
console.log(`File ${path.basename(filePath)} is invalid:`, validate.errors);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error reading or parsing the file ${path.basename(filePath)}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
function validateAllJsonFilesInDirectory(directoryPath) {
|
||||
fs.readdir(directoryPath, (err, files) => {
|
||||
if (err) {
|
||||
console.error('Error reading directory:', err);
|
||||
return;
|
||||
}
|
||||
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(directoryPath, file);
|
||||
if (path.extname(file) === '.json') {
|
||||
validateJsonFile(filePath);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const ajv = new Ajv();
|
||||
addFormats(ajv);
|
||||
|
||||
const validate = ajv.compile(schema);
|
||||
|
||||
const dataDirectoryPath = path.resolve(process.cwd(), 'data');
|
||||
|
||||
validateAllJsonFilesInDirectory(dataDirectoryPath);
|
||||
Reference in new issue
Block a user