|
@@ -14,7 +14,15 @@ const BigNumber = require('bignumber.js')
|
|
|
*/
|
|
|
async function getAllTotkenPrice(ctx) {
|
|
|
console.log('getTotkenPrice in:')
|
|
|
- var ret = await moralis.getAllTotkenPrice()
|
|
|
+ var ret = await moralis.getAllTotkenPrice(ctx.request.body)
|
|
|
+ console.log('getTotkenPrice result:', ret)
|
|
|
+ if (ret)
|
|
|
+ ctx.body = utils.toJson(0, ret, null);
|
|
|
+ else ctx.body = utils.toJson(-1, null, "redis read error.");
|
|
|
+}
|
|
|
+
|
|
|
+async function getAllTokenPrice(ctx) {
|
|
|
+ var ret = await moralis.getAllTotkenPrice(ctx.request.body)
|
|
|
console.log('getTotkenPrice result:', ret)
|
|
|
if (ret)
|
|
|
ctx.body = utils.toJson(0, ret, null);
|
|
@@ -52,8 +60,10 @@ async function getTransfers(ctx) {
|
|
|
logger.log('getTransferRecordGasFree:', tr, temp_obj.address)
|
|
|
if (tr && tr.totalGasFree > 0) {
|
|
|
logger.log('getTransferRecordGasFree redis_set LAST_PRICE:', tr)
|
|
|
- redis.redis_set(reids_token_config.LAST_BNB_PRICE, tr.gas_price.toString());
|
|
|
- redis.redis_set(reids_token_config.LAST_TOKEN_PRICE, tr.gas_price.toString());
|
|
|
+ // redis.redis_set(reids_token_config.LAST_BNB_PRICE, tr.gas_price.toString());
|
|
|
+ // redis.redis_set(reids_token_config.LAST_TOKEN_PRICE, tr.gas_price.toString());
|
|
|
+ redis.writeAppendRedis(reids_token_config.LAST_BNB_PRICE, temp_obj.chain, '', tr.gas_price.toString());
|
|
|
+ redis.writeAppendRedis(reids_token_config.LAST_TOKEN_PRICE, temp_obj.chain, '', tr.gas_price.toString());
|
|
|
}
|
|
|
if (json_obj.data.total > 0) {
|
|
|
//提交归集任务
|
|
@@ -110,8 +120,10 @@ async function getTransfersV2(ctx) {
|
|
|
logger.log('getTransferRecordGasFree:', tr, temp_obj.address)
|
|
|
if (tr && tr.totalGasFree > 0) {
|
|
|
logger.log('getTransferRecordGasFree redis_set LAST_TOTAL_BNB_FREE:', tr)
|
|
|
- redis.redis_set(reids_token_config.LAST_BNB_PRICE, tr.gas_price.toString());
|
|
|
- redis.redis_set(reids_token_config.LAST_TOKEN_PRICE, tr.gas_price.toString().toString());
|
|
|
+ // redis.redis_set(reids_token_config.LAST_BNB_PRICE, tr.gas_price.toString());
|
|
|
+ // redis.redis_set(reids_token_config.LAST_TOKEN_PRICE, tr.gas_price.toString().toString());
|
|
|
+ redis.writeAppendRedis(reids_token_config.LAST_BNB_PRICE, temp_obj.chain, '', tr.gas_price.toString());
|
|
|
+ redis.writeAppendRedis(reids_token_config.LAST_TOKEN_PRICE, temp_obj.chain, '', tr.gas_price.toString());
|
|
|
}
|
|
|
|
|
|
if (json_obj.data.total > 0) {
|
|
@@ -174,11 +186,12 @@ async function withdraw_task() {
|
|
|
logger.log("withdraw_task start")
|
|
|
let last_time = 0
|
|
|
let last_hash = ''
|
|
|
+ let last_chain = ''
|
|
|
|
|
|
while (true) {
|
|
|
var exec_obj = await redis.redis_pop(reids_token_config.WITHDRAW_QUEUE_KEY)
|
|
|
if (!exec_obj) {
|
|
|
- await utils.sleep(60000)
|
|
|
+ await utils.sleep(10000)
|
|
|
logger.log("没有出金任务")
|
|
|
continue
|
|
|
}
|
|
@@ -194,21 +207,22 @@ async function withdraw_task() {
|
|
|
//有可能上一个区块还未更新,这里做一个尝试限制
|
|
|
//Error: Failed to make "eth_sendRawTransaction" request with networkConnector: "already known"
|
|
|
//通过 交易 hash 获取块。last_hash
|
|
|
- if (last_hash) {
|
|
|
+ if (last_hash && last_chain) {
|
|
|
var options = {
|
|
|
transaction_hash: last_hash,
|
|
|
- chain: temp_obj.chain,
|
|
|
+ chain: last_chain,
|
|
|
endTime: '2099-01-01'
|
|
|
}
|
|
|
- var tryCount = 10;
|
|
|
+ var tryCount = 3;
|
|
|
do {
|
|
|
try {
|
|
|
//通过获取上一个交易记录来进行确认
|
|
|
- var transaction = await moralis.getTokenTransfers(options);
|
|
|
+ var transaction = await moralis.getTokenTransfersV2(options);
|
|
|
logger.log('withdraw_task exectransaction', transaction, options, tryCount);
|
|
|
- transaction = JSON.parse(transaction)
|
|
|
+ if (typeof transaction === 'string')
|
|
|
+ transaction = JSON.parse(transaction)
|
|
|
if (transaction.code == 0) {
|
|
|
- if (transaction.data.result.length <= 0) {
|
|
|
+ if (transaction.data.results.length <= 0) {
|
|
|
logger.log('等待10s');
|
|
|
await utils.sleep(10000)
|
|
|
} else {
|
|
@@ -221,7 +235,10 @@ async function withdraw_task() {
|
|
|
}
|
|
|
tryCount -= 1
|
|
|
} catch (error) {
|
|
|
- logger.error('withdraw_task exectransaction', error.toString());
|
|
|
+ logger.error('withdraw_task exectransaction err', error.toString());
|
|
|
+ }
|
|
|
+ if (tryCount < 0) {
|
|
|
+ logger.error('withdraw_task getTokenTransfersV2 警告交易未更新:', JSON.stringify(options));
|
|
|
}
|
|
|
} while (tryCount >= 0);
|
|
|
}
|
|
@@ -239,16 +256,22 @@ async function withdraw_task() {
|
|
|
var nonce = obj.data.nonce
|
|
|
var curGasPrice = BigNumber(obj.data.gasPrice.hex).toNumber()
|
|
|
var curGasLimit = BigNumber(obj.data.gasLimit.hex).toNumber()
|
|
|
- var value = BigNumber(obj.data.value.hex).toNumber()
|
|
|
+ var value = 0
|
|
|
+ if (obj.data.chainId == 97) {
|
|
|
+ value = BigNumber(obj.data.value.hex).toNumber()
|
|
|
+ } else {
|
|
|
+ value = obj.data.value.number
|
|
|
+ }
|
|
|
var hash = obj.data.hash
|
|
|
last_hash = hash
|
|
|
+ last_chain = temp_obj.chain
|
|
|
var update_obj = {}
|
|
|
update_obj.withdraw_status = 2
|
|
|
update_obj.withdraw_hash = hash
|
|
|
update_obj.nonce = nonce
|
|
|
update_obj.gas_price = curGasPrice.toString()
|
|
|
update_obj.gas_limit = curGasLimit.toString()
|
|
|
- update_obj.value = value.toString()
|
|
|
+ update_obj.value = utils.scientificNotationToString(value).toString()
|
|
|
update_obj.errorMsg = ''
|
|
|
await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
|
|
|
break
|
|
@@ -484,9 +507,38 @@ async function getWithdrawStatus(ctx) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-async function timer_transfer_task() {
|
|
|
+
|
|
|
+async function timer_collect_conis_bsc_task() {
|
|
|
+ var index = 0
|
|
|
+ var delay = 50 * 1000 * 60
|
|
|
+ while (1) {
|
|
|
+ var temp_obj = {
|
|
|
+ "chain": "bsc_testnet",
|
|
|
+ "address": "0x3B525c35DdC323B08241493f148340D89e3A73a7"
|
|
|
+ }
|
|
|
+ redis.redis_push(reids_token_config.COLLECT_CONIS_QUEUE_KEY, JSON.stringify(temp_obj))
|
|
|
+ await utils.sleep(delay)
|
|
|
+ index += 1
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function timer_collect_conis_czz_task() {
|
|
|
+ var index = 0
|
|
|
+ var delay = 46 * 1000 * 60
|
|
|
+ while (1) {
|
|
|
+ var temp_obj = {
|
|
|
+ "chain": "czz",
|
|
|
+ "address": "0x39ACD9CC975D792D8160215Dc84fa00E4934F076",
|
|
|
+ }
|
|
|
+ redis.redis_push(reids_token_config.COLLECT_CONIS_QUEUE_KEY, JSON.stringify(temp_obj))
|
|
|
+ await utils.sleep(delay)
|
|
|
+ index += 1
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function timer_transfer_bsc_task() {
|
|
|
var index = 0
|
|
|
- var delay = 60 * 1000 * 60
|
|
|
+ var delay = 30 * 1000 * 60
|
|
|
while (1) {
|
|
|
var obj_ = {
|
|
|
"type": "erc20",
|
|
@@ -496,7 +548,7 @@ async function timer_transfer_task() {
|
|
|
"receiver": "0x3B525c35DdC323B08241493f148340D89e3A73a7",
|
|
|
"withdrawId": index.toString()
|
|
|
}
|
|
|
- obj_.withdraw_id = utils.getTimestamp().toString();
|
|
|
+ obj_.withdraw_id =utils.getCurrentDateFormat('YYYY-MM-DD-HH:mm:ss:SSS').toString()
|
|
|
var info = await moralis.queryCompanyInfoFromId(0);
|
|
|
obj_.user_address = info.user_address
|
|
|
await withdraw_db.create_withdraw_task(obj_)
|
|
@@ -507,11 +559,33 @@ async function timer_transfer_task() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+async function timer_transfer_czz_task() {
|
|
|
+ var index = 0
|
|
|
+ var delay = 40 * 1000 * 60
|
|
|
+ while (1) {
|
|
|
+ var obj_ = {
|
|
|
+ "type": "token",
|
|
|
+ "contractAddress": "0xfb16179d5e84b0e3e7524ed61a9cf7b98d039b20",
|
|
|
+ "amount": "323000000000000000000",
|
|
|
+ "chain": "czz",
|
|
|
+ "receiver": "0x39ACD9CC975D792D8160215Dc84fa00E4934F076"
|
|
|
+ }
|
|
|
+ obj_.withdraw_id = utils.getCurrentDateFormat('YYYY-MM-DD-HH:mm:ss:SSS').toString()
|
|
|
+ var info = await moralis.queryCompanyInfoFromId(0);
|
|
|
+ obj_.user_address = info.user_address
|
|
|
+ await withdraw_db.create_withdraw_task(obj_)
|
|
|
+ redis.redis_push(reids_token_config.WITHDRAW_QUEUE_KEY, JSON.stringify(obj_))
|
|
|
+ await utils.sleep(delay)
|
|
|
+ index += 1
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
//获取交易记录
|
|
|
router.post('/getTransfers', getTransfers)
|
|
|
router.post('/getTransfersV2', getTransfersV2)
|
|
|
// 获取所有代币价格
|
|
|
router.post('/getAllTotkenPrice', getAllTotkenPrice)
|
|
|
+router.post('/getAllTokenPrice', getAllTokenPrice)
|
|
|
|
|
|
// router.post('/transfer', transfer)
|
|
|
//提现
|
|
@@ -533,7 +607,11 @@ router.post('/getAllTokenWithdrawInfoLists', getAllTokenWithdrawInfoLists)
|
|
|
withdraw_task();
|
|
|
collect_conis_task();
|
|
|
|
|
|
-if (process.env.NODE_ENV == 'dev' || process.env.NODE_ENV == 'test')
|
|
|
- timer_transfer_task()
|
|
|
+if (process.env.NODE_ENV == 'dev' || process.env.NODE_ENV == 'test') {
|
|
|
+ timer_transfer_bsc_task()
|
|
|
+ timer_transfer_czz_task()
|
|
|
+ timer_collect_conis_bsc_task()
|
|
|
+ timer_collect_conis_czz_task()
|
|
|
+}
|
|
|
|
|
|
module.exports = router
|