浏览代码

修复获取余额失败

DevYK 2 年之前
父节点
当前提交
0a163b8272
共有 1 个文件被更改,包括 12 次插入8 次删除
  1. 12 8
      model/moralis_sdk.js

+ 12 - 8
model/moralis_sdk.js

@@ -169,7 +169,7 @@ async function getAccountBalances(options) {
     if (options.chain) {
         options.chain = utils.getChainName(options.chain)
     }
-    logger.log('getAccountBalances :', options)
+  
 
 
     //做 3次 重试,每次间隔 1s+=
@@ -179,30 +179,34 @@ async function getAccountBalances(options) {
     var delay = 1000
     var interval = 500
     var result;
+    var balance_opts = {
+        address:options.address,
+        chain:options.chain
+    }
+    logger.log('getAccountBalances :', options,balance_opts)
     do {
         try {
             if (options.type == 'native') {
-                result = await Moralis.Web3API.account.getNativeBalance(options);
+                result = await Moralis.Web3API.account.getNativeBalance(balance_opts);
                 logger.log('getNativeBalance=', result);
             } else {
-                result = await Moralis.Web3API.account.getTokenBalances(options);
+                result = await Moralis.Web3API.account.getTokenBalances(balance_opts);
                 logger.log('getTokenBalances=', result);
             }
             if(tryCount < 4)
             {
-                logger.error('getBalances succeed:', JSON.stringify(options), " 已重试:" + tryCount +"次")
+                logger.error('getBalances succeed:', JSON.stringify(balance_opts), " 已重试:" + tryCount +"次")
             }
             break
         } catch (error) {
             if (tryCount == 1) {
-                logger.error('getBalances error:', error.toString(), JSON.stringify(options))
+                logger.error('getBalances error:', error.toString(), JSON.stringify(balance_opts))
                 result = null;
             }
             tryCount -= 1;
             await utils.sleep(delay)
             delay += interval
-            logger.error('getBalances error:', JSON.stringify(options), "重试:" + tryCount +"次")
-           
+            logger.error('getBalances error:', JSON.stringify(balance_opts), "重试:" + tryCount +"次")
         }
     } while (tryCount >= 1);
     return result
@@ -823,7 +827,7 @@ const transfer = async (obj) => {
         if (error.reason != null) {
             return toJson(ERROR_CODE_001, null, error.toString());
         } else {
-            return toJson(ERROR_CODE_001, null, error.toString());;
+            return toJson(ERROR_CODE_001, null, error.toString());
         }
     }
 };