import { Algorithm } from "../Algorithm" ; import * as WhatToMine from "../apis/whattomine" ; import { logger } from "../logger" ; export interface ICoin { displayName : string ; names : string [ ] ; abbreviation : string ; id : number ; algorithm : Algorithm ; enabled : boolean | null ; lagging : boolean ; } interface ICoinNames { displayName ? : string ; names ? : string [ ] ; } function getAlgorithm ( algo ) { const match = ( Algorithm as any ) [ algo ] as Algorithm ; if ( ! match ) return null ; if ( ! match . niceHash ) return null ; if ( ! match . whatToMine ) return null ; return match ; } function getAdditionalNames ( coin ) { const coins = { BitcoinCash : { displayName : "Bitcoin Cash" , names : [ "bcash" , "bcc" ] } , BitcoinGold : { displayName : "Bitcoin Gold" } , EthereumClassic : { displayName : "Ethereum Classic" } , BitcoinPrivate : { displayName : "Bitcoin Private" } , } ; return coins [ coin . displayName ] || { } ; } export async function getCoins ( ) { const whatToMineCalculators = await WhatToMine . getCalculators ( ) ; const coins = [ ] ; for ( const whatToMineCalculator of whatToMineCalculators ) { const coin = { } as any ; coin . enabled = null ; coin . displayName = whatToMineCalculator . name ; coin . abbreviation = whatToMineCalculator . tag ; coin . names = [ coin . displayName . toLowerCase ( ) , coin . abbreviation . toLowerCase ( ) ] ; coin . lagging = whatToMineCalculator . lagging ; const additionalNames = getAdditionalNames ( coin ) ; if ( additionalNames . displayName ) { coin . displayName = additionalNames . displayName ; coin . names . push ( coin . displayName . toLowerCase ( ) ) ; } if ( additionalNames . names ) { coin . names = coin . names . concat ( additionalNames . names ) ; } coin . id = whatToMineCalculator . id ; const algorithm = getAlgorithm ( whatToMineCalculator . algorithm ) ; if ( algorithm === null ) { logger . debug ( `getCoins(): unknown algo: ${ whatToMineCalculator . algorithm } (${ whatToMineCalculator . name })` ) ; continue ; } coin . algorithm = algorithm ; coins . push ( coin ) ; } coins . sort ( ( a , b ) => a . id - b . id ) ; return coins ; }