feat: vic init

This commit is contained in:
chaosBreaking
2019-10-23 16:20:13 +08:00
parent 6351c697da
commit 9a3dbd9375
4 changed files with 51 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
'use strict';
const { ERC20 } = require('../utils/erc20');
const { USDTAddr, startBlock } = require('./constant');
const { USDTAddr, VICAddr, startBlock, VIC_DECIMAL, USDT_DECIMAL } = require('./constant');
const getUSDTTxList = async address => {
if (!address) return null;
@@ -9,23 +9,43 @@ const getUSDTTxList = async address => {
});
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 parseUsdtTx = txList => {
const parseETHTx = txList => {
if (!txList || !Array.isArray(txList)) return [];
return txList.map(tx => {
tx.amount = (+tx.value) / 1e6;
tx.amount = (+tx.value) / VIC_DECIMAL;
return tx;
});
};
const getNewDepositTx = (usdtTx = [], fundList = []) => {
// usdt
const getNewUSDTDepositTx = (usdtTx = [], fundList = []) => {
if (fundList.length > usdtTx.length) return null;
// fundList的顺序应该与usdtTx的顺序一致所以只要截取新的
const newUsdtTxList = usdtTx.slice(fundList.length);
return parseUsdtTx(newUsdtTxList);
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
};