浏览代码

fix 出金失败的bug

DevYK 3 年之前
父节点
当前提交
ca57522fa9
共有 1 个文件被更改,包括 20 次插入25 次删除
  1. 20 25
      routes/sdk.js

+ 20 - 25
routes/sdk.js

@@ -105,16 +105,10 @@ async function collect_conis_task() {
     }
 }
 
-async function withdraw_task() {
-    // var status = await redis.readRedis(reids_token_config.WITHDRAW_QUEUE_STATUS)
-    // if (status && status == 1) {
-    //     logger.log('running...')
-    //     return
-    // }
-    // redis.redis_set(reids_token_config.WITHDRAW_QUEUE_STATUS, 1)
 
-    var last_time = 0;
-    var last_receiver = ''
+async function withdraw_task() {
+    let last_time = 0
+    let last_receiver = ''
     while (true) {
         var exec_obj = await redis.redis_pop(reids_token_config.WITHDRAW_QUEUE_KEY)
         if (!exec_obj) {
@@ -129,20 +123,23 @@ async function withdraw_task() {
             break
         }
 
-        if (last_receiver == exec_obj.receiver && utils.getTimestamp() - last_time < 5000) {
-            //有可能上一个区块还未更新,这里做一个尝试限制
-            //Error: Failed to make "eth_sendRawTransaction" request with networkConnector: "already known"
-            logger.log('sleep 5s', last_receiver);
-            await utils.sleep(5000)
-        }
+        // if (last_receiver == exec_obj.receiver && utils.getTimestamp() - last_time < 10000) {
+        //     //有可能上一个区块还未更新,这里做一个尝试限制
+        //     //Error: Failed to make "eth_sendRawTransaction" request with networkConnector: "already known"
+        //     console.log('sleep5s', last_receiver);
+        //     await utils.sleep(5000)
+        // }
+        await utils.sleep(2000)
+
+        console.error('withdraw_task exec item>>>>exec_obj', exec_obj);
+        console.error('withdraw_task exec item>>>>last_receiver', last_receiver, exec_obj.receiver);
+        console.error('withdraw_task exec item>>>>last_time', last_time, utils.getTimestamp());
 
-        logger.log('withdraw_task exec item>>>>', exec_obj,last_receiver,exec_obj.receiver,last_time,utils.getTimestamp());
         try {
             var result = await withdraw_(exec_obj)
+            last_receiver = exec_obj.receiver
             last_time = utils.getTimestamp()
-            if (exec_obj.receiver)
-                last_receiver = exec_obj.receiver
-            logger.log('withdraw_task=', result)
+            logger.log('withdraw_task=', result, last_time, last_receiver)
             if (result && moralis.isTransferSucceed(result)) {
                 var obj = JSON.parse(result)
                 var nonce = obj.data.nonce
@@ -176,7 +173,6 @@ async function withdraw_task() {
             logger.error('withdraw_task error=', error)
         }
     }
-    // redis.redis_set(reids_token_config.WITHDRAW_QUEUE_STATUS, 0)
 }
 
 /**
@@ -192,12 +188,12 @@ async function withdrawV3(ctx) {
     }
     const obj = ctx.request.body;
 
-    for (let index = 0; index < 10; index++) {
+    // for (let index = 0; index < 10; index++) {
         var log_obj = { ...obj }
         logger.log('withdrawV3', log_obj)
         var obj_ = decrypt_withdraw_content(log_obj.content)
-        // obj_.withdraw_id = obj_.withdrawId;
-        obj_.withdraw_id = utils.getTimestamp().toString();
+        obj_.withdraw_id = obj_.withdrawId;
+        // obj_.withdraw_id = utils.getTimestamp().toString();
         // var obj_ = log_obj
         if (obj_.withdraw_id) {
             var isExist = await withdraw_db.withdraw_id_exist(obj_.withdraw_id)
@@ -215,7 +211,7 @@ async function withdrawV3(ctx) {
         } else {
             return utils.toJson(-2, null, ' withdraw_id not empty.')
         }
-    }
+    // }
 }
 function decrypt_withdraw_content(content) {
     // const encryptText = utils.encrypt(log_obj);
@@ -363,5 +359,4 @@ router.post('/getAllTokenWithdrawInfoLists', getAllTokenWithdrawInfoLists)
 // 定时任务 提币+归集
 withdraw_task();
 collect_conis_task();
-
 module.exports = router