51 lines
1.8 KiB
JavaScript
51 lines
1.8 KiB
JavaScript
'use strict';
|
||
const { ERC20 } = require('../utils/erc20');
|
||
const { USDTAddr, VICAddr, startBlock, VIC_DECIMAL, USDT_DECIMAL } = require('./constant');
|
||
|
||
const getUSDTTxList = async address => {
|
||
if (!address) return null;
|
||
const res = await ERC20.getActions(address, USDTAddr, startBlock).catch(err => {
|
||
if (err) return [];
|
||
});
|
||
return res.filter(tx => tx.tokenName === 'Tether USD' && tx.tokenSymbol === 'USDT' && tx.to === address && tx.from !== address); //只取转入到本地址的
|
||
};
|
||
const getVICTxList = async address => {
|
||
if (!address) return null;
|
||
const res = await ERC20.getActions(address, VICAddr, startBlock).catch(err => {
|
||
if (err) return [];
|
||
});
|
||
return res.filter(tx => tx.tokenName === 'Value of Individual' && tx.tokenSymbol === 'VIC' && tx.to === address && tx.from !== address); //只取转入到本地址的
|
||
};
|
||
|
||
const parseETHTx = txList => {
|
||
if (!txList || !Array.isArray(txList)) return [];
|
||
return txList.map(tx => {
|
||
tx.amount = (+tx.value) / VIC_DECIMAL;
|
||
return tx;
|
||
});
|
||
};
|
||
// usdt
|
||
const getNewUSDTDepositTx = (usdtTx = [], fundList = []) => {
|
||
if (fundList.length > usdtTx.length) return null;
|
||
// fundList的顺序应该与usdtTx的顺序一致,所以只要截取新的
|
||
const newUsdtTxList = usdtTx.slice(fundList.length);
|
||
return parseETHTx(newUsdtTxList);
|
||
};
|
||
// vic
|
||
const getNewDepositTx = (vicTx = [], fundList = []) => {
|
||
if (fundList.length >= vicTx.length) return null;
|
||
const newList = [];
|
||
const existedFund = fundList.map(fund => fund.txHash).filter(f => f !== null);
|
||
for (let i = 0, len = vicTx.length; i < len; ++i) {
|
||
if (!existedFund.includes(vicTx[i].hash)) {
|
||
newList.push(vicTx[i]);
|
||
}
|
||
}
|
||
return parseETHTx(newList);
|
||
};
|
||
|
||
module.exports = {
|
||
getVICTxList,
|
||
getUSDTTxList,
|
||
getNewDepositTx
|
||
}; |