mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
CMC mapping: merge exceptions on every commit, retrieve from CMC and merge on Update runs. (#3406)
Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
parent
d310074554
commit
78eef8eabc
|
@ -1,5 +1,5 @@
|
||||||
import { ActionInterface, CheckStepInterface } from "../../script/action/interface";
|
import { ActionInterface, CheckStepInterface } from "../../script/action/interface";
|
||||||
import { run } from "./script";
|
import { update, mergeCmcData } from "./script";
|
||||||
import { getSanityChecks } from "./check";
|
import { getSanityChecks } from "./check";
|
||||||
|
|
||||||
export class Coinmarketcap implements ActionInterface {
|
export class Coinmarketcap implements ActionInterface {
|
||||||
|
@ -11,9 +11,12 @@ export class Coinmarketcap implements ActionInterface {
|
||||||
|
|
||||||
sanityFix = null;
|
sanityFix = null;
|
||||||
|
|
||||||
consistencyFix = null;
|
async consistencyFix(): Promise<void> {
|
||||||
|
// do merge, for the case exceptions or script has been changed
|
||||||
|
await mergeCmcData();
|
||||||
|
}
|
||||||
|
|
||||||
async update(): Promise<void> {
|
async update(): Promise<void> {
|
||||||
await run();
|
await update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12903
pricing/coinmarketcap/cmc-data.json
Normal file
12903
pricing/coinmarketcap/cmc-data.json
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -59,22 +59,39 @@ const custom: mapTiker[] = [
|
||||||
// {"coin": 60, "type": typeToken, "token_id": "XXX", "id": XXX}, // XXX (XXX)
|
// {"coin": 60, "type": typeToken, "token_id": "XXX", "id": XXX}, // XXX (XXX)
|
||||||
]
|
]
|
||||||
|
|
||||||
const allContracts: mapTiker[] = [] // Temp storage for mapped assets
|
var allContracts: mapTiker[] = [] // Temp storage for mapped assets
|
||||||
let bnbOwnerToSymbol = {} // e.g: bnb1tawge8u97slduhhtumm03l4xl4c46dwv5m9yzk: WISH-2D5
|
let bnbOwnerToSymbol = {} // e.g: bnb1tawge8u97slduhhtumm03l4xl4c46dwv5m9yzk: WISH-2D5
|
||||||
let bnbOriginalSymbolToSymbol = {} // e.g: WISH: WISH-2D5
|
let bnbOriginalSymbolToSymbol = {} // e.g: WISH: WISH-2D5
|
||||||
|
|
||||||
export async function run() {
|
async function retrieveCmcData() {
|
||||||
try {
|
allContracts = []
|
||||||
await Promise.all([initState(), setBinanceTokens()])
|
await Promise.all([initState(), setBinanceTokens()])
|
||||||
const [totalCrypto, coins] = await Promise.all([getTotalActiveCryptocurrencies(), getTickers()])
|
const [totalCrypto, coins] = await Promise.all([getTotalActiveCryptocurrencies(), getTickers()])
|
||||||
// setBIP44Constants()
|
// setBIP44Constants()
|
||||||
log(`Found ${totalCrypto} on CMC`, chalk.yellowBright)
|
log(`Found ${totalCrypto} on CMC`, chalk.yellowBright)
|
||||||
await BluebirdPromise.mapSeries(coins, processCoin)
|
await BluebirdPromise.mapSeries(coins, processCoin)
|
||||||
|
|
||||||
|
sortContracts()
|
||||||
|
fs.writeFileSync(path.join(__dirname, 'cmc-data.json'), JSON.stringify(allContracts, null, 4))
|
||||||
|
allContracts = []
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function mergeCmcData() {
|
||||||
|
try {
|
||||||
|
allContracts = JSON.parse(readFileSync(path.join(__dirname, 'cmc-data.json')))
|
||||||
addCustom()
|
addCustom()
|
||||||
printContracts()
|
printContracts()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(`Error at the end ${error.message}`)
|
log(`Exception: ${error.message}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function update() {
|
||||||
|
try {
|
||||||
|
await retrieveCmcData()
|
||||||
|
await mergeCmcData()
|
||||||
|
} catch (error) {
|
||||||
|
log(`Exception: ${error.message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +237,7 @@ function addToContractsList(ticker: mapTiker) {
|
||||||
allContracts.push(ticker)
|
allContracts.push(ticker)
|
||||||
}
|
}
|
||||||
|
|
||||||
function printContracts() {
|
function sortContracts() {
|
||||||
const sortedById = allContracts.sort((a,b) => {
|
const sortedById = allContracts.sort((a,b) => {
|
||||||
if (a.id < b.id) return -1
|
if (a.id < b.id) return -1
|
||||||
if (a.id > b.id) return 1
|
if (a.id > b.id) return 1
|
||||||
|
@ -233,9 +250,14 @@ function printContracts() {
|
||||||
if (a.token_id < b.token_id) return -1
|
if (a.token_id < b.token_id) return -1
|
||||||
if (a.token_id > b.token_id) return 1
|
if (a.token_id > b.token_id) return 1
|
||||||
})
|
})
|
||||||
|
allContracts = sortedById
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function printContracts() {
|
||||||
|
sortContracts()
|
||||||
const wstream = fs.createWriteStream(path.join(__dirname, 'mapping.json'))
|
const wstream = fs.createWriteStream(path.join(__dirname, 'mapping.json'))
|
||||||
wstream.write(JSON.stringify(sortedById, null, 4))
|
wstream.write(JSON.stringify(allContracts, null, 4))
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSlip44Index(symbol: string, name: string): number {
|
function getSlip44Index(symbol: string, name: string): number {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user