|
@@ -8,6 +8,7 @@ const redis = require("../model/db/redis_db") //导入 db.js
|
|
|
const withdraw_db = require("../model/db/withdraw_db") //导入 db.js
|
|
|
const report = require("../model/report") //导入 db.js
|
|
|
const BigNumber = require('bignumber.js')
|
|
|
+const czz = require('../model/czz')
|
|
|
/**
|
|
|
* 获取代币价格
|
|
|
* @param {*} ctx
|
|
@@ -150,6 +151,58 @@ async function getAllTokenWithdrawInfoLists(ctx) {
|
|
|
ctx.body = await moralis.getAllTokenWithdrawInfoLists(ctx);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+async function check_czz_withdraw_task() {
|
|
|
+ while (true) {
|
|
|
+ var exec_obj;
|
|
|
+ try {
|
|
|
+ exec_obj = await redis.redis_pop(reids_token_config.CHECK_CZZ_WITHDRAW_STATUS_QUEUE)
|
|
|
+ logger.log("check_czz_withdraw_task redis_pop",exec_obj)
|
|
|
+ if (!exec_obj) {
|
|
|
+ logger.log("没有 czz hash check")
|
|
|
+ await utils.sleep(2 * 60 * 1000)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ exec_obj = JSON.parse(exec_obj)
|
|
|
+ if (utils.getTimestamp() - exec_obj.create_time > exec_obj.lifecycle) {
|
|
|
+ logger.error('已过期 check_czz_withdraw_task :', JSON.stringify(exec_obj))
|
|
|
+ var update_obj = {}
|
|
|
+ update_obj.withdraw_status = 3
|
|
|
+ update_obj.withdraw_hash = ''
|
|
|
+ update_obj.nonce = -1
|
|
|
+ update_obj.gas_price = ''
|
|
|
+ update_obj.gas_limit = ''
|
|
|
+ update_obj.value = '0'
|
|
|
+ update_obj.errorMsg = 'czz timeout'
|
|
|
+ await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ var obj = await czz.check_withdraw_status(exec_obj)
|
|
|
+ if (obj.code == 0) {
|
|
|
+ var nonce = obj.data.nonce
|
|
|
+ var curGasPrice = obj.data.gasPrice.toString()
|
|
|
+ var curGasLimit = obj.data.gasLimit.toString()
|
|
|
+ var hash = obj.data.hash
|
|
|
+ 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 = utils.scientificNotationToString(obj.data.value).toString()
|
|
|
+ update_obj.errorMsg = ''
|
|
|
+ await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
|
|
|
+ } else {
|
|
|
+ redis.redis_push(reids_token_config.CHECK_CZZ_WITHDRAW_STATUS_QUEUE, JSON.stringify(exec_obj))
|
|
|
+ }
|
|
|
+ await utils.sleep(2 * 60 * 1000)
|
|
|
+ } catch (error) {
|
|
|
+ logger.error('check_czz_withdraw_task error', error.toString(), JSON.stringify(exec_obj))
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
async function collect_conis_task() {
|
|
|
logger.log("collect_conis_task start")
|
|
|
while (true) {
|
|
@@ -251,7 +304,7 @@ async function withdraw_task() {
|
|
|
var result = await withdraw_({ ...temp_obj })
|
|
|
last_time = utils.getTimestamp()
|
|
|
logger.log('withdraw_task withdraw_ =', result, last_time)
|
|
|
- if (result && moralis.isTransferSucceed(result)) {
|
|
|
+ if (result && moralis.getTransferCode(result) == 0) {
|
|
|
var obj = JSON.parse(result)
|
|
|
var nonce = obj.data.nonce
|
|
|
var curGasPrice = BigNumber(obj.data.gasPrice.hex).toNumber()
|
|
@@ -275,6 +328,9 @@ async function withdraw_task() {
|
|
|
update_obj.errorMsg = ''
|
|
|
await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
|
|
|
break
|
|
|
+ } else if (result && moralis.getTransferCode(result) == 1) {
|
|
|
+ moralis.pushChainDetailTOQueue(1, exec_obj, result);
|
|
|
+ break
|
|
|
} else {
|
|
|
logger.error('withdraw_task withdraw_ error=', result, JSON.stringify(temp_obj))
|
|
|
if (index < 1 + tryCount && result.includes('eth_sendRawTransaction')) {
|
|
@@ -437,7 +493,7 @@ async function withdraw_(obj) {
|
|
|
logger.log('withdraw log', log_obj);
|
|
|
return new Promise((resolve) => {
|
|
|
moralis.withdraw(obj).then((result) => {
|
|
|
- if (moralis.isTransferSucceed(result)) {
|
|
|
+ if (moralis.getTransferCode(result) == 0) {
|
|
|
//提币日志上报
|
|
|
log_obj.results = result
|
|
|
log_obj.type = report.REPORT_TYPE.withdraw
|
|
@@ -449,7 +505,6 @@ async function withdraw_(obj) {
|
|
|
var tr = moralis.getTransferGasFree('native', result)
|
|
|
log_obj.withdrawTotalGasFee = tr.totalGasFree.toString()
|
|
|
}
|
|
|
- // log_obj.receiver_address_total_balance_after = await queryCollectBalance(info.user_address, utils.getChainName(obj.chain))
|
|
|
//日志上报
|
|
|
report.logReport(log_obj)
|
|
|
}
|
|
@@ -509,7 +564,7 @@ async function getWithdrawStatus(ctx) {
|
|
|
|
|
|
async function timer_collect_conis_bsc_task() {
|
|
|
var index = 0
|
|
|
- var delay = 50 * 1000 * 60
|
|
|
+ var delay = 60 * 1000 * 60
|
|
|
while (1) {
|
|
|
var temp_obj = {
|
|
|
"chain": "bsc_testnet",
|
|
@@ -523,7 +578,7 @@ async function timer_collect_conis_bsc_task() {
|
|
|
|
|
|
async function timer_collect_conis_czz_task() {
|
|
|
var index = 0
|
|
|
- var delay = 15 * 1000 * 60
|
|
|
+ var delay = 60 * 1000 * 60
|
|
|
while (1) {
|
|
|
var temp_obj = {
|
|
|
"chain": "czz",
|
|
@@ -537,7 +592,7 @@ async function timer_collect_conis_czz_task() {
|
|
|
|
|
|
async function timer_transfer_bsc_task() {
|
|
|
var index = 0
|
|
|
- var delay = 30 * 1000 * 60
|
|
|
+ var delay = 60 * 1000 * 60
|
|
|
while (1) {
|
|
|
var obj_ = {
|
|
|
"type": "erc20",
|
|
@@ -547,7 +602,7 @@ async function timer_transfer_bsc_task() {
|
|
|
"receiver": "0x3B525c35DdC323B08241493f148340D89e3A73a7",
|
|
|
"withdrawId": index.toString()
|
|
|
}
|
|
|
- obj_.withdraw_id =utils.getCurrentDateFormat('YYYY-MM-DD-HH:mm:ss:SSS').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_)
|
|
@@ -560,7 +615,7 @@ async function timer_transfer_bsc_task() {
|
|
|
|
|
|
async function timer_transfer_czz_task() {
|
|
|
var index = 0
|
|
|
- var delay = 10 * 1000 * 60
|
|
|
+ var delay = 60 * 1000 * 60
|
|
|
while (1) {
|
|
|
var obj_ = {
|
|
|
"type": "erc20",
|
|
@@ -605,6 +660,8 @@ router.post('/getAllTokenWithdrawInfoLists', getAllTokenWithdrawInfoLists)
|
|
|
// 定时任务 提币+归集
|
|
|
withdraw_task();
|
|
|
collect_conis_task();
|
|
|
+//czz 504 检查
|
|
|
+check_czz_withdraw_task();
|
|
|
|
|
|
if (process.env.NODE_ENV == 'dev' || process.env.NODE_ENV == 'test') {
|
|
|
timer_transfer_bsc_task()
|