DevYK 3 лет назад
Родитель
Сommit
ceb6937b6b
3 измененных файлов с 29 добавлено и 22 удалено
  1. 10 10
      config/dev_config.js
  2. 15 8
      model/moralis_sdk.js
  3. 4 4
      model/redis_db.js

+ 10 - 10
config/dev_config.js

@@ -44,19 +44,19 @@ const db_config = {
         HOST: 'denet-test.csi2lctklqzg.us-east-1.rds.amazonaws.com' //host
     },
 
-    redis: {
-        PORT: 6379, // Redis port
-        HOST: "r-bp1ps6my7lzg8rdhwxpi.redis.rds.aliyuncs.com", // Redis host
-        USERNAME: null,
-        PASSWORD: "Wqsd@2019"
-    },
-
     // redis: {
     //     PORT: 6379, // Redis port
-    //     HOST: "denet-test.y2slbl.clustercfg.memorydb.us-east-1.amazonaws.com", // Redis host
-    //     USERNAME: null, // needs Redis >= 6
-    //     PASSWORD: null,
+    //     HOST: "r-bp1ps6my7lzg8rdhwxpi.redis.rds.aliyuncs.com", // Redis host
+    //     USERNAME: null,
+    //     PASSWORD: "Wqsd@2019"
     // },
+
+    redis: {
+        PORT: 6379, // Redis port
+        HOST: "denet-test.y2slbl.clustercfg.memorydb.us-east-1.amazonaws.com", // Redis host
+        USERNAME: null, // needs Redis >= 6
+        PASSWORD: null,
+    },
 }
 
 // 设置 moralis sdk 配置文件

+ 15 - 8
model/moralis_sdk.js

@@ -234,7 +234,8 @@ async function computeTransferGasFree(obj, my_account_all_coins, tokenPrices) {
             }
             ret_a_gas = account_config.BNB_GAS_PRICE;
 
-            var real_native_amount = BigInt(nativeAllBalance) - BigInt(nativeGasPrice) - BigInt(tokenGasPrice);
+            // var real_native_amount = BigInt(nativeAllBalance) - BigInt(nativeGasPrice) - BigInt(tokenGasPrice);
+            var real_native_amount = BigInt(nativeAllBalance);
             var obj_native = {
                 chain: obj.chain,
                 amount: real_native_amount.toString(),
@@ -342,12 +343,11 @@ async function transfers(obj, my_account_all_coins) {
                 t_i += 1
             } else {
                 logger.tlog('start_collectCoins  error=', ret);
-                t_err.push(ret)
             };
         }
-        if(t_i == my_account_all_coins.transfer_arrays.length){
+        if (t_i == my_account_all_coins.transfer_arrays.length) {
             return toJson(0, null, '所有币归集成功.');
-        }else {
+        } else {
             return toJson(-1, null, '归集失败.');
         }
     } else {
@@ -555,10 +555,17 @@ const collectCoins = async (obj) => {
     var my_account_all_coins = await getAccountAllCoins(obj);
 
     //得到币价格
-    obj.tokenPrices = await redis.readRedis(reids_token_config.TOKENPRICE)
-    if (!obj.tokenPrices) return 'readRedis error'
-    if (typeof obj.tokenPrices == 'string')
-        obj.tokenPrices = JSON.parse(obj.tokenPrices);
+    if (process.env.NODE_ENV == 'dev') {
+        var test_json = '{"tokenPrice": [{"contract": "0x0000000000000000000000000000000000000000", "usdPrice": 400}, {"contract": "0x03716F32f72c692a0B355fa04639669E3341B94e", "usdPrice": 0.1}]}'
+        obj.tokenPrices = JSON.parse(test_json);
+        logger.log('dev tokenPrices=', obj.tokenPrices)
+    } else {
+        obj.tokenPrices = await redis.readRedis(reids_token_config.TOKENPRICE)
+        if (!obj.tokenPrices) return 'readRedis error'
+        if (typeof obj.tokenPrices == 'string')
+            obj.tokenPrices = JSON.parse(obj.tokenPrices);
+    }
+
 
     obj.chain = chain;
     //计算 gas 费用 是否需要归集

+ 4 - 4
model/redis_db.js

@@ -26,12 +26,12 @@ if (process.env.NODE_ENV == 'test') {
   opts = {
     port: port,
     host: host,
-    password: password
+    // password: password
   }
   // var new_opts = "redis://"+password+"@"+host+":"+port+"/0"
   // "redis://:authpassword@127.0.0.1:6380/4"
-  REDIS_INSTANCE = new Redis(opts);
-  // REDIS_INSTANCE = new Redis.Cluster([opts]);
+  // REDIS_INSTANCE = new Redis(opts);
+  REDIS_INSTANCE = new Redis.Cluster([opts]);
   // REDIS_INSTANCE=new Redis.Cluster([opts]);
 } else if (process.env.NODE_ENV == 'prd') {
   opts = {
@@ -43,7 +43,7 @@ if (process.env.NODE_ENV == 'test') {
 }
 
 REDIS_INSTANCE.on('connect', () => {
-  logger.log('connected to redis',opts)
+  logger.log('connected to redis')
 })
 
 REDIS_INSTANCE.on('error', function (err) {