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.
This commit is contained in:
parent
615e8b80c8
commit
4f035dae0f
|
@ -1,5 +1,5 @@
|
|||
import { ActionInterface, CheckStepInterface } from "../../script/action/interface";
|
||||
import { run } from "./script";
|
||||
import { update, mergeCmcData } from "./script";
|
||||
import { getSanityChecks } from "./check";
|
||||
|
||||
export class Coinmarketcap implements ActionInterface {
|
||||
|
@ -11,9 +11,12 @@ export class Coinmarketcap implements ActionInterface {
|
|||
|
||||
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> {
|
||||
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)
|
||||
]
|
||||
|
||||
const allContracts: mapTiker[] = [] // Temp storage for mapped assets
|
||||
var allContracts: mapTiker[] = [] // Temp storage for mapped assets
|
||||
let bnbOwnerToSymbol = {} // e.g: bnb1tawge8u97slduhhtumm03l4xl4c46dwv5m9yzk: WISH-2D5
|
||||
let bnbOriginalSymbolToSymbol = {} // e.g: WISH: WISH-2D5
|
||||
|
||||
export async function run() {
|
||||
try {
|
||||
await Promise.all([initState(), setBinanceTokens()])
|
||||
const [totalCrypto, coins] = await Promise.all([getTotalActiveCryptocurrencies(), getTickers()])
|
||||
// setBIP44Constants()
|
||||
log(`Found ${totalCrypto} on CMC`, chalk.yellowBright)
|
||||
await BluebirdPromise.mapSeries(coins, processCoin)
|
||||
async function retrieveCmcData() {
|
||||
allContracts = []
|
||||
await Promise.all([initState(), setBinanceTokens()])
|
||||
const [totalCrypto, coins] = await Promise.all([getTotalActiveCryptocurrencies(), getTickers()])
|
||||
// setBIP44Constants()
|
||||
log(`Found ${totalCrypto} on CMC`, chalk.yellowBright)
|
||||
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()
|
||||
printContracts()
|
||||
} 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)
|
||||
}
|
||||
|
||||
function printContracts() {
|
||||
function sortContracts() {
|
||||
const sortedById = allContracts.sort((a,b) => {
|
||||
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
|
||||
})
|
||||
allContracts = sortedById
|
||||
}
|
||||
|
||||
|
||||
function printContracts() {
|
||||
sortContracts()
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user