DevYK 2 роки тому
батько
коміт
5890e01044
1 змінених файлів з 51 додано та 37 видалено
  1. 51 37
      routes/sdk.js

+ 51 - 37
routes/sdk.js

@@ -148,7 +148,7 @@ async function withdraw_task() {
                                 logger.log('等待10s');
                                 await utils.sleep(10000)
                             } else {
-                                logger.log('等待3s');
+                                logger.log('等待15s');
                                 await utils.sleep(15000)
                                 break
                             }
@@ -162,46 +162,60 @@ async function withdraw_task() {
                 } while (tryCount >= 0);
             }
         }
-        try {
-            var result = await withdraw_({ ...exec_obj })
-            last_time = utils.getTimestamp()
-            logger.log('withdraw_task=', result, last_time)
-            if (result && moralis.isTransferSucceed(result)) {
-                var obj = JSON.parse(result)
-                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 hash = obj.data.hash
-                last_hash = 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 = value.toString()
-                update_obj.errorMsg = ''
-                await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
-            } else {
-                var update_obj = {}
-                update_obj.withdraw_status = 3
-                if (typeof result === 'string') {
-                    try {
-                        result = JSON.parse(result)
-                        update_obj.errorMsg = result.errMsg
-                    } catch (error) {
-                        logger.error('withdraw_task=', result)
+
+        //如果失败重试一次
+        var tryCount = 1;
+        for (let index = 0; index < 1 + tryCount; index++) {
+            try {
+                var result = await withdraw_({ ...temp_obj })
+                last_time = utils.getTimestamp()
+                logger.log('withdraw_task withdraw_ =', result, last_time)
+                if (result && moralis.isTransferSucceed(result)) {
+                    var obj = JSON.parse(result)
+                    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 hash = obj.data.hash
+                    last_hash = 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 = value.toString()
+                    update_obj.errorMsg = ''
+                    await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
+                    break
+                } else {
+                    logger.error('withdraw_task withdraw_ error=', result,JSON.stringify(temp_obj))
+                    if (index < 1 + tryCount && result.includes('eth_sendRawTransaction')) {
+                        logger.error('try withdraw_:', JSON.stringify(temp_obj), index)
+                        await utils.sleep(3000)
+                        continue
+                    }
+                    var update_obj = {}
+                    update_obj.withdraw_status = 3
+                    if (typeof result === 'string') {
+                        try {
+                            result = JSON.parse(result)
+                            update_obj.errorMsg = result.errMsg
+                        } catch (error) {
+                            logger.error('withdraw_task=', result)
+                        }
                     }
+                    await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
+                    break
                 }
+            } catch (error) {
+                var update_obj = {}
+                update_obj.withdraw_status = 3
+                update_obj.errorMsg = error.toString()
                 await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
+                logger.error('withdraw_task error=', error.toString())
+                break
             }
-        } catch (error) {
-            var update_obj = {}
-            update_obj.withdraw_status = 3
-            update_obj.errorMsg = error.toString()
-            await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
-            logger.error('withdraw_task error=', error.toString())
         }
     }
     logger.log("withdraw_task end")