|
@@ -108,7 +108,8 @@ async function collect_conis_task() {
|
|
|
|
|
|
async function withdraw_task() {
|
|
|
let last_time = 0
|
|
|
- let last_receiver = ''
|
|
|
+ let last_hash = ''
|
|
|
+
|
|
|
while (true) {
|
|
|
var exec_obj = await redis.redis_pop(reids_token_config.WITHDRAW_QUEUE_KEY)
|
|
|
if (!exec_obj) {
|
|
@@ -123,23 +124,44 @@ async function withdraw_task() {
|
|
|
break
|
|
|
}
|
|
|
|
|
|
- // if (last_receiver == exec_obj.receiver && utils.getTimestamp() - last_time < 10000) {
|
|
|
- // //有可能上一个区块还未更新,这里做一个尝试限制
|
|
|
- // //Error: Failed to make "eth_sendRawTransaction" request with networkConnector: "already known"
|
|
|
- // console.log('sleep5s', last_receiver);
|
|
|
- // await utils.sleep(5000)
|
|
|
- // }
|
|
|
- await utils.sleep(2000)
|
|
|
-
|
|
|
- console.error('withdraw_task exec item>>>>exec_obj', exec_obj);
|
|
|
- console.error('withdraw_task exec item>>>>last_receiver', last_receiver, exec_obj.receiver);
|
|
|
- console.error('withdraw_task exec item>>>>last_time', last_time, utils.getTimestamp());
|
|
|
-
|
|
|
+ var temp_obj = { ...exec_obj }
|
|
|
+ if (utils.getTimestamp() - last_time < 60000) {
|
|
|
+ //有可能上一个区块还未更新,这里做一个尝试限制
|
|
|
+ //Error: Failed to make "eth_sendRawTransaction" request with networkConnector: "already known"
|
|
|
+ logger.error('sleep5s', last_receiver);
|
|
|
+ //通过 交易 hash 获取块。last_hash
|
|
|
+ if (last_hash) {
|
|
|
+ var options = {
|
|
|
+ transaction_hash: last_hash,
|
|
|
+ chain: temp_obj.chain,
|
|
|
+ endTime: '2099-01-01'
|
|
|
+ }
|
|
|
+ var tryCount = 10;
|
|
|
+ do {
|
|
|
+ try {
|
|
|
+ var transaction = await moralis.getTokenTransfers(options);
|
|
|
+ logger.log('withdraw_task exectransaction', transaction, options, tryCount);
|
|
|
+ transaction = JSON.parse(transaction)
|
|
|
+ if (transaction.code == 0) {
|
|
|
+ if (transaction.data.result.length <= 0) {
|
|
|
+ await utils.sleep(1500)
|
|
|
+ } else {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ tryCount -= 1
|
|
|
+ } catch (error) {
|
|
|
+ logger.error('withdraw_task exectransaction', error.toString());
|
|
|
+ }
|
|
|
+ } while (tryCount >= 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
try {
|
|
|
- var result = await withdraw_(exec_obj)
|
|
|
- last_receiver = exec_obj.receiver
|
|
|
+ var result = await withdraw_({ ...exec_obj })
|
|
|
last_time = utils.getTimestamp()
|
|
|
- logger.log('withdraw_task=', result, last_time, last_receiver)
|
|
|
+ logger.log('withdraw_task=', result, last_time)
|
|
|
if (result && moralis.isTransferSucceed(result)) {
|
|
|
var obj = JSON.parse(result)
|
|
|
var nonce = obj.data.nonce
|
|
@@ -147,6 +169,7 @@ async function withdraw_task() {
|
|
|
var curGasLimit = BigNumber(obj.data.gasLimit.hex).toNumber()
|
|
|
var value = BigNumber(obj.data.value.hex).toNumber()
|
|
|
var hash = obj.data.hash
|
|
|
+ last_hash = hash
|
|
|
var update_obj = {}
|
|
|
update_obj.withdraw_status = 2
|
|
|
update_obj.withdraw_hash = hash
|
|
@@ -189,30 +212,65 @@ async function withdrawV3(ctx) {
|
|
|
const obj = ctx.request.body;
|
|
|
|
|
|
// for (let index = 0; index < 10; index++) {
|
|
|
- var log_obj = { ...obj }
|
|
|
- logger.log('withdrawV3', log_obj)
|
|
|
- var obj_ = decrypt_withdraw_content(log_obj.content)
|
|
|
- obj_.withdraw_id = obj_.withdrawId;
|
|
|
- // obj_.withdraw_id = utils.getTimestamp().toString();
|
|
|
- // var obj_ = log_obj
|
|
|
- if (obj_.withdraw_id) {
|
|
|
- var isExist = await withdraw_db.withdraw_id_exist(obj_.withdraw_id)
|
|
|
- if (isExist) {
|
|
|
- logger.error('withdraw_id_exist', obj_.withdraw_id + ' is already in the queue.')
|
|
|
- ctx.body = utils.toJson(-2, null, obj_.withdraw_id + ' is already in the queue.')
|
|
|
- return
|
|
|
- }
|
|
|
- redis.redis_push(reids_token_config.WITHDRAW_QUEUE_KEY, JSON.stringify(obj_))
|
|
|
- var info = await moralis.queryCompanyInfoFromId(0);
|
|
|
- obj_.user_address = info.user_address
|
|
|
- await withdraw_db.create_withdraw_task(obj_)
|
|
|
- // withdraw_task()
|
|
|
- ctx.body = utils.toJson(0, obj_.withdraw_id, null)
|
|
|
- } else {
|
|
|
- return utils.toJson(-2, null, ' withdraw_id not empty.')
|
|
|
+ var log_obj = { ...obj }
|
|
|
+ logger.log('withdrawV3', log_obj)
|
|
|
+ var obj_ = decrypt_withdraw_content(log_obj.content)
|
|
|
+ obj_.withdraw_id = obj_.withdrawId;
|
|
|
+ // obj_.withdraw_id = utils.getTimestamp().toString();
|
|
|
+ // var obj_ = log_obj
|
|
|
+ if (obj_.withdraw_id) {
|
|
|
+ var isExist = await withdraw_db.withdraw_id_exist(obj_.withdraw_id)
|
|
|
+ if (isExist) {
|
|
|
+ logger.error('withdraw_id_exist', obj_.withdraw_id + ' is already in the queue.')
|
|
|
+ ctx.body = utils.toJson(-2, null, obj_.withdraw_id + ' is already in the queue.')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ redis.redis_push(reids_token_config.WITHDRAW_QUEUE_KEY, JSON.stringify(obj_))
|
|
|
+ var info = await moralis.queryCompanyInfoFromId(0);
|
|
|
+ obj_.user_address = info.user_address
|
|
|
+ await withdraw_db.create_withdraw_task(obj_)
|
|
|
+ // withdraw_task()
|
|
|
+ ctx.body = utils.toJson(0, obj_.withdraw_id, null)
|
|
|
+ } else {
|
|
|
+ return utils.toJson(-2, null, ' withdraw_id not empty.')
|
|
|
+ }
|
|
|
+ // }
|
|
|
+}
|
|
|
+
|
|
|
+async function withdrawV3Test(ctx) {
|
|
|
+ logger.log('withdrawV3Test')
|
|
|
+ if (ctx.request == null || ctx.request.body == null) {
|
|
|
+ ctx.body = utils.toJson(-1, null, "request error. ");
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const obj = ctx.request.body;
|
|
|
+
|
|
|
+ // for (let index = 0; index < 10; index++) {
|
|
|
+ var log_obj = { ...obj }
|
|
|
+ logger.log('withdrawV3', log_obj)
|
|
|
+ var obj_ = decrypt_withdraw_content(log_obj.content)
|
|
|
+ obj_.withdraw_id = obj_.withdrawId;
|
|
|
+ obj_.withdraw_id = utils.getTimestamp().toString();
|
|
|
+ // var obj_ = log_obj
|
|
|
+ if (obj_.withdraw_id) {
|
|
|
+ var isExist = await withdraw_db.withdraw_id_exist(obj_.withdraw_id)
|
|
|
+ if (isExist) {
|
|
|
+ logger.error('withdraw_id_exist', obj_.withdraw_id + ' is already in the queue.')
|
|
|
+ ctx.body = utils.toJson(-2, null, obj_.withdraw_id + ' is already in the queue.')
|
|
|
+ return
|
|
|
}
|
|
|
+ redis.redis_push(reids_token_config.WITHDRAW_QUEUE_KEY, JSON.stringify(obj_))
|
|
|
+ var info = await moralis.queryCompanyInfoFromId(0);
|
|
|
+ obj_.user_address = info.user_address
|
|
|
+ await withdraw_db.create_withdraw_task(obj_)
|
|
|
+ ctx.body = utils.toJson(0, obj_.withdraw_id, null)
|
|
|
+ } else {
|
|
|
+ return utils.toJson(-2, null, ' withdraw_id not empty.')
|
|
|
+ }
|
|
|
// }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
function decrypt_withdraw_content(content) {
|
|
|
// const encryptText = utils.encrypt(log_obj);
|
|
|
const encryptText = content;
|
|
@@ -350,6 +408,7 @@ router.post('/withdraw', withdraw);
|
|
|
router.post('/withdrawV2', withdrawV2);
|
|
|
//队列的形式
|
|
|
router.post('/withdrawV3', withdrawV3);
|
|
|
+router.post('/withdrawV3Test', withdrawV3Test);
|
|
|
//查询出金服务
|
|
|
router.post('/getWithdrawStatus', getWithdrawStatus);
|
|
|
|
|
@@ -359,4 +418,6 @@ router.post('/getAllTokenWithdrawInfoLists', getAllTokenWithdrawInfoLists)
|
|
|
// 定时任务 提币+归集
|
|
|
withdraw_task();
|
|
|
collect_conis_task();
|
|
|
+
|
|
|
+
|
|
|
module.exports = router
|