[Internal] Enforce values for type in info files (#5513)

* Generate missing info files for ETC tokens.

* Add missing waves info files

* Revert

* Fix wanchain ID casing.

* Enforce values for type in info files.

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
Adam R 2021-02-08 11:23:34 +01:00 committed by GitHub
parent 617df987fd
commit dd56b0122a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 38 additions and 12 deletions

View File

@ -1,7 +1,7 @@
{
"name": "BosTravel",
"symbol": "BOT",
"type": "G020",
"type": "GO20",
"decimals": 18,
"description": "-",
"website": "",

View File

@ -1,7 +1,7 @@
{
"name": "GoDental",
"symbol": "GOD",
"type": "G020",
"type": "GO20",
"decimals": 18,
"description": "-",
"website": "",

View File

@ -1,7 +1,7 @@
{
"name": "Lam Anh Dental",
"symbol": "LAD",
"type": "G020",
"type": "GO20",
"decimals": 18,
"description": "-",
"website": "",

View File

@ -1,7 +1,7 @@
{
"name": "PAZTether",
"symbol": "PAZT",
"type": "G020",
"type": "GO20",
"decimals": 18,
"description": "-",
"website": "",

View File

@ -1,7 +1,7 @@
{
"name": "Go A2ZHome",
"symbol": "A2Z",
"type": "G020",
"type": "GO20",
"decimals": 18,
"description": "-",
"website": "",

View File

@ -1,7 +1,7 @@
{
"name": "Ontology Gas",
"symbol": "ONG",
"type": "gas",
"type": "ontology",
"decimals": 9,
"description": "-",
"website": "",

View File

@ -1,7 +1,7 @@
{
"name": "PayFrequent EURO",
"symbol": "PEUR",
"type": "TRC20",
"type": "TRC21",
"decimals": 6,
"description": "-",
"website": "",

View File

@ -1,7 +1,7 @@
{
"name": "PayFrequent",
"symbol": "PayFQ",
"type": "TRC20",
"type": "TRC21",
"decimals": 6,
"description": "-",
"website": "",

View File

@ -1,7 +1,7 @@
{
"name": "24x7 Crypto",
"symbol": "24x7",
"type": "TRC20",
"type": "TRC21",
"decimals": 4,
"description": "-",
"website": "",

View File

@ -1,7 +1,7 @@
{
"name": "PayFrequent USD",
"symbol": "PUSD",
"type": "TRC20",
"type": "TRC21",
"decimals": 6,
"description": "-",
"website": "",

View File

@ -24,7 +24,7 @@ function isAssetInfoHasAllKeys(info: unknown, path: string): [boolean, string] {
return [hasAllKeys, `Info at path '${path}' missing next key(s): ${arrayDiff(requiredKeys, infoKeys)}`];
}
function isAssetInfoValid(info: unknown, path: string, address: string): [string, string] {
function isAssetInfoValid(info: unknown, path: string, address: string, chain: string): [string, string] {
const isKeys1CorrectType =
typeof info['name'] === "string" && info['name'] !== "" &&
typeof info['type'] === "string" && info['type'] !== "" &&
@ -35,6 +35,10 @@ function isAssetInfoValid(info: unknown, path: string, address: string): [string
return [`Check keys1 '${info['name']}' '${info['type']}' '${info['symbol']}' '${info['decimals']}' '${info['id']}' ${path}`, ""];
}
if (typeof info['type'] !== "string" || chainFromAssetType(info['type']) !== chain ) {
return [`Incorrect type '${info['type']}' '${chain}' '${path}`, ""];
}
if (typeof info['id'] !== "string" || info['id'] !== address ) {
return [`Incorrect id '${info['id']}' '${path}`, ""];
}
@ -56,6 +60,28 @@ function isAssetInfoValid(info: unknown, path: string, address: string): [string
return ["", ""];
}
export function chainFromAssetType(type: string): string {
switch (type) {
case "ERC20": return "ethereum";
case "BEP2": return "binance";
case "BEP20": return "smartchain";
case "ETC20": return "classic";
case "TRC10":
case "TRC20":
return "tron";
case "WAN20": return "wanchain";
case "TRC21": return "tomochain";
case "TT20": return "thundertoken";
case "SPL": return "solana";
case "GO20": return "gochain";
case "KAVA": return "kava";
case "NEP5": return "neo";
case "NRC20": return "nuls";
case "VET": return "vechain";
case "ontology": return "ontology";
}
}
export function explorerUrl(chain: string, contract: string): string {
if (contract) {
switch (chain.toLowerCase()) {
@ -146,7 +172,7 @@ function isAssetInfoOK(chain: string, address: string, errors: string[], warning
errors.push(msg1);
}
const [err2, warn2] = isAssetInfoValid(info, assetInfoPath, address);
const [err2, warn2] = isAssetInfoValid(info, assetInfoPath, address, chain);
if (err2) {
errors.push(err2);
}