sdk.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. var router = require('koa-router')();
  2. var moralis = require('../model/moralis_sdk.js')
  3. var utils = require('../model/utils.js');
  4. var { reids_token_config, account_config } = require('../config/config.js');
  5. const logger = require('../model/logger.js');
  6. router.prefix('/sdk');
  7. const redis = require("../model/db/redis_db") //导入 db.js
  8. const withdraw_db = require("../model/db/withdraw_db") //导入 db.js
  9. const report = require("../model/report") //导入 db.js
  10. const BigNumber = require('bignumber.js')
  11. /**
  12. * 获取代币价格
  13. * @param {*} ctx
  14. */
  15. async function getAllTotkenPrice(ctx) {
  16. console.log('getTotkenPrice in:')
  17. var ret = await moralis.getAllTotkenPrice(ctx.request.body)
  18. console.log('getTotkenPrice result:', ret)
  19. if (ret)
  20. ctx.body = utils.toJson(0, ret, null);
  21. else ctx.body = utils.toJson(-1, null, "redis read error.");
  22. }
  23. async function getAllTokenPrice(ctx) {
  24. var ret = await moralis.getAllTotkenPrice(ctx.request.body)
  25. console.log('getTotkenPrice result:', ret)
  26. if (ret)
  27. ctx.body = utils.toJson(0, ret, null);
  28. else ctx.body = utils.toJson(-1, null, "redis read error.");
  29. }
  30. /**
  31. * 获取交易记录
  32. * @param {*} ctx
  33. */
  34. async function getTransfers(ctx) {
  35. const obj = ctx.request.body;
  36. console.log("getTransfers body", obj);
  37. if (!obj.chain)//默认 bsc 币安链
  38. obj.chain = 'bsc_mainnet'
  39. var temp_obj = { ...obj }
  40. var index = 0
  41. await moralis.getTokenTransfers(obj).then((result) => {
  42. logger.log('getTransfers response', 'index=' + index, result)
  43. ctx.body = result;
  44. if (result) {
  45. //提交归集任务 native 能获取到 gas 、token 无法获取到 gas 费
  46. try {
  47. if (temp_obj.address && moralis.isTransferSucceed(result)) {
  48. var log_obj = { ...obj }
  49. log_obj.results = result
  50. log_obj.type = report.REPORT_TYPE.transfer_record
  51. //埋点日志上报-入金检查
  52. report.logReport(log_obj)
  53. var json_obj = JSON.parse(result);
  54. //缓存当前交易的 gas 费用
  55. var tr = moralis.getTransferRecordGasFree('native', json_obj, temp_obj.address)
  56. logger.log('getTransferRecordGasFree:', tr, temp_obj.address)
  57. if (tr && tr.totalGasFree > 0) {
  58. logger.log('getTransferRecordGasFree redis_set LAST_PRICE:', tr)
  59. // redis.redis_set(reids_token_config.LAST_BNB_PRICE, tr.gas_price.toString());
  60. // redis.redis_set(reids_token_config.LAST_TOKEN_PRICE, tr.gas_price.toString());
  61. redis.writeAppendRedis(reids_token_config.LAST_BNB_PRICE, temp_obj.chain, '', tr.gas_price.toString());
  62. redis.writeAppendRedis(reids_token_config.LAST_TOKEN_PRICE, temp_obj.chain, '', tr.gas_price.toString());
  63. }
  64. if (json_obj.data.total > 0) {
  65. //提交归集任务
  66. if (temp_obj.address) {
  67. logger.log('pushCollectConisObj>>>', temp_obj.address)
  68. redis.redis_push(reids_token_config.COLLECT_CONIS_QUEUE_KEY, JSON.stringify(temp_obj))
  69. }
  70. }
  71. if (json_obj.data.total > 0) {
  72. //提交归集任务
  73. if (temp_obj.address) {
  74. logger.log('pushCollectConisObj>>>', temp_obj.address)
  75. redis.redis_push(reids_token_config.COLLECT_CONIS_QUEUE_KEY, JSON.stringify(temp_obj))
  76. }
  77. }
  78. }
  79. } catch (error) {
  80. console.error('pushCollectConisObj error=', error)
  81. }
  82. }
  83. })
  84. }
  85. /**
  86. * 获取交易记录
  87. * @param {*} ctx
  88. */
  89. async function getTransfersV2(ctx) {
  90. const obj = ctx.request.body;
  91. console.log("getTransfers body", obj);
  92. if (!obj.chain)//默认 bsc 币安链
  93. obj.chain = 'bsc_mainnet'
  94. var temp_obj = { ...obj }
  95. var index = 0
  96. await moralis.getTokenTransfersV2(obj).then((result) => {
  97. logger.log('getTokenTransfersV2 response', 'index=' + index, result)
  98. ctx.body = result;
  99. if (result) {
  100. //提交归集任务 native 能获取到 gas 、token 无法获取到 gas 费
  101. try {
  102. if (temp_obj.address && moralis.isTransferSucceed(result)) {
  103. var log_obj = { ...obj }
  104. log_obj.results = result
  105. log_obj.type = report.REPORT_TYPE.transfer_record
  106. //埋点日志上报-入金检查
  107. report.logReport(log_obj)
  108. var json_obj = JSON.parse(result);
  109. //缓存当前交易的 gas 费用
  110. var tr = moralis.getTransferRecordGasFree('native', json_obj, temp_obj.address)
  111. logger.log('getTransferRecordGasFree:', tr, temp_obj.address)
  112. if (tr && tr.totalGasFree > 0) {
  113. logger.log('getTransferRecordGasFree redis_set LAST_TOTAL_BNB_FREE:', tr)
  114. // redis.redis_set(reids_token_config.LAST_BNB_PRICE, tr.gas_price.toString());
  115. // redis.redis_set(reids_token_config.LAST_TOKEN_PRICE, tr.gas_price.toString().toString());
  116. redis.writeAppendRedis(reids_token_config.LAST_BNB_PRICE, temp_obj.chain, '', tr.gas_price.toString());
  117. redis.writeAppendRedis(reids_token_config.LAST_TOKEN_PRICE, temp_obj.chain, '', tr.gas_price.toString());
  118. }
  119. if (json_obj.data.total > 0) {
  120. //提交归集任务
  121. if (temp_obj.address) {
  122. logger.log('pushCollectConisObj>>>', temp_obj.address)
  123. redis.redis_push(reids_token_config.COLLECT_CONIS_QUEUE_KEY, JSON.stringify(temp_obj))
  124. }
  125. }
  126. }
  127. } catch (error) {
  128. console.error('pushCollectConisObj error=', error)
  129. }
  130. }
  131. })
  132. }
  133. async function getAllTokenWithdrawInfoLists(ctx) {
  134. if (ctx.request == null || ctx.request.body == null) {
  135. ctx.body = utils.toJson(-1, null, "request error. ");
  136. return
  137. }
  138. ctx.body = await moralis.getAllTokenWithdrawInfoLists(ctx);
  139. }
  140. async function collect_conis_task() {
  141. logger.log("collect_conis_task start")
  142. while (true) {
  143. var start_time = utils.getTimestamp()
  144. var exec_obj = await redis.redis_pop(reids_token_config.COLLECT_CONIS_QUEUE_KEY)
  145. if (!exec_obj) {
  146. await utils.sleep(30000)
  147. logger.log("没有归集任务")
  148. continue
  149. }
  150. try {
  151. exec_obj = JSON.parse(exec_obj)
  152. logger.log('collect_conis_task exec item>>>>', exec_obj);
  153. //开始收集用户地址里面的币到归集地址
  154. var ret = await moralis.collectCoins(exec_obj)
  155. logger.log('collect_conis_task ret =', exec_obj, ret)
  156. try {
  157. var ret_obj = JSON.parse(ret)
  158. if (ret_obj.code == 0) {
  159. logger.log('触发归集 delay collect_conis_task ret =', exec_obj, ret)
  160. //间隔 10s 归集,避免提交任务过多
  161. await utils.sleep(10000)
  162. }
  163. } catch (error) { }
  164. } catch (error) {
  165. logger.error('collect_conis_task error', error.toString());
  166. }
  167. logger.log("collect_conis_task cost-time", utils.getTimestamp() - start_time, exec_obj)
  168. }
  169. }
  170. async function withdraw_task() {
  171. logger.log("withdraw_task start")
  172. let last_time = 0
  173. let last_hash = ''
  174. let last_chain = ''
  175. while (true) {
  176. var exec_obj = await redis.redis_pop(reids_token_config.WITHDRAW_QUEUE_KEY)
  177. if (!exec_obj) {
  178. await utils.sleep(10000)
  179. logger.log("没有出金任务")
  180. continue
  181. }
  182. try {
  183. exec_obj = JSON.parse(exec_obj)
  184. } catch (error) {
  185. logger.error('item parse error', error);
  186. break
  187. }
  188. var temp_obj = { ...exec_obj }
  189. if (utils.getTimestamp() - last_time < 60000) {
  190. //有可能上一个区块还未更新,这里做一个尝试限制
  191. //Error: Failed to make "eth_sendRawTransaction" request with networkConnector: "already known"
  192. //通过 交易 hash 获取块。last_hash
  193. if (last_hash && last_chain) {
  194. var options = {
  195. transaction_hash: last_hash,
  196. chain: last_chain,
  197. endTime: '2099-01-01'
  198. }
  199. var tryCount = 3;
  200. do {
  201. try {
  202. //通过获取上一个交易记录来进行确认
  203. var transaction = await moralis.getTokenTransfersV2(options);
  204. logger.log('withdraw_task exectransaction', transaction, options, tryCount);
  205. if (typeof transaction === 'string')
  206. transaction = JSON.parse(transaction)
  207. if (transaction.code == 0) {
  208. if (transaction.data.results.length <= 0) {
  209. logger.log('等待10s');
  210. await utils.sleep(10000)
  211. } else {
  212. logger.log('等待5s');
  213. await utils.sleep(5000)
  214. break
  215. }
  216. } else {
  217. break
  218. }
  219. tryCount -= 1
  220. } catch (error) {
  221. logger.error('withdraw_task exectransaction err', error.toString());
  222. }
  223. if (tryCount < 0) {
  224. logger.error('withdraw_task getTokenTransfersV2 警告交易未更新:', JSON.stringify(options));
  225. }
  226. } while (tryCount >= 0);
  227. }
  228. }
  229. //如果失败重试一次
  230. var tryCount = 1;
  231. for (let index = 0; index < 1 + tryCount; index++) {
  232. try {
  233. var result = await withdraw_({ ...temp_obj })
  234. last_time = utils.getTimestamp()
  235. logger.log('withdraw_task withdraw_ =', result, last_time)
  236. if (result && moralis.isTransferSucceed(result)) {
  237. var obj = JSON.parse(result)
  238. var nonce = obj.data.nonce
  239. var curGasPrice = BigNumber(obj.data.gasPrice.hex).toNumber()
  240. var curGasLimit = BigNumber(obj.data.gasLimit.hex).toNumber()
  241. var value = 0
  242. if (obj.data.chainId == 97) {
  243. value = BigNumber(obj.data.value.hex).toNumber()
  244. } else {
  245. value = obj.data.value.number
  246. }
  247. var hash = obj.data.hash
  248. last_hash = hash
  249. last_chain = temp_obj.chain
  250. var update_obj = {}
  251. update_obj.withdraw_status = 2
  252. update_obj.withdraw_hash = hash
  253. update_obj.nonce = nonce
  254. update_obj.gas_price = curGasPrice.toString()
  255. update_obj.gas_limit = curGasLimit.toString()
  256. update_obj.value = utils.scientificNotationToString(value).toString()
  257. update_obj.errorMsg = ''
  258. await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
  259. break
  260. } else {
  261. logger.error('withdraw_task withdraw_ error=', result, JSON.stringify(temp_obj))
  262. if (index < 1 + tryCount && result.includes('eth_sendRawTransaction')) {
  263. logger.error('try withdraw_:', JSON.stringify(temp_obj), index)
  264. await utils.sleep(3000)
  265. continue
  266. }
  267. var update_obj = {}
  268. update_obj.withdraw_status = 3
  269. if (typeof result === 'string') {
  270. try {
  271. result = JSON.parse(result)
  272. update_obj.errorMsg = result.errMsg
  273. } catch (error) {
  274. logger.error('withdraw_task=', result)
  275. }
  276. }
  277. await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
  278. break
  279. }
  280. } catch (error) {
  281. var update_obj = {}
  282. update_obj.withdraw_status = 3
  283. update_obj.errorMsg = error.toString()
  284. await withdraw_db.update_withdraw_task(exec_obj.withdraw_id, update_obj)
  285. logger.error('withdraw_task error=', error.toString())
  286. break
  287. }
  288. }
  289. }
  290. logger.log("withdraw_task end")
  291. }
  292. /**
  293. * 队列版本
  294. * @param {*} ctx
  295. * @returns
  296. */
  297. async function withdrawV3(ctx) {
  298. logger.log('withdrawV3')
  299. if (ctx.request == null || ctx.request.body == null) {
  300. ctx.body = utils.toJson(-1, null, "request error. ");
  301. return
  302. }
  303. const obj = ctx.request.body;
  304. // for (let index = 0; index < 10; index++) {
  305. var log_obj = { ...obj }
  306. logger.log('withdrawV3', log_obj)
  307. var obj_ = decrypt_withdraw_content(log_obj.content)
  308. obj_.withdraw_id = obj_.withdrawId;
  309. // obj_.withdraw_id = utils.getTimestamp().toString();
  310. // var obj_ = log_obj
  311. if (obj_.withdraw_id) {
  312. var isExist = await withdraw_db.withdraw_id_exist(obj_.withdraw_id)
  313. if (isExist) {
  314. logger.error('withdraw_id_exist', obj_.withdraw_id + ' is already in the queue.')
  315. ctx.body = utils.toJson(-2, null, obj_.withdraw_id + ' is already in the queue.')
  316. return
  317. }
  318. var info = await moralis.queryCompanyInfoFromId(0);
  319. obj_.user_address = info.user_address
  320. await withdraw_db.create_withdraw_task(obj_)
  321. redis.redis_push(reids_token_config.WITHDRAW_QUEUE_KEY, JSON.stringify(obj_))
  322. // withdraw_task()
  323. ctx.body = utils.toJson(0, obj_.withdraw_id, null)
  324. } else {
  325. return utils.toJson(-2, null, ' withdraw_id not empty.')
  326. }
  327. // }
  328. }
  329. async function withdrawV3Test(ctx) {
  330. logger.log('withdrawV3Test')
  331. if (ctx.request == null || ctx.request.body == null) {
  332. ctx.body = utils.toJson(-1, null, "request error. ");
  333. return
  334. }
  335. const obj = ctx.request.body;
  336. // for (let index = 0; index < 10; index++) {
  337. var log_obj = { ...obj }
  338. logger.log('withdrawV3', log_obj)
  339. var obj_ = decrypt_withdraw_content(log_obj.content)
  340. obj_.withdraw_id = utils.getCurrentDateFormat('YYYY-MM-DD-HH:mm:ss:SSS').toString()
  341. // var obj_ = log_obj
  342. if (obj_.withdraw_id) {
  343. var isExist = await withdraw_db.withdraw_id_exist(obj_.withdraw_id)
  344. if (isExist) {
  345. logger.error('withdraw_id_exist', obj_.withdraw_id + ' is already in the queue.')
  346. ctx.body = utils.toJson(-2, null, obj_.withdraw_id + ' is already in the queue.')
  347. return
  348. }
  349. redis.redis_push(reids_token_config.WITHDRAW_QUEUE_KEY, JSON.stringify(obj_))
  350. var info = await moralis.queryCompanyInfoFromId(0);
  351. obj_.user_address = info.user_address
  352. await withdraw_db.create_withdraw_task(obj_)
  353. ctx.body = utils.toJson(0, obj_.withdraw_id, null)
  354. } else {
  355. return utils.toJson(-2, null, ' withdraw_id not empty.')
  356. }
  357. // }
  358. }
  359. function decrypt_withdraw_content(content) {
  360. // const encryptText = utils.encrypt(log_obj);
  361. const encryptText = content;
  362. logger.log("加密", encryptText);
  363. let decryptObj = utils.decrypt(encryptText);
  364. try {
  365. logger.log("解密 before", decryptObj);
  366. decryptObj = JSON.parse(decryptObj);
  367. console.log("解密 json parse", decryptObj);
  368. } catch (error) {
  369. logger.error("json error:", error);
  370. decryptObj = null;
  371. }
  372. return decryptObj;
  373. }
  374. /**
  375. *
  376. * @param {鉴权版本} ctx
  377. */
  378. async function withdrawV2(ctx) {
  379. if (ctx.request == null || ctx.request.body == null) {
  380. ctx.body = utils.toJson(-1, null, "request error. ");
  381. return
  382. }
  383. const obj = ctx.request.body;
  384. var log_obj = { ...obj }
  385. // const encryptText = utils.encrypt(log_obj);
  386. const encryptText = log_obj.content;
  387. logger.log("加密", encryptText);
  388. let decryptObj = utils.decrypt(encryptText);
  389. try {
  390. logger.log("解密 before", decryptObj);
  391. decryptObj = JSON.parse(decryptObj);
  392. // console.log("解密 json parse", decryptObj);
  393. await withdraw_(decryptObj).then(result => {
  394. ctx.body = result;
  395. })
  396. } catch (error) {
  397. logger.error("json error:", error);
  398. ctx.body = utils.toJson(-1, null, error.toString());
  399. }
  400. }
  401. async function withdraw_(obj) {
  402. console.log("withdraw_", obj);
  403. var log_obj = { ...obj }
  404. var info = await moralis.queryCompanyInfoFromId(0);
  405. // log_obj.company_address_total_balance_before = await moralis.queryCollectBalance(info.user_address, obj.chain)
  406. log_obj.company_public_key = info.user_address
  407. logger.log('withdraw log', log_obj);
  408. return new Promise((resolve) => {
  409. moralis.withdraw(obj).then((result) => {
  410. if (moralis.isTransferSucceed(result)) {
  411. //提币日志上报
  412. log_obj.results = result
  413. log_obj.type = report.REPORT_TYPE.withdraw
  414. //缓存当前交易的 gas 费用
  415. if (result && log_obj.contractAddress) {
  416. var tr = moralis.getTransferGasFree('token', result)
  417. log_obj.withdrawTotalGasFee = tr.totalGasFree.toString()
  418. } else {
  419. var tr = moralis.getTransferGasFree('native', result)
  420. log_obj.withdrawTotalGasFee = tr.totalGasFree.toString()
  421. }
  422. // log_obj.receiver_address_total_balance_after = await queryCollectBalance(info.user_address, utils.getChainName(obj.chain))
  423. //日志上报
  424. report.logReport(log_obj)
  425. }
  426. resolve(result)
  427. });
  428. })
  429. }
  430. //出金
  431. async function withdraw(ctx) {
  432. if (ctx.request == null || ctx.request.body == null) {
  433. ctx.body = utils.toJson(-1, null, "request error. ");
  434. return
  435. }
  436. const obj = ctx.request.body;
  437. await withdraw_(obj).then(result => {
  438. ctx.body = result;
  439. })
  440. }
  441. /**
  442. * 查询出金状态
  443. * @param {*} ctx
  444. */
  445. async function getWithdrawStatus(ctx) {
  446. if (ctx.request == null || ctx.request.body == null) {
  447. ctx.body = utils.toJson(-1, null, "request error. ");
  448. return
  449. }
  450. const obj = ctx.request.body;
  451. var info = await withdraw_db.queryWithdrawInfoFromWithdrawId(obj.withdrawId)
  452. logger.log('getWithdrawStatus info', JSON.stringify(info))
  453. if (info) {
  454. if (info.withdraw_status != 3) {
  455. ctx.body = utils.toJson(0, {
  456. withdrawId: info.withdraw_id,
  457. withdrawStatus: info.withdraw_status,
  458. withdrawHash: info.withdraw_hash,
  459. chainId: info.chain_id,
  460. transferTimestamp: info.update_time,
  461. }, null)
  462. } else {
  463. ctx.body = utils.toJson(0, {
  464. withdrawId: info.withdraw_id,
  465. withdrawStatus: info.withdraw_status,
  466. withdrawHash: info.withdraw_hash,
  467. chainId: info.chain_id,
  468. transferTimestamp: info.update_time,
  469. errorMsg: info.errorMsg
  470. }, null)
  471. }
  472. } else {
  473. ctx.body = utils.toJson(-1, null, obj.withdraw_id + ' id does not exist.')
  474. }
  475. }
  476. async function timer_collect_conis_bsc_task() {
  477. var index = 0
  478. var delay = 50 * 1000 * 60
  479. while (1) {
  480. var temp_obj = {
  481. "chain": "bsc_testnet",
  482. "address": "0x3B525c35DdC323B08241493f148340D89e3A73a7"
  483. }
  484. redis.redis_push(reids_token_config.COLLECT_CONIS_QUEUE_KEY, JSON.stringify(temp_obj))
  485. await utils.sleep(delay)
  486. index += 1
  487. }
  488. }
  489. async function timer_collect_conis_czz_task() {
  490. var index = 0
  491. var delay = 15 * 1000 * 60
  492. while (1) {
  493. var temp_obj = {
  494. "chain": "czz",
  495. "address": "0x39ACD9CC975D792D8160215Dc84fa00E4934F076",
  496. }
  497. redis.redis_push(reids_token_config.COLLECT_CONIS_QUEUE_KEY, JSON.stringify(temp_obj))
  498. await utils.sleep(delay)
  499. index += 1
  500. }
  501. }
  502. async function timer_transfer_bsc_task() {
  503. var index = 0
  504. var delay = 30 * 1000 * 60
  505. while (1) {
  506. var obj_ = {
  507. "type": "erc20",
  508. "contractAddress": "0xFF94950Ee8A79c52cC4B0Aa5178C8cEa48A3F3A6",
  509. "amount": "123000000000000000000",
  510. "chain": "bsc_testnet",
  511. "receiver": "0x3B525c35DdC323B08241493f148340D89e3A73a7",
  512. "withdrawId": index.toString()
  513. }
  514. obj_.withdraw_id =utils.getCurrentDateFormat('YYYY-MM-DD-HH:mm:ss:SSS').toString()
  515. var info = await moralis.queryCompanyInfoFromId(0);
  516. obj_.user_address = info.user_address
  517. await withdraw_db.create_withdraw_task(obj_)
  518. redis.redis_push(reids_token_config.WITHDRAW_QUEUE_KEY, JSON.stringify(obj_))
  519. await utils.sleep(delay)
  520. index += 1
  521. }
  522. }
  523. async function timer_transfer_czz_task() {
  524. var index = 0
  525. var delay = 10 * 1000 * 60
  526. while (1) {
  527. var obj_ = {
  528. "type": "erc20",
  529. "contractAddress": "0xfb16179d5e84b0e3e7524ed61a9cf7b98d039b20",
  530. "amount": "100000000000000000000",
  531. "chain": "czz",
  532. "receiver": "0x39ACD9CC975D792D8160215Dc84fa00E4934F076"
  533. }
  534. obj_.withdraw_id = utils.getCurrentDateFormat('YYYY-MM-DD-HH:mm:ss:SSS').toString()
  535. var info = await moralis.queryCompanyInfoFromId(0);
  536. obj_.user_address = info.user_address
  537. await withdraw_db.create_withdraw_task(obj_)
  538. redis.redis_push(reids_token_config.WITHDRAW_QUEUE_KEY, JSON.stringify(obj_))
  539. await utils.sleep(delay)
  540. index += 1
  541. }
  542. }
  543. //获取交易记录
  544. router.post('/getTransfers', getTransfers)
  545. router.post('/getTransfersV2', getTransfersV2)
  546. // 获取所有代币价格
  547. router.post('/getAllTotkenPrice', getAllTotkenPrice)
  548. router.post('/getAllTokenPrice', getAllTokenPrice)
  549. // router.post('/transfer', transfer)
  550. //提现
  551. router.post('/withdraw', withdraw);
  552. //提现鉴权-body 加密
  553. router.post('/withdrawV2', withdrawV2);
  554. //队列的形式
  555. router.post('/withdrawV3', withdrawV3);
  556. if (process.env.NODE_ENV == 'dev' || process.env.NODE_ENV == 'test') {
  557. router.post('/withdrawV3Test', withdrawV3Test);
  558. //查询出金服务
  559. router.post('/getWithdrawStatus', getWithdrawStatus);
  560. //获取所有地址的所要消耗的最低提取费
  561. router.post('/getAllTokenWithdrawInfoLists', getAllTokenWithdrawInfoLists)
  562. // 定时任务 提币+归集
  563. withdraw_task();
  564. collect_conis_task();
  565. if (process.env.NODE_ENV == 'dev' || process.env.NODE_ENV == 'test') {
  566. timer_transfer_bsc_task()
  567. timer_transfer_czz_task()
  568. timer_collect_conis_bsc_task()
  569. timer_collect_conis_czz_task()
  570. }
  571. module.exports = router