Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/chronik.js
Show First 20 Lines • Show All 427 Lines • ▼ Show 20 Lines | export const parseChronikTx = (BCH, tx, wallet) => { | ||||
const walletHash160s = getHashArrayFromWallet(wallet); | const walletHash160s = getHashArrayFromWallet(wallet); | ||||
const { inputs, outputs } = tx; | const { inputs, outputs } = tx; | ||||
// Assign defaults | // Assign defaults | ||||
let incoming = true; | let incoming = true; | ||||
let xecAmount = new BigNumber(0); | let xecAmount = new BigNumber(0); | ||||
let originatingHash160 = ''; | let originatingHash160 = ''; | ||||
let etokenAmount = new BigNumber(0); | let etokenAmount = new BigNumber(0); | ||||
const isEtokenTx = 'slpTxData' in tx && typeof tx.slpTxData !== 'undefined'; | const isEtokenTx = 'slpTxData' in tx && typeof tx.slpTxData !== 'undefined'; | ||||
const isGenesisTx = | |||||
isEtokenTx && | |||||
tx.slpTxData.slpMeta && | |||||
tx.slpTxData.slpMeta.txType && | |||||
tx.slpTxData.slpMeta.txType === 'GENESIS'; | |||||
if (isGenesisTx) { | |||||
console.log(`${tx.txid} isGenesisTx`); | |||||
} | |||||
// Defining variables used in lines legacy parseTxData function from useBCH.js | // Defining variables used in lines legacy parseTxData function from useBCH.js | ||||
let substring = ''; | let substring = ''; | ||||
let airdropFlag = false; | let airdropFlag = false; | ||||
let airdropTokenId = ''; | let airdropTokenId = ''; | ||||
let opReturnMessage = ''; | let opReturnMessage = ''; | ||||
let isCashtabMessage = false; | let isCashtabMessage = false; | ||||
let isEncryptedMessage = false; | let isEncryptedMessage = false; | ||||
▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | for (let i = 0; i < outputs.length; i += 1) { | ||||
// Parse token qty if token tx | // Parse token qty if token tx | ||||
// Note: edge case this is a token tx that sends XEC to Cashtab recipient but token somewhere else | // Note: edge case this is a token tx that sends XEC to Cashtab recipient but token somewhere else | ||||
if (isEtokenTx) { | if (isEtokenTx) { | ||||
try { | try { | ||||
const thisEtokenAmount = new BigNumber( | const thisEtokenAmount = new BigNumber( | ||||
thisOutput.slpToken.amount, | thisOutput.slpToken.amount, | ||||
); | ); | ||||
etokenAmount = incoming | etokenAmount = | ||||
incoming || isGenesisTx | |||||
? etokenAmount.plus(thisEtokenAmount) | ? etokenAmount.plus(thisEtokenAmount) | ||||
: etokenAmount.minus(thisEtokenAmount); | : etokenAmount.minus(thisEtokenAmount); | ||||
} catch (err) { | } catch (err) { | ||||
// edge case described above; in this case there is zero eToken value for this Cashtab recipient, so add 0 | // edge case described above; in this case there is zero eToken value for this Cashtab recipient, so add 0 | ||||
etokenAmount.plus(new BigNumber(0)); | etokenAmount.plus(new BigNumber(0)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Output amounts not at your wallet are sent amounts if !incoming | // Output amounts not at your wallet are sent amounts if !incoming | ||||
// Exception for eToken genesis transactions | |||||
if (!incoming) { | if (!incoming) { | ||||
const thisOutputAmount = new BigNumber(thisOutput.value); | const thisOutputAmount = new BigNumber(thisOutput.value); | ||||
xecAmount = xecAmount.plus(thisOutputAmount); | xecAmount = xecAmount.plus(thisOutputAmount); | ||||
if (isEtokenTx) { | if (isEtokenTx && !isGenesisTx) { | ||||
try { | try { | ||||
const thisEtokenAmount = new BigNumber( | const thisEtokenAmount = new BigNumber( | ||||
thisOutput.slpToken.amount, | thisOutput.slpToken.amount, | ||||
); | ); | ||||
etokenAmount = etokenAmount.plus(thisEtokenAmount); | etokenAmount = etokenAmount.plus(thisEtokenAmount); | ||||
} catch (err) { | } catch (err) { | ||||
// NB the edge case described above cannot exist in an outgoing tx | // NB the edge case described above cannot exist in an outgoing tx | ||||
// because the eTokens sent originated from this wallet | // because the eTokens sent originated from this wallet | ||||
▲ Show 20 Lines • Show All 114 Lines • Show Last 20 Lines |