|
@@ -40,6 +40,32 @@ function toJson(code_, obj_, errMsg_) {
|
|
return utils.toJson(code_, obj_, errMsg_);
|
|
return utils.toJson(code_, obj_, errMsg_);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * 通过交易记录获取 gas 费用
|
|
|
|
+ * @param {} type
|
|
|
|
+ * @param {*} obj
|
|
|
|
+ * @param {*} address
|
|
|
|
+ */
|
|
|
|
+function getTransferRecordGasFree(type, obj, address) {
|
|
|
|
+ logger.log('getTransferRecordGasFree fun in', type, obj, address)
|
|
|
|
+ if (obj && obj.data && obj.data.result && Array.isArray(obj.data.result) && obj.data.result.length > 0) {
|
|
|
|
+ logger.log('getTransferRecordGasFree fun in',1)
|
|
|
|
+ for (let index = 0; index < obj.data.result.length; index++) {
|
|
|
|
+ const element = obj.data.result[index];
|
|
|
|
+ logger.log('getTransferRecordGasFree fun in 2',element)
|
|
|
|
+ if (element.type == type && element.to_address.toLowerCase() == address.toLowerCase()) {
|
|
|
|
+ if (element.gas_price && element.gas && type == 'native') {//native
|
|
|
|
+ return {
|
|
|
|
+ totalGasFree: parseInt(element.gas_price) * parseInt(element.gas),
|
|
|
|
+ gas_price: parseInt(element.gas_price)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取转账的 gas 费
|
|
* 获取转账的 gas 费
|
|
@@ -357,121 +383,6 @@ async function transfers(obj, my_account_all_coins) {
|
|
} else {
|
|
} else {
|
|
return toJson(-1, null, 'transfer conditions are not met.');
|
|
return toJson(-1, null, 'transfer conditions are not met.');
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- //v0.1 版本归集
|
|
|
|
- // var address = obj.address;
|
|
|
|
- // var chain = obj.chain;
|
|
|
|
- // var tokenPrices = obj.tokenPrices;
|
|
|
|
- // logger.log('tokenPrices=', tokenPrices, my_account_all_coins);
|
|
|
|
-
|
|
|
|
- // var nativeValue = my_account_all_coins.native.balance;
|
|
|
|
-
|
|
|
|
- // if (!my_account_all_coins || !tokenPrices) return 'error.'
|
|
|
|
-
|
|
|
|
- // logger.log(' my_account_all_coins.other.lenth=', my_account_all_coins.other.length);
|
|
|
|
-
|
|
|
|
- // var isUpdateNativeBalance = 0;
|
|
|
|
-
|
|
|
|
- // //token 归集
|
|
|
|
- // if (my_account_all_coins.other && Array.isArray(my_account_all_coins.other) && my_account_all_coins.other.length > 0) {
|
|
|
|
- // var available = Array.isArray(tokenPrices.tokenPrice) && tokenPrices.tokenPrice.length > 0
|
|
|
|
- // if (!available) return -1;
|
|
|
|
- // for (let i = 0; i < my_account_all_coins.other.length; ++i) {
|
|
|
|
- // var transfer_item = my_account_all_coins.other[i];
|
|
|
|
- // if (my_account_all_coins.other[i].token_address != null) {
|
|
|
|
- // var find_transfer_item = findTokenPriceItem(transfer_item.token_address, tokenPrices);
|
|
|
|
- // //todo 计算 token 币价格 * token美元单价
|
|
|
|
- // if (find_transfer_item && calculate_total_usdprice(transfer_item.balance, transfer_item.decimals, find_transfer_item.usdPrice) > 1.0) {
|
|
|
|
- // var info = await queryCompanyInfoFromId(0);
|
|
|
|
- // var obj_20 = {
|
|
|
|
- // chain: obj.chain,
|
|
|
|
- // contractAddress: transfer_item.token_address,
|
|
|
|
- // amount: transfer_item.balance,
|
|
|
|
- // receiver: info.user_address,
|
|
|
|
- // type: 'erc20',
|
|
|
|
- // address: address,
|
|
|
|
- // }
|
|
|
|
- // logger.log('start_collectCoins erc20:', obj_20);
|
|
|
|
- // logger.log('calculate_total_usdprice 20', calculate_total_usdprice(transfer_item.balance, transfer_item.decimals, '0.1'));
|
|
|
|
- // isUpdateNativeBalance = 1;
|
|
|
|
- // var ret = await start_collectCoins(obj_20)
|
|
|
|
- // logger.log('start_collectCoins erc20 respose...', ret);
|
|
|
|
-
|
|
|
|
- // //更新 native 金额
|
|
|
|
- // if (!isTransferSucceed(ret)) return ret;
|
|
|
|
-
|
|
|
|
- // var transfer = getTransferGasFree('token', ret)
|
|
|
|
- // if (transfer && transfer.totalGasFree > 0) {
|
|
|
|
- // logger.log('start_collectCoins 20 tempNativeValue=', my_account_all_coins.native.balance)
|
|
|
|
- // var tempNativeValue = reduceNativeValue(nativeValue, transfer.totalGasFree)
|
|
|
|
- // my_account_all_coins.native.balance = tempNativeValue.toString();
|
|
|
|
- // logger.log('start_collectCoins 20 udpateNativeValue=', tempNativeValue);
|
|
|
|
- // } else return "get native value error."
|
|
|
|
- // } else {
|
|
|
|
- // logger.error('find_transfer_item error.', transfer_item);
|
|
|
|
- // }
|
|
|
|
- // } else {
|
|
|
|
- // logger.error('token Must be greater than a dollar.', transfer_item.balance, transfer_item.decimals);
|
|
|
|
- // // return toJson(-1, null, 'token Must be greater than a dollar.');
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- // //native 归集
|
|
|
|
- // if (my_account_all_coins.native) {
|
|
|
|
- // logger.log('查询本地余额参数=', obj)
|
|
|
|
- // if (obj.chain) {
|
|
|
|
- // obj.chain = utils.getChainName(obj.chain)
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- // obj.chain = chain;
|
|
|
|
- // logger.log('查询本地余额 after', my_account_all_coins.native)
|
|
|
|
- // var find_native_item = findTokenPriceItem('0x0000000000000000000000000000000000000000', tokenPrices);
|
|
|
|
- // //todo 计算 token 币价格 * token美元单价
|
|
|
|
- // if (find_native_item) {
|
|
|
|
- // var nativeCoins = calculate_total_usdprice(my_account_all_coins.native.balance, '18', find_native_item.usdPrice);
|
|
|
|
- // logger.log('start_collectCoins nativeCoins:', nativeCoins, obj);
|
|
|
|
- // logger.log('start_collectCoins obj:', obj);
|
|
|
|
- // logger.log('start_collectCoins native.balance:', my_account_all_coins.native.balance);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // if (nativeCoins > 1.0) {
|
|
|
|
- // logger.log('native.balance', my_account_all_coins.native.balance)
|
|
|
|
- // logger.log('aGasPrice', obj.transFerGasFree.aGasPrice)
|
|
|
|
- // logger.log('gasLimint', account_config.BNB_GAS_LIMIT)
|
|
|
|
- // // var gasPrice = BigInt(obj.transFerGasFree.aGasPrice);
|
|
|
|
-
|
|
|
|
- // var gasPrice = BigInt(account_config.BNB_GAS_PRICE);
|
|
|
|
- // var gasLimit = BigInt(account_config.BNB_GAS_LIMIT);
|
|
|
|
- // var nativeBalance = BigInt(my_account_all_coins.native.balance);
|
|
|
|
-
|
|
|
|
- // logger.log('native.balance>>>', nativeBalance)
|
|
|
|
- // logger.log('aGasPrice>>>', gasPrice)
|
|
|
|
- // logger.log('gasLimint>>>', gasLimit)
|
|
|
|
-
|
|
|
|
- // var real_native_amount = nativeBalance - gasPrice * gasLimit;
|
|
|
|
- // logger.log('start_collectCoins native amount:', real_native_amount.toString());
|
|
|
|
- // var info = await queryCompanyInfoFromId(0);
|
|
|
|
- // obj = {
|
|
|
|
- // chain: chain,
|
|
|
|
- // amount: real_native_amount.toString(),
|
|
|
|
- // receiver: info.user_address,
|
|
|
|
- // type: 'native',
|
|
|
|
- // address: address,
|
|
|
|
- // }
|
|
|
|
- // logger.log('start_collectCoins native:', obj);
|
|
|
|
- // logger.log('calculate_total_usdprice native', nativeCoins, find_native_item);
|
|
|
|
- // return await start_collectCoins(obj)
|
|
|
|
- // } else {
|
|
|
|
- // logger.error('native Must be greater than a dollar.', obj);
|
|
|
|
- // return toJson(-1, null, 'native Must be greater than a dollar.');
|
|
|
|
- // }
|
|
|
|
- // } else {
|
|
|
|
- // logger.error('native Must be greater than a dollar.', obj);
|
|
|
|
- // return toJson(-1, null, 'native Must be greater than a dollar.');
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -890,6 +801,8 @@ module.exports = {
|
|
getAllTotkenPrice,
|
|
getAllTotkenPrice,
|
|
withdraw,
|
|
withdraw,
|
|
collectCoins,
|
|
collectCoins,
|
|
|
|
+ isTransferSucceed,
|
|
|
|
+ getTransferRecordGasFree,
|
|
pushCollectConisObj,
|
|
pushCollectConisObj,
|
|
}
|
|
}
|
|
|
|
|