|
@@ -215,9 +215,6 @@ async function getAccountBalances(options) {
|
|
|
if (options.chain) {
|
|
|
options.chain = utils.getChainName(options.chain)
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
//做 3次 重试,每次间隔 1s+=
|
|
|
//Error: Request failed with status code 524
|
|
|
//Error: Request failed with status code 500
|
|
@@ -234,10 +231,10 @@ async function getAccountBalances(options) {
|
|
|
try {
|
|
|
if (options.type == 'native') {
|
|
|
// result = await Moralis.Web3API.account.getNativeBalance(balance_opts);
|
|
|
- result = await getBalances(balance_opts, 'native')
|
|
|
+ result = await getBalances(balance_opts, 'native', 1)
|
|
|
logger.log('getNativeBalance=', result);
|
|
|
} else {
|
|
|
- result = await getBalances(balance_opts, 'token')
|
|
|
+ result = await getBalances(balance_opts, 'token', 1)
|
|
|
// result = await Moralis.Web3API.account.getTokenBalances(balance_opts);
|
|
|
logger.log('getTokenBalances=', result);
|
|
|
}
|
|
@@ -246,8 +243,19 @@ async function getAccountBalances(options) {
|
|
|
}
|
|
|
break
|
|
|
} catch (error) {
|
|
|
+ logger.error('getBalances error:', error.toString(), JSON.stringify(balance_opts), JSON.stringify(options))
|
|
|
if (tryCount == 1) {
|
|
|
- logger.error('getBalances error:', error.toString(), JSON.stringify(balance_opts), JSON.stringify(options))
|
|
|
+ try {
|
|
|
+ result = await getBalances(balance_opts, options.type, 0)
|
|
|
+ if (result != null) {
|
|
|
+ logger.error('sync-node-getBalances success', JSON.stringify(balance_opts), options.type)
|
|
|
+ break
|
|
|
+ } else {
|
|
|
+ logger.error('sync-node-getBalances error', JSON.stringify(balance_opts), options.type)
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ logger.error('getBalances error:', error.toString(), JSON.stringify(balance_opts), JSON.stringify(options))
|
|
|
+ }
|
|
|
result = null;
|
|
|
break
|
|
|
}
|
|
@@ -482,7 +490,7 @@ async function updateNativeBalance(nativeBalance, obj) {
|
|
|
do {
|
|
|
//上面转账完 BNB 会减去,这里再获取一次
|
|
|
// var native_ret = await Moralis.Web3API.account.getNativeBalance(temp);
|
|
|
- var native_ret = await getBalances(balance_opts, 'native');
|
|
|
+ var native_ret = await getBalances(balance_opts, 'native', 1);
|
|
|
logger.log('更新余额 :', nativeBalance, native_ret, retryCount)
|
|
|
if (nativeBalance != native_ret.balance && BigInt(nativeBalance) < BigInt(native_ret.balance)) {
|
|
|
return native_ret.balance;
|
|
@@ -1348,7 +1356,7 @@ async function getTransferRecord(opts, type, use_moralis_sdk_) {
|
|
|
gas_price: element.gas_price,
|
|
|
block_timestamp: element.block_timestamp,
|
|
|
trx_hash: element.hash,
|
|
|
- responseType:'moralis'
|
|
|
+ responseType: 'moralis'
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -1366,7 +1374,7 @@ async function getTransferRecord(opts, type, use_moralis_sdk_) {
|
|
|
value: element.value,
|
|
|
block_timestamp: element.block_timestamp,
|
|
|
trx_hash: element.transaction_hash,
|
|
|
- responseType:'moralis'
|
|
|
+ responseType: 'moralis'
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -1384,7 +1392,7 @@ async function getTransferRecord(opts, type, use_moralis_sdk_) {
|
|
|
gas_price: ret.gas_price,
|
|
|
block_timestamp: ret.block_timestamp,
|
|
|
trx_hash: ret.hash,
|
|
|
- responseType:'moralis'
|
|
|
+ responseType: 'moralis'
|
|
|
})
|
|
|
}
|
|
|
return {
|
|
@@ -1413,10 +1421,10 @@ async function getTransferRecord(opts, type, use_moralis_sdk_) {
|
|
|
* 获取 token or native 余额
|
|
|
* @param {*} opts
|
|
|
*/
|
|
|
-async function getBalances(opts, type) {
|
|
|
+async function getBalances(opts, type, use_moralis_sdk_) {
|
|
|
logger.info('getBalances>>>>>>>>', opts, type)
|
|
|
//是否使用 moralis sdk 进行查询
|
|
|
- var use_moralis_sdk = 1
|
|
|
+ var use_moralis_sdk = use_moralis_sdk_
|
|
|
var temp_opts = { ...opts }
|
|
|
if (use_moralis_sdk) {
|
|
|
if (type == 'native') {
|
|
@@ -1425,7 +1433,17 @@ async function getBalances(opts, type) {
|
|
|
return await Moralis.Web3API.account.getTokenBalances(temp_opts);
|
|
|
}
|
|
|
} else {
|
|
|
-
|
|
|
+ if (type == 'native') {
|
|
|
+ temp_opts.type = 'native'
|
|
|
+ var ret = await account_mysql.getAccountBalances(temp_opts)
|
|
|
+ if (ret) {
|
|
|
+ return ret.results[0]
|
|
|
+ }
|
|
|
+ } else if (type == 'token') {
|
|
|
+ temp_opts.type = 'token'
|
|
|
+ var ret = await account_mysql.getAccountBalances(temp_opts)
|
|
|
+ return ret.results
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|