Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/chronik.js
// Chronik methods | // Chronik methods | ||||
import BigNumber from 'bignumber.js'; | import BigNumber from 'bignumber.js'; | ||||
import { currency } from 'components/Common/Ticker'; | import { currency } from 'components/Common/Ticker'; | ||||
import { | import { | ||||
parseOpReturn, | parseOpReturn, | ||||
convertToEncryptStruct, | convertToEncryptStruct, | ||||
getHashArrayFromWallet, | getHashArrayFromWallet, | ||||
getUtxoWif, | getUtxoWif, | ||||
convertEcashtoEtokenAddr, | convertEcashtoEtokenAddr, | ||||
convertToEcashPrefix, | hash160ToAddress, | ||||
} from 'utils/cashMethods'; | } from 'utils/cashMethods'; | ||||
import ecies from 'ecies-lite'; | import ecies from 'ecies-lite'; | ||||
import wif from 'wif'; | import wif from 'wif'; | ||||
import cashaddr from 'ecashaddrjs'; | import cashaddr from 'ecashaddrjs'; | ||||
// Return false if do not get a valid response | // Return false if do not get a valid response | ||||
export const getTokenStats = async (chronik, tokenId) => { | export const getTokenStats = async (chronik, tokenId) => { | ||||
try { | try { | ||||
▲ Show 20 Lines • Show All 889 Lines • ▼ Show 20 Lines | ) => { | ||||
return { | return { | ||||
chronikTxHistory, | chronikTxHistory, | ||||
txHistoryUpdatedTokenInfoById, | txHistoryUpdatedTokenInfoById, | ||||
txHistoryNewTokensToCache, | txHistoryNewTokensToCache, | ||||
}; | }; | ||||
}; | }; | ||||
export const getMintAddress = async (chronik, BCH, tokenId) => { | export const getMintAddress = async (chronik, tokenId) => { | ||||
let genesisTx; | let genesisTx; | ||||
let mintingHash160; | let mintingHash160; | ||||
try { | try { | ||||
genesisTx = await chronik.tx(tokenId); | genesisTx = await chronik.tx(tokenId); | ||||
// get the minting address chronik | // get the minting address chronik | ||||
// iterate over the tx outputs | // iterate over the tx outputs | ||||
const { outputs } = genesisTx; | const { outputs } = genesisTx; | ||||
for (let i = 0; i < outputs.length; i += 1) { | for (let i = 0; i < outputs.length; i += 1) { | ||||
Show All 9 Lines | try { | ||||
// then this is the minting address | // then this is the minting address | ||||
const thisOutputHash160 = thisOutput.outputScript; | const thisOutputHash160 = thisOutput.outputScript; | ||||
mintingHash160 = thisOutputHash160.substring( | mintingHash160 = thisOutputHash160.substring( | ||||
thisOutputHash160.indexOf('76a914') + '76a914'.length, | thisOutputHash160.indexOf('76a914') + '76a914'.length, | ||||
thisOutputHash160.lastIndexOf('88ac'), | thisOutputHash160.lastIndexOf('88ac'), | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
const mintingAdressBchFormat = | |||||
BCH.Address.hash160ToCash(mintingHash160); | return convertEcashtoEtokenAddr(hash160ToAddress(mintingHash160)); | ||||
const mintEcashAddressChronik = convertToEcashPrefix( | |||||
mintingAdressBchFormat, | |||||
); | |||||
const mintEtokenAddressChronik = convertEcashtoEtokenAddr( | |||||
mintEcashAddressChronik, | |||||
); | |||||
return mintEtokenAddressChronik; | |||||
} catch (err) { | } catch (err) { | ||||
console.log(`Error in getMintAddress`, err); | console.log(`Error in getMintAddress`, err); | ||||
return err; | return err; | ||||
} | } | ||||
}; | }; |