Browse Source

print withdraw_task error 参数2

DevYK 2 năm trước cách đây
mục cha
commit
7cf171dac9
3 tập tin đã thay đổi với 70 bổ sung8 xóa
  1. 29 8
      routes/sdk.js
  2. 7 0
      test/json_test.js
  3. 34 0
      test/test.js

+ 29 - 8
routes/sdk.js

@@ -306,16 +306,31 @@ async function withdraw_task() {
                 last_time = utils.getTimestamp()
                 last_time = utils.getTimestamp()
                 logger.log('withdraw_task withdraw_ =', result, last_time)
                 logger.log('withdraw_task withdraw_ =', result, last_time)
                 if (result && moralis.getTransferCode(result) == 0) {
                 if (result && moralis.getTransferCode(result) == 0) {
-                    var obj = JSON.parse(result)
+                    var obj;
+                    var curGasPrice = 0;
+                    var curGasLimit = 0;
+                    if (typeof result === 'string') {
+                        obj = JSON.parse(result)
+                    }
                     var nonce = obj.data.nonce
                     var nonce = obj.data.nonce
-                    var curGasPrice = BigNumber(obj.data.gasPrice.hex).toNumber()
-                    var curGasLimit = BigNumber(obj.data.gasLimit.hex).toNumber()
+                    try {
+                        curGasPrice = BigNumber(obj.data.gasPrice.hex).toNumber()
+                        curGasLimit = BigNumber(obj.data.gasLimit.hex).toNumber()
+                    } catch (error) {
+                        logger.error('BigNumber toNumber error')
+                    }
+
                     var value = 0
                     var value = 0
-                    if (obj.data.chainId == 97) {
-                        value = BigNumber(obj.data.value.hex).toNumber()
-                    } else {
-                        value = obj.data.value.number
+                    try {
+                        if (obj.data.chainId == 97) {
+                            value = BigNumber(obj.data.value.hex).toNumber()
+                        } else {
+                            value = obj.data.value.number
+                        }
+                    } catch (error) {
+                        logger.error('BigNumber value toNumber error')
                     }
                     }
+
                     var hash = obj.data.hash
                     var hash = obj.data.hash
                     last_hash = hash
                     last_hash = hash
                     last_chain = temp_obj.chain
                     last_chain = temp_obj.chain
@@ -325,7 +340,11 @@ async function withdraw_task() {
                     update_obj.nonce = nonce
                     update_obj.nonce = nonce
                     update_obj.gas_price = curGasPrice.toString()
                     update_obj.gas_price = curGasPrice.toString()
                     update_obj.gas_limit = curGasLimit.toString()
                     update_obj.gas_limit = curGasLimit.toString()
-                    update_obj.value = utils.scientificNotationToString(value).toString()
+                    try {
+                        update_obj.value = utils.scientificNotationToString(value).toString()
+                    } catch (error) {
+                        logger.error('scientificNotationToString error')
+                    }
                     update_obj.errorMsg = ''
                     update_obj.errorMsg = ''
                     await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
                     await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
                     break
                     break
@@ -676,3 +695,5 @@ if (process.env.NODE_ENV == 'dev' || process.env.NODE_ENV == 'test') {
 }
 }
 
 
 module.exports = router
 module.exports = router
+
+

+ 7 - 0
test/json_test.js

@@ -0,0 +1,7 @@
+function test() {
+    var obj = ''
+    var aaa = JSON.parse(obj)
+    console.log('test', aaa)
+}
+
+test()

+ 34 - 0
test/test.js

@@ -147,5 +147,39 @@ router.post('/crypto_test', crypto_test)
 
 
 router.post('/withdraw', withdraw)
 router.post('/withdraw', withdraw)
 
 
+
+
+function test(){
+  var obj = {
+    "code": 0,
+    "data": {
+      "nonce": 497,
+      "gasPrice": {
+        "type": "BigNumber",
+        "hex": "0x012a05f200"
+      },
+      "gasLimit": {
+        "type": "BigNumber",
+        "hex": "0x8d1f"
+      },
+      "to": "0x55d398326f99059fF775485246999027B3197955",
+      "value": {
+        "type": "BigNumber",
+        "hex": "0x00"
+      },
+      "data": "0xa9059cbb000000000000000000000000270ddfa439265358896dbe5317b009f83eebdec2000000000000000000000000000000000000000000000000119ee96b60435da1",
+      "chainId": 56,
+      "v": 148,
+      "r": "0xb9597d15f01f2eae5905b27ca88c789e28a3076f4e9ac33a69353355ca1ee8f9",
+      "s": "0x375e70c6b8837474ad64475b5d487e42503cbc1d9d900fc0779d23de73dc8325",
+      "from": "0xe1fea51159E486e590E139B4BBe1Dc646Df98396",
+      "hash": "0x1e95f98c64ca5de7cf903221a11a2eda87621a29ea52a24f884844f7c7f2ca50",
+      "type": null,
+      "confirmations": 0
+    },
+    "errMsg": ""
+  }
+}
+
 module.exports = router
 module.exports = router