def __init__(self, configure): super().__init__(configure) session = Session() self._token_address = None token_info = session.query(self.CoinSetting).filter_by( coin_type=self.coin_type, main_type=self.coin_category).first() self._token_address = token_info.token_address
def poll(self): logger.info("--------- etc gather_transaction listen start ---------") session = Session() while True: try: transfer_list = session.query( self.coin_transfer_coll).filter_by( status=GatherStatusEnum.GATHERING, coin_series=self.coin_category).all() for item in transfer_list: self.monitor_tx_id(session, item) except Exception as e: logger.exception(e) time.sleep(10)
def poll(self): logger.info('----------- etc gather start -----------') session = Session() while True: try: coin_transfer_list = session.query( self.coin_transfer_coll).filter_by( status=GatherStatusEnum.GATHER, coin_series=self.coin_category).all() for item in coin_transfer_list: self.gather(session, item) except Exception as e: logger.exception(e) time.sleep(10)
def poll(self): session = Session() logger.info('----------- ask_fee start -----------') while True: try: coin_ask_fee_list = session.query( self.coin_ask_fee_coll).filter_by( **{'status': AskFeeStatusEnum.ASKING, 'coin_series': 'ETH'}).all() for item in coin_ask_fee_list: self.ask_fee(session, item) except Exception as e: logger.exception("缴费轮寻发生错误{}".format(e)) time.sleep(10)
def poll(self): logger.info("----------- eth_gather start -----------") session = Session() while True: try: coin_transfer_list = session.query( self.coin_transfer_coll).filter_by( status=GatherStatusEnum.GATHER, coin_series="ETH").all() for item in coin_transfer_list: if item.coin_type == 'ETH': self.eth_withdraw_op(session, item) else: self.token_withdraw_op(session, item) except Exception as e: logger.exception("汇聚轮寻发生错误{}".format(e)) time.sleep(10)
def main(): session = Session() init_block_info(session) while True: try: operator = ERC20Token(provider_endpoint=config.eth_wallet_url) # 获取区块信息及交易列表 block_info = session.query(block_info_document).filter_by( coin_type=coin_type).first() checked_block_info = check_block(block_info, operator) if not checked_block_info: continue tx_list = operator.get_block_tx_id_list( checked_block_info['block_num']) # 遍历交易列表 for tx_id in tx_list: tx_process(session, hexstr_if_str(to_hex, tx_id), operator) logger.info( f'pull block finished: {checked_block_info["block_num"]}') except Exception as e: logger.exception(e) else: block_info.block_hash = checked_block_info['block_hash'] block_info.block_num = checked_block_info['block_num'] try: session.commit() except Exception as e: logger.exception("更新区块发生错误{}".format(e)) session.rollback() time.sleep(3)
def poll(self): logger.info('-----------etc_recharge start-----------') session = Session() self.init_block_info(session) while True: try: operator = self.erc_op_class(ipc_path=config.etc_ipc_path) # 获取区块信息及交易列表 block_info = session.query(self.block_info_coll).filter_by( coin_type=self.coin_category).first() checked_block_info = self.check_block(block_info, operator) if not checked_block_info: continue tx_list = operator.get_block_tx_id_list( checked_block_info['block_num']) # 遍历交易列表 for tx_id in tx_list: self.tx_process(session, hexstr_if_str(to_hex, tx_id), operator) logger.info( f'pull block finished: {checked_block_info["block_num"]}') except Exception as e: logger.exception(e) else: # 存储交易区块信息 block_info.block_num = checked_block_info['block_num'] block_info.block_hash = checked_block_info['block_hash'] try: session.commit() except Exception as e: logger.exception("检查回滚区块时发生错误{}".format(e)) session.rollback() time.sleep(3)
def poll(self): logger.info("----------- withdraw check start -----------") session = Session() while True: try: self.check_withdraw(session) except Exception as e: logger.exception("提币轮寻发生错误{}".format(e)) time.sleep(2)
def poll(self): logger.info("----------- gather start -----------") session = Session() while True: try: self.check_do_gather(session) time.sleep(60 * 10) except Exception as e: logger.exception("汇聚轮寻发生错误{}".format(e)) time.sleep(60 * 10)
def poll(self): logger.info("----------- gather tx start -----------") session = Session() while True: try: self.check_gather_tx(session) time.sleep(5) except Exception as e: logger.exception(e) time.sleep(60)
def poll(self): logger.info('------ etc charge withdraw transaction start ---------') session = Session() while True: try: withdraw_list = session.query(self.withdraw_coll).filter_by( informed=InformEnum.NO, coin_series=self.coin_category).all() recharge_list = session.query( self.coin_recharge_coll).filter_by( informed=InformEnum.NO, coin_series=self.coin_category).all() for item in recharge_list: self.monitor_tx_id(session, item, 'recharge') for item in withdraw_list: self.monitor_tx_id(session, item, 'withdraw') except Exception as e: logger.exception("充提币交易轮寻发生错误{}".format(e)) time.sleep(10)
def poll(self): logger.info("----------- update balance start -----------") session = Session() while True: try: self.update_wallet_balance(session) time.sleep(10) except Exception as e: logger.exception("更新余额缓存表轮寻发生错误{}".format(e)) time.sleep(60)
def poll(self): logger.info("----------- recharge start -----------") session = Session() while True: try: self.check_recharge(session) time.sleep(5) except Exception as e: logger.exception("冲币轮寻发生错误{}".format(e)) time.sleep(30)
class WithdrawBalanceRecord(Record): AccountBalance = AccountBalance session = Session() def __init__(self, configure): super().__init__(configure) self.tb_address = configure.tb_address @property def balance(self): record = self.AccountBalance.find_one( {'coin_type': '{}_TX'.format(self.coin_type.upper())}) if record: ret = record.to_dict() return ret.get("balance", 0) else: return 0 @balance.setter def balance(self, val): _doc = dict() utc_now = datetime.utcnow() _doc['coin_type'] = '%s_TX' % self.coin_type.upper() _doc['updated_at'] = utc_now _doc['balance'] = val _doc['address'] = self.configure.tb_address account_balance = self.session.query(self.AccountBalance).filter_by( coin_type='%s_TX' % self.coin_type).with_for_update().first() if account_balance: account_balance.coin_type = _doc['coin_type'] account_balance.update_at = _doc['updated_at'] account_balance.balance = _doc['balance'] else: account_balance_ = self.AccountBalance(**_doc) self.session.add(account_balance_) try: self.session.commit() except Exception as e: logging.error( f"%s: Update account balance: %s (Update Account balance record failed!)" % (BALANCE_UPDATE_ERR, val)) logging.exception("更新余额表时发生错误{}".format(e)) self.session.rollback()
def poll(self): logger.info("----------- eth_askfee_tx_listener start -----------") session = Session() while True: try: coin_ask_fee_list = session.query( self.coin_ask_fee_coll).filter_by( status=AskFeeStatusEnum.WAIT_CONFIRM, coin_series="ETH").all() for item in coin_ask_fee_list: self.monitor_tx_id(session, item) try: session.commit() except Exception as e: logger.error("缴费交易轮寻更新数据库失败") logger.exception(e) session.rollback() except Exception as e: logger.exception("缴费交易轮寻发生错误{}".format(e)) time.sleep(10)
def poll(self): logger.info("----------- eth_gather_tx_listener start -----------") session = Session() while True: try: transfer_list = session.query( self.coin_transfer_coll).filter_by( status=GatherStatusEnum.GATHERING, coin_series="ETH").all() for item in transfer_list: self.monitor_tx_id(session, item) try: session.commit() except Exception as e: logger.error("汇聚交易数据库操作时发生错误") logger.exception(e) session.rollback() except Exception as e: logger.exception("汇聚交易轮寻发生错误{}".format(e)) time.sleep(10)
def poll(self): logger.info("----------- erc_charge_withdraw start -----------") session = Session() while True: try: withdraw_list = session.query( self.withdraw_coll).filter_by(**{ 'coin_series': 'ETH', 'informed': InformEnum.NO }).all() for item in withdraw_list: self.monitor_tx_id(session, item, 'withdraw') try: session.commit() except Exception as e: logger.error("提币轮寻数据库操作失败") logger.exception(e) session.rollback() else: logger.info("提币轮寻更新成功") except Exception as e: logger.exception("提币交易确认轮寻发生错误{}".format(e)) time.sleep(10)
def poll(self): logger.info("----------- erc_recharge_tx start -----------") session = Session() while True: try: recharge_list = session.query( self.coin_recharge_coll).filter_by( **{ 'coin_series': 'ETH', 'informed': InformEnum.NO }).all() for item in recharge_list: self.monitor_tx_id(session, item) try: session.commit() except Exception as e: session.rollback() logger.error("冲币执行数据库commit失败") logger.exception(e) else: logger.info("冲币更新数据成功") except Exception as e: logger.exception("充币交易确认轮寻发生错误{}".format(e)) time.sleep(10)