Files
vic-server-mongo/src/common/deposit.js
chaosBreaking 9a3dbd9375 feat: vic init
2019-10-23 16:20:13 +08:00

51 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'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
};