Changeset View
Changeset View
Standalone View
Standalone View
apps/ecash-herald/src/parse.ts
| Show All 16 Lines | import { | ||||
| encodeCashAddress, | encodeCashAddress, | ||||
| encodeOutputScript, | encodeOutputScript, | ||||
| getTypeAndHashFromOutputScript, | getTypeAndHashFromOutputScript, | ||||
| } from 'ecashaddrjs'; | } from 'ecashaddrjs'; | ||||
| import BigNumber from 'bignumber.js'; | import BigNumber from 'bignumber.js'; | ||||
| import { | import { | ||||
| TOKEN_SERVER_OUTPUTSCRIPT, | TOKEN_SERVER_OUTPUTSCRIPT, | ||||
| BINANCE_OUTPUTSCRIPT, | BINANCE_OUTPUTSCRIPT, | ||||
| COINEX_OUTPUTSCRIPT, | |||||
| } from '../constants/senders'; | } from '../constants/senders'; | ||||
| import { prepareStringForTelegramHTML, splitOverflowTgMsg } from './telegram'; | import { prepareStringForTelegramHTML, splitOverflowTgMsg } from './telegram'; | ||||
| import { OutputscriptInfo } from './chronik'; | import { OutputscriptInfo } from './chronik'; | ||||
| import { | import { | ||||
| formatPrice, | formatPrice, | ||||
| satsToFormattedValue, | satsToFormattedValue, | ||||
| returnAddressPreview, | returnAddressPreview, | ||||
| containsOnlyPrintableAscii, | containsOnlyPrintableAscii, | ||||
| ▲ Show 20 Lines • Show All 2,386 Lines • ▼ Show 20 Lines | ): string[] => { | ||||
| const appTxMap = new Map(); | const appTxMap = new Map(); | ||||
| let totalStakingRewardSats = 0n; | let totalStakingRewardSats = 0n; | ||||
| let cashtabXecRewardCount = 0; | let cashtabXecRewardCount = 0; | ||||
| let cashtabXecRewardSats = 0n; | let cashtabXecRewardSats = 0n; | ||||
| let cashtabCachetRewardCount = 0; | let cashtabCachetRewardCount = 0; | ||||
| let binanceWithdrawalCount = 0; | let binanceWithdrawalCount = 0; | ||||
| let binanceWithdrawalSats = 0n; | let binanceWithdrawalSats = 0n; | ||||
| let coinexWithdrawalCount = 0; | |||||
| let coinexWithdrawalSats = 0n; | |||||
| let fungibleTokenTxs = 0; | let fungibleTokenTxs = 0; | ||||
| let appTxs = 0; | let appTxs = 0; | ||||
| let unknownLokadTxs = 0; | let unknownLokadTxs = 0; | ||||
| // tokenId => {info, list, cancel, buy, adPrep, send, burn, mint, genesis: {genesisQty: <>, hasBaton: <>}} | // tokenId => {info, list, cancel, buy, adPrep, send, burn, mint, genesis: {genesisQty: <>, hasBaton: <>}} | ||||
| const tokenActions = new Map(); | const tokenActions = new Map(); | ||||
| let invalidTokenEntries = 0; | let invalidTokenEntries = 0; | ||||
| ▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | for (const tx of txs) { | ||||
| // Increment total value amount withdrawn | // Increment total value amount withdrawn | ||||
| binanceWithdrawalSats += sats; | binanceWithdrawalSats += sats; | ||||
| // We also call this a withdrawal | // We also call this a withdrawal | ||||
| // Note that 1 tx from the hot wallet may include more than 1 withdrawal | // Note that 1 tx from the hot wallet may include more than 1 withdrawal | ||||
| binanceWithdrawalCount += 1; | binanceWithdrawalCount += 1; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (senderOutputScript === COINEX_OUTPUTSCRIPT) { | |||||
| // Tx sent by CoinEx | |||||
| // Make sure it's not just a utxo consolidation | |||||
| for (const output of outputs) { | |||||
| const { sats, outputScript } = output; | |||||
| if (outputScript !== COINEX_OUTPUTSCRIPT) { | |||||
| // If we have an output that is not sending to the coinex hot wallet | |||||
| // Increment total value amount withdrawn | |||||
| coinexWithdrawalSats += sats; | |||||
| // We also call this a withdrawal | |||||
| // Note that 1 tx from the hot wallet may include more than 1 withdrawal | |||||
| coinexWithdrawalCount += 1; | |||||
| } | |||||
| } | |||||
| } | |||||
| // Other token actions | // Other token actions | ||||
| if (tokenEntries.length > 0) { | if (tokenEntries.length > 0) { | ||||
| for (const tokenEntry of tokenEntries) { | for (const tokenEntry of tokenEntries) { | ||||
| // Get the tokenId | // Get the tokenId | ||||
| // Note that groupTokenId is only defined for NFT child | // Note that groupTokenId is only defined for NFT child | ||||
| const { | const { | ||||
| tokenId, | tokenId, | ||||
| ▲ Show 20 Lines • Show All 1,448 Lines • ▼ Show 20 Lines | if (binanceWithdrawalCount > 0) { | ||||
| tgMsg.push(`${config.emojis.bank} <b><i>Binance</i></b>`); | tgMsg.push(`${config.emojis.bank} <b><i>Binance</i></b>`); | ||||
| tgMsg.push( | tgMsg.push( | ||||
| `<b>${binanceWithdrawalCount}</b> withdrawal${ | `<b>${binanceWithdrawalCount}</b> withdrawal${ | ||||
| binanceWithdrawalCount > 1 ? 's' : '' | binanceWithdrawalCount > 1 ? 's' : '' | ||||
| }, ${renderedBinanceWithdrawalQty}`, | }, ${renderedBinanceWithdrawalQty}`, | ||||
| ); | ); | ||||
| } | } | ||||
| if (coinexWithdrawalCount > 0) { | |||||
| // CoinEx hot wallet | |||||
| const renderedCoinexWithdrawalQty = satsToFormattedValue( | |||||
| coinexWithdrawalSats, | |||||
| xecPriceUsd, | |||||
| ); | |||||
| tgMsg.push(`${config.emojis.bank} <b><i>CoinEx</i></b>`); | |||||
| tgMsg.push( | |||||
| `<b>${coinexWithdrawalCount}</b> withdrawal${ | |||||
| coinexWithdrawalCount > 1 ? 's' : '' | |||||
| }, ${renderedCoinexWithdrawalQty}`, | |||||
| ); | |||||
| } | |||||
| return splitOverflowTgMsg(tgMsg); | return splitOverflowTgMsg(tgMsg); | ||||
| }; | }; | ||||
| interface ParsedStaker { | interface ParsedStaker { | ||||
| /** | /** | ||||
| * Odds of this staker winning a given block | * Odds of this staker winning a given block | ||||
| * Formatted as a string for pressentation | * Formatted as a string for pressentation | ||||
| * e.g. 17% | * e.g. 17% | ||||
| ▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines | |||||